Skip to main content
gamedev.net
🔒 Locked

winsock

Started by AlexM 2 replies 550+ views
Original Post
AlexM
AlexM
I''m using MFC''s CAsyncSocket, overriding the virtual members. For right now I just want to run two programs simultaneously on my computer, one sends a message and the other receives it (of course I am DIALED UP, so the message should travel to and back from my connection host). I get a funny error when I try to connect to the listening socket that says something like "an operation was attempted on something that isn''t a socket". This is the class: class MySock : public CAsyncSocket { public: MySock *server; //socket that is used to accept HWND h; void OnAccept(); void OnConnect(); void OnSend(); void OnReceive(); }; void MySock::OnConnect() //client { MessageBox(h,"Connected",NULL,MB_OK); } void MySock::OnAccept() //server, creates server socket { server = new MySock(); Accept(*server); server->h = h; MessageBox(h,"Accepted connection",NULL,MB_OK); } void MySock::OnReceive() { char msg[100]; Receive(msg,100); MessageBox(h,msg,NULL,MB_OK); } void MySock::OnSend() { Send("hahahahahahahahah",10); } Then I create a socket in both programs, one calls MySock::Listen() and the other calls MySock::Connect(), specifying the same IP address I used to create the server socket and its current port. I''ve checked all other points and the error occurs only in MySock::Connect() call. I can''t figure it out. Thanks for any help, Alex.
AlexM
AlexM
really need help here...
Don Bishop
Don Bishop
I''ve never used MFC''s sockets, but I think I might see your problem. Basically you want to call Recieve() on the socket that is set with Accept(), and not the main Listen()ing server socket.

Let me know if this isn''t the problem, or you still can''t get it to work....

Don
Prefect
Prefect
Never, never ever use the WAExxx-functions and classes of WinSock. Why? Because you''ll have it soo much easier when you finally decide the time has come to port / learn to program on a different platform.

cu,
Prefect
Widelands - laid back, free software strategy

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.