|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
TCPClient and TCPListener over the networkI 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 In article <OIsW38VNFHA.3***@TK2MSFTNGP14.phx.gbl>, Dave Coate wrote:
> Hi, Your explicitly binding to the loopback interface. You need to change> > 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 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: On the client use:> Dim Client As New TcpClient > Client.Connect(IPAddress.Parse("127.0.0.1"), 8000) > Client.Connect _ (Dns.GetHostByName ("TheServersName").AddressList(0), 8000) HTH -- Tom Shelton [MVP] 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 Show quoteHide quote "Tom Shelton" <t**@YOUKNOWTHEDRILLmtogden.com> wrote in message news:uNSJSNWNFHA.1268@TK2MSFTNGP14.phx.gbl... > In article <OIsW38VNFHA.3***@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]
Refresh DataSet - please Help Me :-(
Get Variable Out of Arraylist ReInstantiate an Object? Advice needed How can I determine WHICH exception I got in my CATCH? using StringBuilder class for concatenation? SaveFileDialog how to convert... Storing multiple text files inone file. How to restrict the multiple opening of the Same window... |
|||||||||||||||||||||||