
marmav (Normal User)
Newbie
    
Messaggi: 1
Iscritto: 04/06/2010
|
Salve,
sono nuovo del forum, avrei bisogno di capire come intercettare l'evento di disconnessione di un client dal software server che sto sviluppando.
di seguito posto il codice sviluppato fino ad ora, spero mi riusciate ad aiutare
Codice sorgente - presumibilmente VB.NET |
Private Sub form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load serverSocket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) Dim IpEndPoint As IPEndPoint = New IPEndPoint(IPAddress.Any, 8888) serverSocket.Bind(IpEndPoint) serverSocket.Listen(20) serverSocket.BeginAccept(New AsyncCallback(AddressOf OnAccept), Nothing) End Sub Private Sub OnAccept(ByVal ar As IAsyncResult) clientSocket = serverSocket.EndAccept(ar) serverSocket.BeginAccept(New AsyncCallback(AddressOf OnAccept), Nothing) AddClient(clientSocket) End Sub Delegate Sub _AddClient(ByVal client As Socket) Private Sub AddClient(ByVal client As Socket) If InvokeRequired Then Invoke(New _AddClient(AddressOf AddClient), client) Exit Sub End If txtStatoServer.Text &= "Connesso " & CStr((IPAddress.Parse(CType(client.RemoteEndPoint, IPEndPoint).Address.ToString).ToString)) & vbCrLf End Sub
|
Ultima modifica effettuata da marmav il 13/07/2012 alle 19:25 |