C Board  

Go Back   C Board > General Programming Boards > Networking/Device Communication

Reply
 
LinkBack Thread Tools Display Modes
Old 03-08-2004, 10:02 PM   #1
30 Helens Agree
 
neandrake's Avatar
 
Join Date: Jan 2002
Posts: 607
Simple Winsock Wrapper

I've been working a while at making a simple Asynchronous Winsock Wrapper and I'm pretty satisfied with what I have. Any other wrappers I've looked at seemed too complicated for simple purposes. I would love some help with it; right now the big thing is with classes and sending/receiving data. They work, but not very well and was wondering if someone would be willing to work on this project with me. Thanks for any help.
__________________

AIM: Neandrake
EMAIL: nta0 @ yahoo . com

Operating System: Windows XP SP2
Compiler: GCC
IDE: Notepad++


Don't give up your freedom to think - www.cognitiveliberty.org
neandrake is offline   Reply With Quote
Old 03-17-2004, 04:49 AM   #2
That Creepy Network Guy
 
DeepBlackMagic's Avatar
 
Join Date: Feb 2003
Posts: 265
I just finished a similar project for a cross-platform wrapper class. I would love to chat with you and swap some code.


Hope to hear from you.
DeepBlackMagic is offline   Reply With Quote
Old 03-17-2004, 11:30 AM   #3
Carnivore ('-'v)
 
Hunter2's Avatar
 
Join Date: May 2002
Posts: 2,866
What kind of asynchronous sockets are you using? Event, message, overlapped event, completion routine?
__________________
Just Google It. √

