P
Pete Davis
I've written an async socket server app and I'm having an issue with the
EndReceive() call.
My begin receive call is:
sockState.RemoteSocket.BeginReceive(sockState.ReceiveBuffer, 0,
SocketState.BufferSize, 0, new AsyncCallback(this.ReadCallback), sockState);
The ReadCallback() method begins:
private void ReadCallback(IAsyncResult asyncResult)
{
Debug.WriteLine("SocketServer.ReadCallback: Entry");
SocketState socketState = (SocketState) asyncResult.AsyncState;
int bytesRead = socketState.RemoteSocket.EndReceive(asyncResult);
Debug.WriteLine(String.Format("SocketServer.ReadCallback: End receive with
{0} bytes", bytesRead));
The first Debug.WriteLine() gets called when I connect, but EndReceive seems
to block after the send.
My test application is very simple. All it does is:
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp);
IPEndPoint ep = new IPEndPoint(IPAddress.Loopback, 7451);
sock.Connect(ep);
HelloMsg hm = (HelloMsg)
SocketMessageFactory.CreateSocketMessage(SocketMsgType.HELLO);
sock.Send(hm.ToBuffer());
So, as I said, the server registers the connection and gets to the
ReadCallback method, but blocks on EndReceive. Any ideas on what I'm
missing?
Thanks.
Pete
EndReceive() call.
My begin receive call is:
sockState.RemoteSocket.BeginReceive(sockState.ReceiveBuffer, 0,
SocketState.BufferSize, 0, new AsyncCallback(this.ReadCallback), sockState);
The ReadCallback() method begins:
private void ReadCallback(IAsyncResult asyncResult)
{
Debug.WriteLine("SocketServer.ReadCallback: Entry");
SocketState socketState = (SocketState) asyncResult.AsyncState;
int bytesRead = socketState.RemoteSocket.EndReceive(asyncResult);
Debug.WriteLine(String.Format("SocketServer.ReadCallback: End receive with
{0} bytes", bytesRead));
The first Debug.WriteLine() gets called when I connect, but EndReceive seems
to block after the send.
My test application is very simple. All it does is:
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp);
IPEndPoint ep = new IPEndPoint(IPAddress.Loopback, 7451);
sock.Connect(ep);
HelloMsg hm = (HelloMsg)
SocketMessageFactory.CreateSocketMessage(SocketMsgType.HELLO);
sock.Send(hm.ToBuffer());
So, as I said, the server registers the connection and gets to the
ReadCallback method, but blocks on EndReceive. Any ideas on what I'm
missing?
Thanks.
Pete