简体   繁体   中英

how to use java sockets to connect to an online server

I have spent some time learning Java and in doing so have built myself a rather complex game. My game is a desktop ran swing app which after play results in a score value that gets entered onto a leaderboard. The game is pretty much complete, except a few security mechanisms.

At first I never intended to have my game connected to the net as the phrase 'networking' has always put me off. Now that my game has slowly developed, it has actually turned out far better than I had imagined which has kinda twisted my arm into wanting to learn how to network.

After lots of research into the subject, I decided to have a look into sockets and build myself a simple client/socket server. Both programs connected on my local machine which has bought me here.

I already know that allowing the client to send the score to the server is always vulnerable to cheats, but originally this game was never intended for online score posting. Instead I have decided to make my game code so damn unreadable and messy that it may just be easier to cheat/crack someone elses program. (wishful thinking).

This game is only a learning curve, so abuse of the score system in my eyes will only serve to teach.

My questions may seem silly, but its only trying to get a fuller understanding.

I'm wanting to use a socket to send a number, lets say 2371 from my desktop game to a java server that is hosted on a random webserver. I then want the java server to find the position of this players score (2371) and then print the score on a website leaderboard.

Is it really as simple as adjusting the code URL and then uploading the socketServer code to webhosting space?

If it is, what am I uploading..... a .java file, or any other?

I have also read many times in my research that alot of webhosts dont allow the uploading of java files with open ports. Is this correct?

Many thanks guys, this is a subject that I have always steered clear of, so all and any advice would be appreciated.

What you need is a computer on the internet that can run a process (your Java server application), that your Java client applications can connect to. So you would upload the file(s) (maybe it's a jar, or some class files), and tell the server through whatever interface you have to run the process. This server application can then hold everyone's scores and save them to disk and whatever else you need.

I have also read many times in my research that alot of webhosts dont allow the uploading of java files with open ports. Is this correct?

This is correct. You'll need to rent a server (if you don't have one yourself that you can put on your own internet connection), a simple web hosting companies will not allow you to host your own running process.

Instead I have decided to make my game code so damn unreadable and messy that it may just be easier to cheat/crack someone elses program. (wishful thinking).

I'm not sure if this a joke but there's source code obfuscators out there like ProGuard which do exactly this.

If you really want to protect against people simply writing scores out to the server with their own modified client then you'll have to have some of the logic of the game be handled by the server process itself. Of course someone could still go further and create a bot or whatever else they need to cheat and get their bogus score listed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM