Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi..

There is a problem..

 

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

 

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 hasn't ever been called,why???This seems like operation of recieving data never copletes, but it is wrong, I get all bytes which sent

Posted

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);

 

doesn't call RecieveCallback method in the recursive loop, how does it understand that thet are no more bytes , if doesn't call this method ???

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...