Tcplistener not.... listening?
Hi guys, I have a problem.
I have a tcplistener listening on port 8500 and a background worker accepting a client. The program works fine on the server computer, but when I telnet to port 8500 on another PC it doesn't work. How may I do that? Im guessig it is a firewall problem but both PCs are connected on the same network. How would I set up something like this?
Thanks in advance,
Farrow
Re: Tcplistener not.... listening?
I also forgot to mention that both PCs are running Windows 7.
Re: Tcplistener not.... listening?
Code?
Telnet is not the same as TCP.
Re: Tcplistener not.... listening?
Public tcp = New System.Net.Sockets.TcpListener(8500)
tcp.Start()
...in the background worker
tcp.AcceptTcpClient()
Re: Tcplistener not.... listening?
Are you trying to connect using your local IP, public IP, or what?
Re: Tcplistener not.... listening?
The server is 192.168.1.105, which is what Im trying to connect to. If it helps, here is my telnet command:
telnet 192.168.1.105 8500
I am using local IP.
Again, this works on the server using localhost but, oddly enough, telnetting to 192.168.1.105 from the server itself does not yield a connection. Doing a ipconfig and a nmap scan both revealed that that is actually the ip of the server. At this point I am sure it is a firewall problem, but i dont know.
Re: Tcplistener not.... listening?
I did some tests of my own and I found that you have to specify the IP of the listener.
vb Code:
Dim IP As IPAddress = IPAddress.Parse("127.0.0.1")
Dim PORT As Integer = 8500
Dim Listener As New TcpListener(IP, PORT)
Listener.Start()
The above would only work when I ran telnet on the server. However to telnet from another computer on the network to the server I had to specify the IP address like this:
vb Code:
Dim IP As IPAddress = IPAddress.Parse("192.168.1.105")
Dim PORT As Integer = 8500
Dim Listener As New TcpListener(IP, PORT)
Listener.Start()
I did NOT have to port forward, or turn my firewall off. Also, It's best you don't hardcode the IP and get the local IP on the fly.
Re: Tcplistener not.... listening?
Just wanted to add... In VS2008 it gives an error when only supplying a port to the listener, saying that the method has been deprecated. So it's best you supply an IP and a Port like my examples above.
Re: Tcplistener not.... listening?
Lets say that you get the ports set up correctly and are able to telnet address 8500. Are you prepared for the messages that telnet expects to send and receive responses for?
Re: Tcplistener not.... listening?
I do not plan on using Telnet as the client. I am simply using telnet to connect to my PC to verify it is working. There will be a client portion of the program soon, though.
@1 above, thanks alot for your solution. I'm sorry if this is asking too much but... how would I programatically go about finding the local IP of the server?
Thanks to all who have helped so far. I believe I am nearing the solution.