Advertisement

OnReceive() in the CSocket class. Help!

Started by October 04, 2002 08:24 PM
5 comments, last by DimSum 22 years, 3 months ago
Hi all, I''ve been playing around with CSocket for the last few days trying to get a file to send over from a client to a server. Well I''m working on the server side right now, and I''m stuck on how CSocket::OnReceive() works?? I know its a callback function but how do you use it exactly?? right now I use the Listen() function to listen to a port number. But then, how does it know when something is being sent to it?? I''m assuming that OnReceive handles this notification. For the server I have: CSocket sockSrvr; sockSrvr.Create(700); sockSrvr.Listen(); // what i do after this?? How do I use the OnReceive() function to wait for a receive from a client?? I looked at the CHATSRV sample from the Visual Studios documentation but I''m still a confused on how its used. Can someone help me with this?? Can you use code to show me too?? thanks all. -Phil
So... I inherited the CSocket class and overrode the method OnReceive(). But this method doesn''t ever get called. On my client side I do a:

pSocket->Send(data, myFileLength);

Should the send notify the OnReceive method on the server side?? I''m confused on how to notify the OnReceive() on ther server side. can someone help or explain?? thanks.

-Phil
Advertisement
Are you Connecting the two Apps with a call to CSocket.Connect??
if not thats where you need to start

-Ian
-VBLimitsSorry about the Spelling..
Listen() only tells the socket to listen for any incoming connections on that socket.

You have to actually Accept() the connection before you can call Send() and Receive() on it.
daerid@gmail.com
I see.
So when do I call Accept()?? Do I do it right after my Listen() call?? How about the parameter passed into Accept(), does the client have to connect to that CSocket instance?? I tried the following for Accept() but OnReceive() still wasn''t called:

  CSocket connectSocket;	AfxSocketInit();	pSocket = new CServerSocket ();	// create the socket		if (pSocket->Create(700, SOCK_STREAM, "###.##.##.##"))	{		pSocket->Listen ();		pSocket->Accept (connectSocket);			}  


I''m pretty sure that I''m using Accept() wrong. Can anyone help??
I''m also a little confused on what to do with "connectSocket" afterwards....

thanks again

I''m overriding the OnAccept() method and when a client trys to connect it gets called. And then when I actually try to Accept() the socket it fails...
Here''s what I have:

  void CServerSocket::vfnProcessPendingAccept(){	CSocket* clientSocket = new CSocket();	if ( m_pSocket->Accept(*clientSocket) )  // FAILS here!	{		TRACE ("Socket accepted by server.\n");	}	else	{		TRACE ("Socket NOT accepted by server.\n");	}}  

The above is called after an OnAccept().
The program fails on the Accept() call. Can anyone help me??

thanks

-Phil
Advertisement
And when i say it fails, I mean that I get an "Access Violation"

someone help plz

This topic is closed to new replies.

Advertisement