This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

socket problem  RSS feed

 
leigh matheson
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to use sockets. I created a simple server and tested it with Telnet, using both localhost and the IP address, on the same machine and it worked fine. I went to another computer, on the same home network, and tried Telnet from there but it could not connect.  Just so someone won't suggest something trivial:
1. the IP address was correct.
2. the port address was correct.
3. I created a rule to allow incoming on the selected port.

I then wrote a simple client on the remote machie and tried that. All I got was connection timed out error.

I then disabled the firewall on both machines and still it would not connect. I checked using netstat to make sure everything looked OK and my port number was right there and its entry was the  same as 23 and the others. The only differences being the associated application.
1. experimented with telnet on the client machine. If I tried my port number (9991) it would not work. If I tried 1042, from the netstat list, it instantly connected. If I used 23 it wanted a username and password. Clearly the client machine could communicate with the server computer on some ports.
2. experimented with the client program. If I used 23 as the port it would connect to the server with no problem.

It seems I must be missing something when it comes to setting  up the port but I have no idea what. Some things I read said that the router doesn't matter since I am doing this all within the home network. One guy, though, said that he got his sockets to work when he switched modems. But he had no idea why that would do anything.

So what do I have to do to get this to work with my port 9991? To recap:
1. telnet can connect to ports remotely - 23 and 1042, for example - but not to 9991.
2. my java client program can connect to port 23 but not to 9991.

Since the ports that work are predefined and my 9991 is done through a program. I assume it must have something to with that. Not the language because my program is simple and is the same as others from the internet and my Java book. It is not the firewall because I disabled them and things still did not work. Anyone have any ideas? Thanks in advance for any guidance anyone can give.

 
Ron McLeod
Saloon Keeper
Posts: 1424
206
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
leigh matheson wrote:I am trying to use sockets. I created a simple server and tested it with Telnet, using both localhost and the IP address, on the same machine and it worked fine. I went to another computer, on the same home network, and tried Telnet from there but it could not connect.
  • Are the two computers in the same subnet?
  • How are the two computers interconnected - using an Ethernet switch?
  • What operating system are you running on the computers (Windows, Linux, ..)?


  • leigh matheson wrote:I checked using netstat to make sure everything looked OK and my port number was right there and its entry was the  same as 23 and the others.
    Can you post the output from netstat for your port?

    leigh matheson wrote:If I used 23 it wanted a username and password.
    Where did that come from?  Do you have another server application running on the server computer, or was your connection being intercepted by another device/platform such as a router/firewall?

    leigh matheson wrote:... my program is simple and is the same as others from the internet and my Java book.
    Can you post your server code here?
     
    Ron McLeod
    Saloon Keeper
    Posts: 1424
    206
    Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    ... and Welcome to CodeRanch! 
     
    leigh matheson
    Greenhorn
    Posts: 4
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    In no particular order:

    Server code of relevance ( as I said very basic, straight from the book, etc):


    Netstat stuff for 23 and 9991 (all the Listening entries are the same):


    As I said it works on one machine using either localhost or IP address (192.168.1.12).

    This is a home network hooked up through a Verizon router. They are on the same subnet. The server is win7 and I have tried connecting to it from win10 and XP. I can ping the server with no problem.

    I am assuming it was connecting to port 23 on the machine specified in the IP address (telnet 192.168.1.12 9991). Is there some reason why it wouldn't? There are no other servers running, I disabled the firewalls (I already said this and hate to repeat myself) and it made no difference. I did mention that one person I found said that replacing the router made his server/client work. And why ask if something else was intercepting things? If I knew that and couldn't figure out what to do about that I would be asking specifically about that. Can you tell me what on the router to look for? And, again, it is not the firewall since I disabled them on BOTH machines.

    Edit: Added code tags to format your code
     
    Ron McLeod
    Saloon Keeper
    Posts: 1424
    206
    Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    If it was me troubleshooting, I would take the router out of the scenario and interconnect the two machines directly with an Ethernet cable (if one or both supports auto-MDI/MDIX), or through an Ethernet switch.

    If you want to post a working example of your code, I could try running it as well and confirm that it works in my environment.
     
    leigh matheson
    Greenhorn
    Posts: 4
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Update. I woke up today and tried a second XP machine. Worked fine. I went back to the other machines and both worked fine. Nothing has been done other than one was just turned on and the others had both been hibernating. So my problem has inexplicably gone away. Thankd again. Sorry it was for nothing.
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!