Here is the part of code which fail :
public void WaitConnexion(IPEndPoint localEP)
{
if (localEP.Port != 9000)
{
MessageBox.Show("Le port doit être 9000");
return;
}
LocalEndPoint = localEP;
if (reader.socket.Connected)
{
MessageBox.Show("Vous êtes déjà connecté", "Conflit de connexion", MessageBoxButton.OK, MessageBoxImage.Exclamation);
return;
}
// on bind le socket avec le endpoint local, et on le met en attente de connexion asynchrone
// reader.socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
reader.socket.Bind(localEP);
reader.socket.Listen(1);
reader.socket.BeginAccept(new AsyncCallback(WaitConnexionCallBack), reader.socket);
}
and here is the diconnect method with its callback :
public void Disconnect()
{
if (!reader.socket.Connected)
return;
reader.socket.BeginDisconnect(true, new AsyncCallback(DisconnectCallBack), reader.socket);
}
private void DisconnectCallBack(IAsyncResult result)
{
reader.socket = (result.AsyncState as Socket);
reader.socket.EndDisconnect(result);
if (Disconnected != null)
Disconnected(this, EventArgs.Empty);
}