Ti Posto il codice cosi si capisce meglio il problema
I programmi funzionano che il Client all'avvio si connette in automatico al server in locale.
Il server all'avvio in automatico accetta.
Quando il server è connesso la prima cosa che fa è attivare il timer per la lettura della chat e un altro timer che sarebbe quello per mandare le informazioni del computer al client.
Il client quando è connesso anche lui attiva il timer per la lettura della chat e un altro timer che sarebbe quello per ricevere le informazioni del computer server per poi smistarle nelle determinate TextBox
esempio.
Nome Computer nella textbox1
Sistema Operativo nella textbox2
CODICE CLIENT
Imports System.Net.Sockets
Imports System.Text.UTF8Encoding
Public Class Form1
Dim Client As TcpClient
Dim Flusso As NetworkStream
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Client = New TcpClient
Try
Client.Connect("127.0.0.1", 8888)
Catch SE As SocketException
Timer1.Stop()
Timer1.Start()
End Try
If Client.Connected Then
Timer1.Stop()
TextBox2.Text = TextBox2.Text & "Connessione OK" & vbCrLf
Flusso = Client.GetStream()
Timer2.Start()
Timer3.Start()
Else
TextBox2.Text = TextBox2.Text & "Connessione fallita" & vbCrLf
Timer1.Stop()
Timer1.Start()
End If
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
If Client.Available > 0 Then
Dim Temporaneo(Client.Available - 1) As Byte
Flusso.Read(Temporaneo, 0, Temporaneo.Length)
Dim Testo As String = UTF8.GetString(Temporaneo)
TextBox2.Text = TextBox2.Text & Testo & vbCrLf
End If
End Sub
Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
If Client.Available > 0 Then
Dim Temporaneo1(Client.Available - 1) As Byte
Flusso.Read(Temporaneo1, 0, Temporaneo1.Length)
Dim Testo1 As String = UTF8.GetString(Temporaneo1)
TextBox4.Text = TextBox4.Text & Testo1 & vbCrLf
End If
If Client.Available > 0 Then
Dim Temporaneo2(Client.Available - 1) As Byte
Flusso.Read(Temporaneo2, 0, Temporaneo2.Length)
Dim Testo2 As String = UTF8.GetString(Temporaneo2)
TextBox5.Text = TextBox5.Text & Testo2 & vbCrLf
End If
Timer3.Stop()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Temporaneo() As Byte = UTF8.GetBytes(TextBox1.Text)
Flusso.Write(Temporaneo, 0, Temporaneo.Length)
TextBox1.Text = ""
End Sub
End Class
------------------------------CODICE SERVER------------------
Imports System.Net.Sockets
Imports System.Text.UTF8Encoding
Public Class Form1
Dim Listener As TcpListener
Dim Client As TcpClient
Dim Flusso As NetworkStream
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Listener = New TcpListener(8888)
Listener.Start()
Timer1.Start()
TextBox2.Text = TextBox2.Text & "Sono in attesa di qualcuno..." & vbCrLf
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If Listener.Pending() Then
Timer1.Stop()
Client = Listener.AcceptTcpClient()
Listener.Stop()
Flusso = Client.GetStream()
Timer2.Start()
Timer3.Start()
TextBox2.Text = TextBox2.Text & "Si è connesso un utente" & vbCrLf
End If
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
If Client.Available > 0 Then
Dim Temporaneo(Client.Available - 1) As Byte
Flusso.Read(Temporaneo, 0, Temporaneo.Length)
Dim Testo As String = UTF8.GetString(Temporaneo)
TextBox2.Text = TextBox2.Text & Testo & vbCrLf
End If
End Sub
Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
Dim Temporaneo1() As Byte = UTF8.GetBytes("IP Locale"
Flusso.Write(Temporaneo1, 0, Temporaneo1.Length)
Dim Temporaneo2() As Byte = UTF8.GetBytes("Nome Computer"
Flusso.Write(Temporaneo2, 0, Temporaneo2.Length)
Timer3.Stop()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Temporaneo() As Byte = UTF8.GetBytes(TextBox1.Text)
Flusso.Write(Temporaneo, 0, Temporaneo.Length)
TextBox1.Text = ""
End Sub
End Class
------
Il problema sta che quando il server invia le informazioni, il client le riceve però le legge entrambe nella textbox per la chat senza spazi.
Grazie moltissimo per l'aiuto che mi state dando