Async Socket Listener on separate thread - VB.net
        Posted  
        
            by TheHockeyGeek
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by TheHockeyGeek
        
        
        
        Published on 2010-03-26T13:37:04Z
        Indexed on 
            2010/03/26
            14:03 UTC
        
        
        Read the original article
        Hit count: 380
        
I am trying to use the code from Microsoft for an Async Socket connection. It appears the listener runs in the main thread locking the GUI. I am new at both socket connections and multi-threading all at the same time. Having a hard time getting my mind wrapped around this all at once.
The code used is at http://msdn.microsoft.com/en-us/library/fx6588te.aspx Using this example, how can I move the listener to its own thread?
 Public Shared Sub Main()
    ' Data buffer for incoming data.
    Dim bytes() As Byte = New [Byte](1023) {}
    ' Establish the local endpoint for the socket.
    Dim ipHostInfo As IPHostEntry = Dns.GetHostEntry(Dns.GetHostName())
    Dim ipAddress As IPAddress = ipHostInfo.AddressList(1)
    Dim localEndPoint As New IPEndPoint(ipAddress, 11000)
    ' Create a TCP/IP socket.
    Dim listener As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
    ' Bind the socket to the local endpoint and listen for incoming connections.
    listener.Bind(localEndPoint)
    listener.Listen(100)
© Stack Overflow or respective owner