-
Dec 3rd, 2011, 01:00 AM
#1
Thread Starter
Member
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
-
Dec 3rd, 2011, 05:12 AM
#2
Re: tcp server issue
It is because your threading is mixed up.
ConnectionThread = New Thread(AddressOf ClientConnection)
that line should be deleted.
-
Dec 3rd, 2011, 05:17 PM
#3
Thread Starter
Member
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?
-
Dec 3rd, 2011, 05:25 PM
#4
Thread Starter
Member
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
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|