TCPListener always listens on port 0? 
Author Message
 TCPListener always listens on port 0?

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



Fri, 30 May 2003 02:08:01 GMT  
 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



Mon, 02 Jun 2003 04:21:08 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. VB Port Listening ** Only listening not bound to a port

2. Listen to port or port sniff...

3. How can you Listen to port 80

4. Using Sockets/Ports to listen for POP3 traffic

5. How to make winsock control listen on an used port

6. Finding and listening to ports used by other programs

7. Listen to TCP/IP PORT

8. Listen to LPT-port???????

9. Listening to a comm port???

10. Listen to a COM-port

11. Port Listening

12. Com Port Listening

 

 
Powered by phpBB® Forum Software