Salve a tutti..ho creato un server con le classi tcplistener e tcpclient. Ho impostato 2 timer, uno per l'ascolto delle nuove connessioni dai client e un altro per la ricezione dei byte.
codice:
If tcplisten.Pending Then
client = tcplisten.AcceptTcpClient
netstrm = client.GetStream
Dim IPAddress As New IPAddress(Dns.GetHostByName(Dns.GetHostName).AddressList(0).Address)
Dim strIPAddress As String = IPAddress.ToString
Dim ip As String = client.Client.RemoteEndPoint.ToString.Substring(0, client.Client.RemoteEndPoint.ToString.IndexOf(":"))
Ricevi.Enabled = True
Utenti.Items.Add(ip)
GroupBox1.Text = "Utenti Connessi: " & Utenti.Items.Count()
Dim bytes As Byte() = System.Text.Encoding.ASCII.GetBytes("Connesso al server: " & strIPAddress & " Tuo IP: " & ip)
netstrm.Write(bytes, 0, bytes.Length)
netstrm.Flush()
End If
codice:
Private Sub Ricevi_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Ricevi.Tick
If netstrm.DataAvailable = True Then
Dim stringar As String
Dim bytes(client.ReceiveBufferSize()) As Byte
netstrm.Read(bytes, 0, bytes.Length)
stringar += System.Text.Encoding.ASCII.GetString(bytes)
TextBox1.Text += stringar & vbCrLf
End If
End Sub
vorrei gestire una liste user..sono riuscito fino ad ora solo ad aggiungere man mano quelli che entrano ma non riesco a trovare l'evento che mi permette di rilevare quando un client si disconnette.
mi potreste aiutare..?? Grazieee
ps qst domanda già l'ho fatta in un post da me creato precedentemente solo che ho preferito ricopiarlo qui per non andare off topic e per essere più facile da trovare dagli user che verranno