-
tcp server issue
I have a simple tcp server listening for clients. I use a mud client to test if it's working. The mud client says that it's connected to 127.0.0.1, but the server doesn't show the msgbox that a client has connected. Any suggestions?
Code:
Imports System.Net
Imports System.Net.Sockets
Imports System.IO
Imports System.Threading
Public Class Form1
Dim Host As New TcpListener(IPAddress.Any, 45050)
Dim Client As New TcpClient
Dim ConnectionSocket As Socket
Dim ConnectionThread As New Thread(AddressOf ClientConnection)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Host.Start()
ConnectionThread = New Thread(AddressOf ClientConnection)
End Sub
Private Sub ClientConnection()
If Host.Pending = True Then
Client = Host.AcceptTcpClient
ConnectionSocket = Host.AcceptSocket
MsgBox("Client is connected")
End If
End Sub
End Class
-
Re: tcp server issue
It is because your threading is mixed up.
ConnectionThread = New Thread(AddressOf ClientConnection)
that line should be deleted.
-
Re: tcp server issue
I took out the ConnectionThread = new thread(addressof ClientConnection) but left the Dim part, still same result.
gmud connects, but the server program does nothing. Is there something wrong with the .pending?
-
Re: tcp server issue
Adding a timer, and changing the loop a bit fixed the issue.
I set the timer to trigger every 100 intervals and it just calls the ClientConnection(). Why threading isn't working I'm not sure, but I guess I can remove that from my code now :)