dcsimg
Results 1 to 4 of 4

Thread: tcp server issue

  1. #1

    Thread Starter
    Member
    Join Date
    May 2011
    Posts
    48

    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

  2. #2
    Fanatic Member BlindSniper's Avatar
    Join Date
    Jan 2011
    Location
    South Africa
    Posts
    865

    Re: tcp server issue

    It is because your threading is mixed up.
    ConnectionThread = New Thread(AddressOf ClientConnection)
    that line should be deleted.

    Useful CodeBank Entries of mine
    Expand Function
    Code Compiler
    Sudoku Solver
    HotKeyHandler Class

    Read this to get Effective help on VBForums
    Hitchhiker's Guide to Getting Help at VBF

  3. #3

    Thread Starter
    Member
    Join Date
    May 2011
    Posts
    48

    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?

  4. #4

    Thread Starter
    Member
    Join Date
    May 2011
    Posts
    48

    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
  •  



Featured


Click Here to Expand Forum to Full Width