473,385 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Problems with TCP Listener

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
3 4008
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

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Axel Dachtler | last post by:
Hi, I have a listener problem. The listener cannot read SERVICE_NAME in TNS-Descriptor. The service-name I specified in Oracle Net Manager for this database is testdb as well. ...
2
by: William F. O'Neill | last post by:
Have just upgraded my home installation of Oracle 10g. Was using 9i. The installation seemed to go fine, but with all the documentation, I'm having a hard time getting the Enterprise Manager to...
3
by: Bill | last post by:
When vb6 Winsock.RemoteHost is set to "127.0.0.1", c# socket listener cannot hear connect request (my old vb6 winsock listener could hear it...). Why doesn't this work, and is there a work...
4
by: Phil Grimpo | last post by:
I had previously explained this problem in a different thread, but now that I have an IISState log, I figured I'd re-start the thred. My situation and the log are following... I have a very odd...
6
by: Steve Teeples | last post by:
I have been perplexed by how to best treat an event that spans different classes. For example, I have a form which a user inputs data. I want to broadcast that data via an event to another...
5
by: mivey4 | last post by:
Hi, First off, I am aware that this is a very heavily documented error and I have done my homework for throughly researching probable causes before deciding to post my problem here. At this point,...
5
by: JasonX | last post by:
Im having problems with my program, in that if I close the main form while my new thread is doing work which involves writing to the main form, then I get an error about a disposed object. To...
2
by: vertozia | last post by:
Hey there, ive been having difficulty placing an image, this is my screenshot, and what ive done so far: http://img341.imageshack.us/img341/9894/gridwg2.jpg /** * ConnectFourGUI * Provide...
1
by: michael ngong | last post by:
michael.john@gmx.at (Michael John) wrote in message news:<90cc4edd.0306230900.28075193@posting.google.com>... MIchael I you stated the OS and platform that could make it easier to address your...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.