A "What's Next" Networking Question
#1 Members - Reputation: 126
Posted 18 October 2012 - 12:35 AM
I contacted one of my friends, an electrical engineer, about how to program a multi-player game and he told me to look into sockets. So, I found a few tutorials on socket programming (using java.net.* and java.io.*) and within forty five minutes I had a server and a client program. The server parsed input streams regarding character movement and reported them to the other clients. I could open up a few local clients and they would all show the main character from each of the clients running around. After a solid few seconds of fist pumping I sat back down and looked over the code to try and figure out what was really going on.
I realized, hey there's no place in this code where the client connects to the server on a non-local connection!
connection = new Socket(InetAddress.getByName("localhost").getHostName() , port #);...is not going to find a server on another computer over Al Gore's greatest invention!
It occurred to me that maybe I could just hard code the TCP/IP address into the client, but I know for a fact that my internet connection has a dynamic IP address, so no way that would work. This is not my area or expertise and I'm sure I'm just a google search away from a solid tutorial or explanation, however, I haven't been successful in finding a good answer. It reminds me of a student asks me what the pI of a certain protein is, after they have failed to figure it out for hours. My gut reaction is, "are you kidding me? It takes 5 minutes to figure that out." But then I remember that they don't have the tools and experience to even begin solving the problem.
So, my question is, what's next? What is the recommended way to get a client to connect to a non-local server using java.net.*?
By the way, I read through the article "Get Answers to Your Questions!"->Forum FAQ, Q0 is the best! I laughed so hard!
#2 Members - Reputation: 521
Posted 18 October 2012 - 03:47 AM
#3 Members - Reputation: 444
Posted 18 October 2012 - 04:42 AM
There are several free providers for this kind of thing. One of the first ones (I think) was dyndns which I used for quite a while. There you registered a name (e.g. DontReferenceMyPointer.dyndns.com) and that one always pointed to your current IP address. However, looking at their website they don't offer a free service anymore. But I found a list of free provider: http://dnslookup.me/dynamic-dns/
#4 Members - Reputation: 452
Posted 18 October 2012 - 10:31 AM
If you are using a router, you can connect to it (moslty 192.168.0.1) and check if it provides a dynamic ip option. If it does, you can easily config it (mostly it will show a list of services it can interface with) by entering your username/password in the given provider.
If it does not you will need to download a program and install it, your pc will then inform the server of your current ip and it will redirect your domain to your new ip.
Also, if you are using a router, you will need to create a mac binding (so your pc will always have the same ip inside your local network) and then create a virtual server that will map the requests for your router to your pc.
Those are the very basic steps you need to follow, you can find very detailed tutorials on your chosen dynamic ip provider's site.
http://16bitsflag.blogspot.com.br/
#5 Members - Reputation: 126
Posted 18 October 2012 - 11:56 AM
But here's what I got from the answers (-) and my response and/or follow up question (+):
-(Ripiz) I need something to anchor my server or for my server to publish an IP calling card so that the clients can find it.
+It seems like writing to a *.txt file in a dropbox every loop through the server and having the client constantly check the dropbox to see if the server has changed may be suboptimal and error prone. (I know how to write to the dropbox, but I would have no idea how to make a client read from a dropbox on another computer.)
+Is it possible to have a server listen and create sockets through something constant like a web address? Or, is that totally unreasonable?
-(brx) I can register with a website that will report to my client the server operating machine's IP address.
+This sounds pretty promising, however, are there any security issues with this (the site says "secure" but I'd rather know an outsider's opinion) and can this be implemented into java (I don't understand how the new IP is reported to the client without writing code to do so in the client)?
-(KnolanCross) I need to expand my knowledge of IP and routers (which I am learning is even more limited than I thought.)
+I'll read through some dynamic IP tutorials and see if this helps solve my puzzle.
Thank you for all the replies! Please let me know if you find a serious error in my understanding or if you think I would benefit from reading some other materials!
#6 Moderators - Reputation: 3297
Posted 18 October 2012 - 11:58 AM
If you're new to network programming, I suggest you skim the FAQ, because it contains both help for newbies, as well as help for more advanced programmers, and when you get to a particular problem, you may then remember some question from the FAQ, and can go back and look it up there!
#7 Members - Reputation: 126
Posted 18 October 2012 - 12:00 PM
This is also answered in the FAQ, which says you need a name to look up through DNS, and suggests using dyndns.org or similar to establish and update a name for your dynamic IP.
If you're new to network programming, I suggest you skim the FAQ, because it contains both help for newbies, as well as help for more advanced programmers, and when you get to a particular problem, you may then remember some question from the FAQ, and can go back and look it up there!
I do remember reading that, however, I don't think i understood what I was reading, so I didn't make the connection. I'll go back through the FAQ again now that I have better understanding of what I am looking for. Thank you!
#8 Members - Reputation: 1566
Posted 18 October 2012 - 12:50 PM
Although, I think you're looking for the dynamic DNS solutions, I just wanted to make sure.
---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)
#9 Members - Reputation: 119
Posted 22 October 2012 - 09:23 PM
No need to change your codes except inputting the server IP in client login UI.
Edited by Eric Wu, 22 October 2012 - 09:29 PM.






