I have a serious problem with the asynchronous method of getting System.Net.Sockets.Socket.
Here is the code I use to open the connection:
_socket = new Socket(endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
_socket.Connect(endpoint);
byte[] buffer = new byte[1024];
_socket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, ReceiveCallback, buffer);
and here is the callback method:
private void ReceiveCallback(IAsyncResult result)
{
byte[] buffer = (byte[])result.AsyncState;
int count = _socket.EndReceive(result);
if (count > 0)
{
}
buffer = new byte[1024];
_socket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, ReceiveCallback, buffer);
}
The problem is that ReceiveCallback is never called despite a socket connection.
Can anyone help me on this?
source
share