A good, simple tutorial for making sockets work over the Internet.
John McClellan
Ranch Hand
Joined: Aug 15, 2011
Posts: 35
posted
0
Hello. Yesterday and today I've learned a few basic things about making sockets in Java an using them to create client/server-type applications. The problem here is that I'm not seeing much in the way of really simple, beginner's tutorials about how to apply that across more than a single computer (specifically across the Internet). All I've seen so far at least looks like it would only work on a single computer (they use localhost as the server, don't get into URLs, etc.). Does anybody have a good link to such a tutorial please? Thanks!
The reason you aren't seeing those specialized tutorials is that there isn't any difference between a socket connecting your application to a server on localhost and a socket connecting your browser to www.coderanch.com. You don't have to write your code any differently either.
Do you have a specific problem behind this question, or are you just asking out of curiosity?
John McClellan
Ranch Hand
Joined: Aug 15, 2011
Posts: 35
posted
0
Well, I haven't actually tried doing this across multiple computers, but it's just hard for me to see how it would know which thing to connect to if I didn't pass it some sort of information that describes where the server is and what it is. Below I've included the actual code I was using for the client side. What would I have to change if I were to try to access the server across the Internet, instead of on the same computer?
John McClellan
Ranch Hand
Joined: Aug 15, 2011
Posts: 35
posted
0
I mean, it probably has something to do with changing the name "localhost" to something different, but I'm not sure of the specifics. Also would it still be using that port number the same way?
Tim Moores
Rancher
Joined: Sep 21, 2011
Posts: 2407
posted
0
Spot on: you'd change "localhost" to the name or IP address of the machine you're trying to connect to, and you're in business. Ports are the same everywhere.
Now what I'm having trouble with is the following: I'm using a wireless router, and when I call InetAddress.getByName(<some sort of internal, local ip>) on my own computer, that works just fine. But then when I try to call InetAddress.getByName(<the router's ip>), either on my own computer or on another one on the same router, that doesn't work. What's the problem?
I've tried turning it off and running the program, but I still got the same error.
John de Michele
Rancher
Joined: Mar 09, 2009
Posts: 600
posted
0
John:
Did you try running it against localhost? What was the output?
John.
John McClellan
Ranch Hand
Joined: Aug 15, 2011
Posts: 35
posted
0
The nature of this output has to do with what the program was made to do.
Keerthivasan Ramanathan
Greenhorn
Joined: Mar 23, 2011
Posts: 11
posted
0
you are getting this exception because the socket server is not running at the specified port of the specified host. When you get 'Connection refused', it is either your socket server doesn't run or firewall/security rights issue.
Keerthivasan Ramanathan
Greenhorn
Joined: Mar 23, 2011
Posts: 11
posted
0
I forgot to add one more. this exception will occur, when the maximum incoming requests queue of the socket server is full.
subject: A good, simple tutorial for making sockets work over the Internet.