The IAsyncResult object was not returned from the corresponding asynchronous method of this class

时间:2015-06-30 13:36:37

标签: c# .net sockets asyncsocket

I have recently coded a Csharp server and client program where they can send messages to each other. I have started of basic and I ave run into a problem, when I connect the first client everything is fine, the messages send and receive fine from booth partys. When I add a second client I receive a Argument exception, shown in the image below.

Accept method:

public void NewConnection_Incoming(IAsyncResult AR)
{
    Socket incomingMessageSocket = _incomingSocket.EndAccept(AR);
    string IP = incomingMessageSocket.RemoteEndPoint.ToString().Split(':')[0];
    byte[] _buffer = new byte[1024];
    Console.ForegroundColor = ConsoleColor.Green;
    Console.WriteLine("[" + DateTime.Now.ToShortTimeString() + "] New connection received on incoming socket.");
    Console.ForegroundColor = ConsoleColor.White;

    this._incomingSocket.BeginAccept(new AsyncCallback(NewConnection_Incoming), _incomingSocket);

    incomingMessageSocket.BeginReceive(_buffer, 0, _buffer.Length,
        SocketFlags.None, new AsyncCallback(OnReceiveMessage), incomingMessageSocket);    
}

Image:

enter image description here

0 个答案:

没有答案