AsyncSockets ??

Tigran

Member
Joined
Sep 10, 2003
Messages
7
Hi..
There is a problem..

I call RecieveCallback function, which is CALLBACK function for asynchronious sockets method, BeginRecieve..my kode looks like this...

Code:
private static void RecieveCallback(IAsyncResult ar)	{

NotifyServer.StateObject so = NotifyServer.StateObject)ar.AsyncState;
			
Socket handle = so.workSocket;
IAsyncResult res = null;
	try{
		int bytesRead = -1;
		bytesRead = so.workSocket.EndReceive(ar);
		//MessageBox.Show(bytesRead.ToString());
		if(bytesRead > 0){so.sb.Append(Encoding.ASCII.GetString(so.buffer,0,bytesRead));
					res = handle.BeginReceive(so.buffer,0,MAX_SIZE,0,new AsyncCallback(RecieveCallback),so);					
					//MessageBox.Show(so.sb.Length.ToString());
				}//if		
				else
				   MessageBox.Show(so.sb.Length.ToString()); !!!!!!!!!!!!

			}
			catch(Exception ex){
				MessageBox.Show(String.Format("NotifyServer::RecieveCallback Error {0}",ex.Message));
			}

}

The problem is , that method MessageBox hasnt ever been called,why???This seems like operation of recieving data never copletes, but it is wrong, I get all bytes which sent
 
This is an interesting thing, because in maybe any sample wrote like this, and more, when I pass this code in debug mode, I check, that after recieving last bytes the line

res = handle.BeginReceive(so.buffer,0,MAX_SIZE,0,new AsyncCallback(RecieveCallback),so);

doesnt call RecieveCallback method in the recursive loop, how does it understand that thet are no more bytes , if doesnt call this method ???
 
Back
Top