By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,639 Members | 1,326 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,639 IT Pros & Developers. It's quick & easy.

Problems with TCP Listener

P: n/a
I have been looking at examples of code to create a simple TCP listener on a
certain port.

However they all start off with this line:

Dim tcpListener As New TcpListener(portNumber)

When I code this, I get an error which says that this is obsolete and I
should use tcpListener(IPAddress localaddr int port)

The examples I am looking at are only a few weeks old so I don't understand
why it is obsolete.

I am actually trying to listen for data on port 10002 from a network device
192.168.0.61.

I tried:
Dim ipAddress As ipAddress = Dns.Resolve("localhost").AddressList(0)
Dim tcpListener As New TcpListener(ipAddress,10002)
Dim Listener As New System.Net.Sockets.TcpListener(ipAddress, 10002)
Listener.Start()
Dim tcpClient As tcpClient = Listener.AcceptTcpClient()

but it just sits there and doesn't see any connections coming in.

On the sender side it is sending a short text message on port 10002 to host
192.168.0.2, which is my PC. Is this the same as 127.0.0.0 as defined in the
line:

Dim ipAddress As ipAddress = Dns.Resolve("localhost").AddressList(0)

above?

Thanks

-Jerry
Mar 29 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
localhost, or loopback, should probably be 127.0.0.1
But if you have a local network then just use their IPs, such as your
192.168.0.2 example.

I think you might be using examples for VS2003 in VS2005?
In your code you have declared two Listeners, but you should only have
1 listener per port/ip address.
Have it sit in an infinate loop calling AcceptSocket (well, thats in
VS2003, not sure about 2005).

Also, make sure you have your PC firewall configured to allow that port
through, on BOTH machines.
This could be your headache (windows firewall by default will be
blocking this port).

Mar 29 '06 #2

P: n/a

Jerry Spence1 wrote:
I have been looking at examples of code to create a simple TCP listener on a
certain port.

However they all start off with this line:

Dim tcpListener As New TcpListener(portNumber)

When I code this, I get an error which says that this is obsolete and I
should use tcpListener(IPAddress localaddr int port)

The examples I am looking at are only a few weeks old so I don't understand
why it is obsolete.

I am actually trying to listen for data on port 10002 from a network device
192.168.0.61.

I tried:
Dim ipAddress As ipAddress = Dns.Resolve("localhost").AddressList(0)
Dim tcpListener As New TcpListener(ipAddress,10002)
Dim Listener As New System.Net.Sockets.TcpListener(ipAddress, 10002)
Listener.Start()
Dim tcpClient As tcpClient = Listener.AcceptTcpClient()

but it just sits there and doesn't see any connections coming in.

On the sender side it is sending a short text message on port 10002 to host
192.168.0.2, which is my PC. Is this the same as 127.0.0.0 as defined in the
line:

Dim ipAddress As ipAddress = Dns.Resolve("localhost").AddressList(0)

above?

Thanks

-Jerry


Try replacing "localhost" with a call to Dns.GetHostName (). By using
localhost, you are binding to the loopback interface (127.0.0.1) -
which, means most likely you aren't going to receive traffic for
192.168.0.2.

--
Tom Shelton [MVP]

--
Tom Shelton [MVP]

Mar 29 '06 #3

P: n/a
Thanks you for both replies. Steven, the two listensers was a cut and paste
problem (just to confuse!). Yes, the Dns.GetHostName () worked a treat.

Thanks very much.

-Jerry
"Tom Shelton" <to*@mtogden.com> wrote in message
news:11**********************@g10g2000cwb.googlegr oups.com...

Jerry Spence1 wrote:
I have been looking at examples of code to create a simple TCP listener
on a
certain port.

However they all start off with this line:

Dim tcpListener As New TcpListener(portNumber)

When I code this, I get an error which says that this is obsolete and I
should use tcpListener(IPAddress localaddr int port)

The examples I am looking at are only a few weeks old so I don't
understand
why it is obsolete.

I am actually trying to listen for data on port 10002 from a network
device
192.168.0.61.

I tried:
Dim ipAddress As ipAddress = Dns.Resolve("localhost").AddressList(0)
Dim tcpListener As New TcpListener(ipAddress,10002)
Dim Listener As New System.Net.Sockets.TcpListener(ipAddress, 10002)
Listener.Start()
Dim tcpClient As tcpClient = Listener.AcceptTcpClient()

but it just sits there and doesn't see any connections coming in.

On the sender side it is sending a short text message on port 10002 to
host
192.168.0.2, which is my PC. Is this the same as 127.0.0.0 as defined in
the
line:

Dim ipAddress As ipAddress = Dns.Resolve("localhost").AddressList(0)

above?

Thanks

-Jerry


Try replacing "localhost" with a call to Dns.GetHostName (). By using
localhost, you are binding to the loopback interface (127.0.0.1) -
which, means most likely you aren't going to receive traffic for
192.168.0.2.

--
Tom Shelton [MVP]

--
Tom Shelton [MVP]

Mar 29 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.