|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Problems with TCP Listenercertain 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 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). Jerry Spence1 wrote:
Show quoteHide quote > I have been looking at examples of code to create a simple TCP listener on a Try replacing "localhost" with a call to Dns.GetHostName (). By using> 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 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] 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 Show quoteHide quote "Tom Shelton" <t**@mtogden.com> wrote in message news:1143616283.670836.230960@g10g2000cwb.googlegroups.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] >
Datagrid problem
Doing some extra task while saving databind Controls in VB.Net 2005 ? Dynamically Loading Programs select all text when textbox1 is clicked Auto-stop DUN via VB.Net? Oledb VS Sql. Oledb works with Sql Server; Sql doesn't...why Adding HTML code to project. SQL Server and ADO.Net best method Re: ContextSwitchDeadlock was detected Error when trying to create new SQL Server login via ado.Net |
|||||||||||||||||||||||