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

TCPClient and TCPListener over the network

P: n/a
Hi,

I am working on a client-server app. I can get two applications to talk to
each other on the same machine using 127.0.0.1, but as soon as I try it
using a computer name or actual IP address I get a SocketException: "No
connection could be made because the target machine actively refused it".

On the server I have a listener:
Private m_Listener As TcpListener
m_Listener = New TcpListener(IPAddress.Parse("127.0.0.1"), 8000)
m_Listener.Start()

On the Client I have a client:
Dim Client As New TcpClient
Client.Connect(IPAddress.Parse("127.0.0.1"), 8000)

This runs fine and I can get the two apps to exchange information

However, if I try to use a computer name on the client to connect...
Client.Connect("ComputerName.foo.com", 8000)

I get the error I mentioned above.

Name resolution (DNS) is fine and I have administrative rights on the box.

What am I missing?

TIA
Dave

Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
In article <OI**************@TK2MSFTNGP14.phx.gbl>, Dave Coate wrote:
Hi,

I am working on a client-server app. I can get two applications to talk to
each other on the same machine using 127.0.0.1, but as soon as I try it
using a computer name or actual IP address I get a SocketException: "No
connection could be made because the target machine actively refused it".

On the server I have a listener:
Private m_Listener As TcpListener
m_Listener = New TcpListener(IPAddress.Parse("127.0.0.1"), 8000)
m_Listener.Start()

Your explicitly binding to the loopback interface. You need to change
your server to bind to its external ip address. I would use something
like GetHostByName...

m_Listener = New TcpListener _
(Dns.GetHostByName ("TheServersName").AddressList (0), 8000)
On the Client I have a client:
Dim Client As New TcpClient
Client.Connect(IPAddress.Parse("127.0.0.1"), 8000)


On the client use:

Client.Connect _
(Dns.GetHostByName ("TheServersName").AddressList(0), 8000)

HTH
--
Tom Shelton [MVP]
Nov 21 '05 #2

P: n/a
Very cool Tom! All the examples I found were using an obsolete overload of
the TcpListener constructor that did not include the binding parameter. I
could not work it out...

Your code not only works on my local computer, but between two computers as
well. Thanks!

Dave

"Tom Shelton" <to*@YOUKNOWTHEDRILLmtogden.com> wrote in message
news:uN**************@TK2MSFTNGP14.phx.gbl...
In article <OI**************@TK2MSFTNGP14.phx.gbl>, Dave Coate wrote:
Hi,

I am working on a client-server app. I can get two applications to talk to each other on the same machine using 127.0.0.1, but as soon as I try it
using a computer name or actual IP address I get a SocketException: "No
connection could be made because the target machine actively refused it".
On the server I have a listener:
Private m_Listener As TcpListener
m_Listener = New TcpListener(IPAddress.Parse("127.0.0.1"), 8000)
m_Listener.Start()


Your explicitly binding to the loopback interface. You need to change
your server to bind to its external ip address. I would use something
like GetHostByName...

m_Listener = New TcpListener _
(Dns.GetHostByName ("TheServersName").AddressList (0), 8000)
On the Client I have a client:
Dim Client As New TcpClient
Client.Connect(IPAddress.Parse("127.0.0.1"), 8000)


On the client use:

Client.Connect _
(Dns.GetHostByName ("TheServersName").AddressList(0), 8000)

HTH
--
Tom Shelton [MVP]

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.