Hi,
I'm trying to get humbling in VB2005. This time it's the use of a TCP-listener.
I need to have a conection open in order to send and recieve messages on both sides.
So far I'm using a VB6 Client(that way I know it is working) and make trials on a Server.
Connecting is OK, Sending to the Client is OK however if the client is sending it doesn't show on the desired Textbox ("Messagetraffic"), why??
The VB6 Client is tested for sending correctly!
her is my code:
Code:Public Class Form1 Dim Listener As Net.Sockets.TcpListener Dim thrListen As New Threading.Thread(AddressOf DoListen) Dim client As Net.Sockets.TcpClient Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub Listen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Listen.Click Dim basePort As Integer = 1360 Listener = New Net.Sockets.TcpListener(Net.IPAddress.Loopback, basePort) Listener.Start() Me.Refresh() thrListen.IsBackground = True thrListen.Start() End Sub Private Sub DoListen() Dim sr As IO.StreamReader Do Try client = Listener.AcceptTcpClient sr = New IO.StreamReader(client.GetStream) If sr.ReadToEnd.Length > 0 Then Me.MessageTraffic.Text = Me.MessageTraffic.Text & Environment.NewLine & sr.ReadToEnd sr.Close() End If Catch End Try Loop End Sub Private Sub Senden_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Senden.Click Dim sw As New IO.StreamWriter(Client.GetStream) sw.Write(MessageText.Text) Me.MessageTraffic.Text = Me.MessageTraffic.Text & Environment.NewLine & MessageText.Text MessageText.Text = vbNullChar sw.Flush() End Sub End Class




Reply With Quote