N
Nuno Magalhaes
Does anyone know why the BeginAccept doesn't work? If, in the code
below, I do the normal Accept function I can get the client socket but
it seems that the callback isn't really called.
Here's the code:
-----------------------------
private Socket socket;
private Socket clientSocket;
public TcpServer(string serverIP,int serverPort)
{
clientSocket=null;
socket=new
Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
IPEndPoint ep=new IPEndPoint(IPAddress.Parse(serverIP),serverPort);
socket.Bind(ep);
socket.Listen(10);
socket.BeginAccept(new AsyncCallback(AcceptConnection),socket);
}
private void AcceptConnection(IAsyncResult ar)
{
Socket socket=(Socket)ar.AsyncState;
clientSocket=socket.EndAccept(ar);
//throw new Exception("TCP Accepted on
#"+clientSocket.RemoteEndPoint.ToString());
throw new Exception("Yuhuu");
}
below, I do the normal Accept function I can get the client socket but
it seems that the callback isn't really called.
Here's the code:
-----------------------------
private Socket socket;
private Socket clientSocket;
public TcpServer(string serverIP,int serverPort)
{
clientSocket=null;
socket=new
Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
IPEndPoint ep=new IPEndPoint(IPAddress.Parse(serverIP),serverPort);
socket.Bind(ep);
socket.Listen(10);
socket.BeginAccept(new AsyncCallback(AcceptConnection),socket);
}
private void AcceptConnection(IAsyncResult ar)
{
Socket socket=(Socket)ar.AsyncState;
clientSocket=socket.EndAccept(ar);
//throw new Exception("TCP Accepted on
#"+clientSocket.RemoteEndPoint.ToString());
throw new Exception("Yuhuu");
}