Re: Asynchronous sockets and buffer size
- From: Matthew Geyer <nospam@xxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 26 May 2007 22:07:52 -0700
Sorry, I don't know what I expected with an explanation like that.
here's what my code is like with all the fluff cut out:
private void OnReceive(IAsyncResult asyn)
{
ObjectThing Job = (ObjectThing)asyn.AsyncState;
long BytesReceived = Job.s.EndReceive(asyn);
if (BytesReceived > 0)
{
ProcessData(Job);
Job.s.BeginReceive(Job.buffer, 0, Job.buffer.Length, 0, new AsyncCallback(this.OnReceive), Job);
}
else
{
Job.s.Close();
Job.s = null;
}
}
private void OnSend(IAsyncResult asyn)
{
ObjectThing Job = (ObjectThing)asyn.AsyncState;
Job.s.EndSend(asyn);
Job.s.BeginReceive(Job.buffer, 0, Job.buffer.Length, 0, new AsyncCallback(this.OnReceive), Job);
}
private void OnConnect(IAsyncResult asyn)
{
ObjectThing Job = (ObjectThing)asyn.AsyncState;
Job.s.EndConnect(asyn);
Job.s.BeginSend(Encoding.ASCII.GetBytes(Job.data + "\r\n"), 0, Encoding.ASCII.GetBytes(Job.data + "\r\n").Length, 0, new AsyncCallback(this.OnSend), Job);
}
Job.s is the socket and i call Job.s.BeginConnect(...) to start.
Michael Rubinstein wrote:
Matthew, I am not quite sure which 'excellent MSDN example' you were following. Normally TCP/IP servers (I assume you do TCP/IP) do not imitate disconnect - clients do. On the server side do not terminate client connection until the client disconnects - BeginReceive() on the server side returns 0, and you will not loose data..
Michael
- Follow-Ups:
- Re: Asynchronous sockets and buffer size
- From: Michael Rubinstein
- Re: Asynchronous sockets and buffer size
- From: Peter Duniho
- Re: Asynchronous sockets and buffer size
- References:
- Asynchronous sockets and buffer size
- From: Matthew Geyer
- Re: Asynchronous sockets and buffer size
- From: Michael Rubinstein
- Asynchronous sockets and buffer size
- Prev by Date: Re: Missing Row in DataSet
- Next by Date: Re: Asynchronous sockets and buffer size
- Previous by thread: Re: Asynchronous sockets and buffer size
- Next by thread: Re: Asynchronous sockets and buffer size
- Index(es):
Relevant Pages
|