(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
Hunter2 is offline   Reply With Quote
Old 03-17-2004, 06:34 PM   #4
30 Helens Agree
 
neandrake's Avatar
 
Join Date: Jan 2002
Posts: 607
DeepBlackMagic, get my contact info from any of my posts.
Hunter2, uhm, I'm guessing events. They're basic Winsock Asynchronous sockets. They work on events.
__________________

AIM: Neandrake
EMAIL: nta0 @ yahoo . com

Operating System: Windows XP SP2
Compiler: GCC
IDE: Notepad++


Don't give up your freedom to think - www.cognitiveliberty.org
neandrake is offline   Reply With Quote
Old 03-17-2004, 07:39 PM   #5
Carnivore ('-'v)
 
Hunter2's Avatar
 
Join Date: May 2002
Posts: 2,866
>>uhm, I'm guessing events... They work on events.
A logical guess
**EDIT** Uh, do you mean network events, or WSAEVENT objects?

Cool, actually I'm working on a wrapper too right now, using async. winsock with events. Did you add support for more than 64 sockets (i.e. auto thread management)?
__________________
Just Google It. √

(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
Hunter2 is offline   Reply With Quote
Old 03-17-2004, 09:24 PM   #6
30 Helens Agree
 
neandrake's Avatar
 
Join Date: Jan 2002
Posts: 607
No, mine is very simple, using the FD_READ, etc. events. I'm definately willing to share code, and even more to work with someone on this kind of thing. My biggest problem is handling data that is sent/received and such.
__________________

AIM: Neandrake
EMAIL: nta0 @ yahoo . com

Operating System: Windows XP SP2
Compiler: GCC
IDE: Notepad++


Don't give up your freedom to think - www.cognitiveliberty.org
neandrake is offline   Reply With Quote
Old 03-17-2004, 09:29 PM   #7
Carnivore ('-'v)
 
Hunter2's Avatar
 
Join Date: May 2002
Posts: 2,866
>>using the FD_READ, etc. events
There's 2 (main?) ways of doing 'Async.' Winsock, you can use WSAAsyncSelect() and WSAEventSelect(). Which one are you using?

>>My biggest problem is handling data that is sent/received and such.
Hmm, what do you mean by that?
__________________
Just Google It. √

(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
Hunter2 is offline   Reply With Quote
Old 03-17-2004, 10:06 PM   #8
That Creepy Network Guy
 
DeepBlackMagic's Avatar
 
Join Date: Feb 2003
Posts: 265
Hey hunter howzit goin. If you recall, your early socket wrapper was the inspiration for my massive socket and thread (and soon mutex) cross platform wrapper system. Ill post a chunk of my CVS code on a website and reply to this thread with a link. It will have the bulk of the wrapper classes and a sample application (IRC Bot i think) that uses them. For practical perposes they are still a beta because some features arent completely tested, but i havent seen any major bugs in the implimentations i have used them for.
DeepBlackMagic is offline   Reply With Quote
Old 03-17-2004, 10:24 PM   #9
That Creepy Network Guy
 
DeepBlackMagic's Avatar
 
Join Date: Feb 2003
Posts: 265
I posted a chunk of the CVS directory in a directory visible to the web, remember its still somewhat untested, however im always looking for complaints, suggestions, and contributers.

http://www.SocketPimps.net/cvs/

If there are any problems with the link or you want to get in contact with me, my aim name is SocketPimp and im going to be around until about noon on thursday, then im going out of town until monday. Work, work, work, no weekend for me.
DeepBlackMagic is offline   Reply With Quote
Old 03-18-2004, 08:29 PM   #10
Carnivore ('-'v)
 
Hunter2's Avatar
 
Join Date: May 2002
Posts: 2,866
Code:
//DISABLE GAY STL WARNINGS
#pragma warning(disable:4786)
LMAO that is the greatest thing I've ever seen in my life!!! Where'd you learn how to do that?

Looking at sockets_win.h, I'm thinking it looks rather familiar. Flattered, I am Interesting idea about the UNIX vs. Win including though, and I'm going to have to look at your Thread class carefully - looks interesting.

Just thinking though, you should probably fix up your "Usage" comment block, I believe something should be mentioned about Socket::networkInit() when the program starts, and Socket::networkShutdown() when the program ends as opposed to after you're finished using the socket
__________________
Just Google It. √

(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
Hunter2 is offline   Reply With Quote
Old 03-21-2004, 08:10 PM   #11
That Creepy Network Guy
 
DeepBlackMagic's Avatar
 
Join Date: Feb 2003
Posts: 265
<just got back from trip, exhausted>

Your wrapper worked so well i just had to customize it, tweek a few things, and start cranking out a unix version of it. because it lacks a proper header your not credited in it, however i think i mentioned you in the botclass's header file. And sockets arent useful in single threaded apps. And multi-threaded apps need mutexes and semaphores.... well it kinda snowballed a littlebit and i had to slow down and think it all out.

Yes, my commenting isnt up to snuff. I was planning to go through everything and auctually comment on use once it was at a stage it would really be used. At the time the comments were writen I wasnt totally sure about exact implimentations and necessary functions for socket functions on both sides, so i kinda left it open.

Auctually, right now i think networkinit is hardwired into the constructor <naughty me> so its not entirely necessary to call. Networkshutdown on the otherhand is...<checks> doesnt seem to be in the destructor, which is probablly a smart move now that i think about it.

The thread wrapper uses Pthreads on the unix side and windows threading on the windows side. There might be a pthread implimentation for windows (vaporware). I was going to impliment ways to pause and resume and other standard thread functions but im still working on how to do that properly. Platform specific stuff is a pain sometimes. The threading class has alot of trippy void pointer trickery going on, bug me if something doesnt make sense. I think windows passed 2 void pointers, while pthreads wanted a void pointer pointer or something. Had to create a static member function to redirect the function calls.
DeepBlackMagic is offline   Reply With Quote
Old 03-22-2004, 10:29 AM   #12
Carnivore ('-'v)
 
Hunter2's Avatar
 
Join Date: May 2002
Posts: 2,866
>>sockets arent useful in single threaded apps
NetMaggotz is single-threaded, and so is ICerView and a 'chat' server/client I made

Quote:
networkinit is hardwired into the constructor <naughty me> so its not entirely necessary to call. Networkshutdown on the otherhand is...<checks> doesnt seem to be in the destructor, which is probablly a smart move now that i think about it.
Errrr, I don't know how smart a move that is actually (I didn't notice it when I looked at the code lol). Take a look at this from MSDN:
Quote:
An application must call one WSACleanup call for every successful WSAStartup call to allow third-party DLLs to make use of a WS2_32.DLL on behalf of an application. This means, for example, that if an application calls WSAStartup three times, it must call WSACleanup three times.
That's why I made it a separate static function

**EDIT**
>>because it lacks a proper header your not credited in it
That's ok, I'm just flattered that you used it at all
__________________
Just Google It. √

(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
Hunter2 is offline   Reply With Quote
Old 03-22-2004, 10:55 PM   #13
That Creepy Network Guy
 
DeepBlackMagic's Avatar
 
Join Date: Feb 2003
Posts: 265
I understand some apps can function as a single thread, however ideally there is always a thread running for the user interface, so the window doesnt hang, and one thread to process data, and one thread to recieve.

If the WSA* functions must meet up 1 to 1 then ill have to hard code network shutdown into the destructor as well. One good hack deserves another. Ill have to finalize the interface when i finally get around to releasing the code publicly. I need to make a site for people to download all of my little projects from one of these days

I guess it was just the voice of my old CS instructors echoing around in my head to credit and header everything properly. Its that sense of shame and pain they etch into you if you ever forget to include a little detail like that.
DeepBlackMagic is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Winsock issues tjpanda Windows Programming 3 12-04-2008 08:32 AM
winsock help Anubis208 C++ Programming 1 03-05-2008 07:46 AM
Simple Socialising Chat Bots bengreenwood C++ Programming 10 11-28-2007 08:42 AM
winsock pode Networking/Device Communication 2 09-26-2003 12:45 AM
Very simple question, problem in my Code. Vber C Programming 7 11-16-2002 03:57 PM


All times are GMT -6. The time now is 11:51 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22