
TCPListener always listens on port 0?
Ben,
Here is a little chunk of code I am using for the TCP Listener to begin
listening on port 50.
mobjListener = New System.Net.Sockets.TCPListener(New
System.Net.IPAddress("100.100.100.1"), 50)
mobjListener.Start()
Do Until mobjListener.Pending = True
application.DoEvents()
Loop
'OK, we have a pending connect request
mobjSocket = mobjListener.Accept()
....and so on and so on...
I hope this helps.
Quote:
> I seem to be having a bit of trouble (moreso than before) with the
> TCPListener class. Here is the code I'm using:
> Dim ep As Net.IPEndPoint
> Dim ip As Net.IPAddress
> ip = New IPAddress("127.0.0.1")
> ep = New Net.IPEndPoint(ip, iPort)
> g_tcpListen = New TCPListener(ep)
> g_tcpListen.Start()
> I've also tried it like this:
> g_tcpListen = New TCPListener(iPort)
> g_tcpListen.Start()
> (where iPort is an integer with a valid port number and g_tcpListen is a
> TCPListener class)
> Both, when run, give me an unexpected result of listening on port 0. What
> would cause this? Just a bug in the code? If so, does anyone know of any
> documentation on how to setup the Socket class to listen?
> Ben Vanik