Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SocketException error

Status
Not open for further replies.

Simulacra

MIS
Joined
Jun 8, 2006
Messages
2
Location
US
Hello,

I am new to VB.Net. I bought this book "Network Programming in .Net" by Fiach Reid, to become familiar with VB and .Net. Anywho, I am testing one of his examples where you create a client that xfers a file to the server. What a great example. So I go ahead and type it in character for character, when I start to run the server in debug it stops at tcpListener.Start()

Here is the method

Code:
Public Sub listenerThread()


        Dim myHost As System.Net.IPHostEntry = Dns.GetHostEntry("localhost")
        Dim myIP As System.Net.IPAddress = myHost.AddressList(0)
        Dim tcpListener As New TcpListener(myIP, 80)
        Dim handlerSocket As Socket
        Dim thdstHandler As ThreadStart
        Dim thdHandler As Thread

        tcpListener.Start()

        Do
            handlerSocket = tcpListener.AcceptSocket
            If handlerSocket.Connected Then
                lbConnections.Items.Add(handlerSocket.RemoteEndPoint.ToString() + "Connected.")
                SyncLock (Me)
                    alSockets.Add(handlerSocket)
                End SyncLock
                thdstHandler = New ThreadStart(AddressOf handlerThread)
                thdHandler = New Thread(thdstHandler)
                thdHandler.Start()
            End If
        Loop
    End Sub

The error I get in VB is

SocketException - only one usage of each socket address (protocol/network address/port) is normally permitted.

I am having trouble seeing the problem. Could someone point it out?

Thanks
 
You can only have one socket number bindededed at a time :)

Change your socket number to something unused like 1001. If you're going to do a lot of network programming, I'd recommend researching commonly used socket (or port) numbers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top