如何使用Java套接字连接到在线服务器 [英] how to use java sockets to connect to an online server

查看:53
本文介绍了如何使用Java套接字连接到在线服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了一些时间学习Java,并以此为自己打造了一个相当复杂的游戏.我的游戏是一个桌面跑步比赛应用程序,该程序在玩后会产生一个得分值,并将其输入到排行榜中.除了一些安全机制外,该游戏非常完整.

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.

我想使用套接字发送一个数字,比如说从我的桌面游戏到一个随机Web服务器上托管的Java服务器上的2371.然后,我希望Java服务器找到该玩家分数的位置(2371),然后将分数打印在网站排行榜上.

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.

真的真的很简单,就是调整代码URL,然后将socketServer代码上传到虚拟主机空间?

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

如果是,我要上传什么.... java文件或其他文件?

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

在研究中,我还读过很多书,很多Web主机不允许上传带有开放端口的Java文件.这是正确的吗?

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.

推荐答案

您需要的是Internet上的一台计算机,该计算机可以运行Java客户端应用程序可以连接到的进程(您的Java服务器应用程序).因此,您将上载文件(也许是jar或某些类文件),然后通过运行该过程所需的任何接口告诉服务器.然后,该服务器应用程序可以保存每个人的分数并将其保存到磁盘以及您需要的其他任何内容.

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.

在研究中,我还读过很多书,很多Web主机不允许上传带有开放端口的Java文件.这是正确的吗?

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?

这是正确的.您需要租用一台服务器(如果您自己的服务器无法与自己的Internet连接),简单的网络托管公司将不允许您托管自己的运行进程.

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).

我不确定这是否是个玩笑,但是像ProGuard这样的源代码混淆器确实可以做到这一点.

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.

这篇关于如何使用Java套接字连接到在线服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