I have a multiplayer game server application written in Java which connects to player clients when they join the multiplayer game via a socket. The server application (a JAR running in the JVM) is listening to a port (e.g. 9999) for incoming connections from clients.
I want to add a website to minitor the entire project which contains information taken from the running game server(s). One way would be to open a socket from the site (a PHP socket for example) to the gameserver (Java) and implement a custom protocol for taking data from the server. But that method is time consuming as I need to add support for each type of datum I want to pass to the monitoring website.
I was thinking if there is a way to write the site in Java and simply communicate with my gameserver via a direct link. RMI would be a solution I assume since both my JAR and my WAR can communicate through it, but isn't there some better way to build both the web application and the gameserver application inside the same JAR file? So that when my gameserver runs, the web application runs too?
this looks to me as the fastest way to have an admin console. Just transform your server into a war application which contains both your game server with an open socket for clients and your administration pages. To start your server simply drop it into a tomcat.
A cleaner approach which does not require some self-created protocol would be to have your server use mbeans for all key objects which you would like to admin. But this needs some coding.
Cheers, Sven
You should have an embedded web server in your game server. Try Jetty (http://jetty.codehaus.org/jetty/). It's quite easy to embed in any java application.
Related
I wrote an application with front end in js and back end in java. It is supposed to be a socket application. In js I use standard socket javascript client. In java I use classes from packages javax.websocket, so the essential class has the annotation #ServerEndpoint("/server"). I deployed my app on openshift and only client is working. When I try to connect to the server(url looks like ws://address.of.my.page.on.cloud/server) I get the console alert in firefox that the connection with socket server could not be done. I guess maybe openshift isn't suppose to handle sockets but I could not find any servers that provide such possibility for free. Are there any out there? Or maybe I am doing something wrong?
I have one Desktop application and i want to call that applicating using command line from anothr web application. is it possible ?
A desktop application being the target of a call is usually a bad idea because in order to succeed the desktop application must be visible from where you want to reach it. This might or might not be a problem.
If the 2 computers are on a LAN, this should not be a problem. If the desktop application is behind a router or firewall, this requires opening and forwarding a port to the computer the desktop application is running on. This might not be feasible or doable (e.g. you have no permission to change firewall and routing settings) in many cases.
Best approach would be for the desktop application to contact the web server.
But if you really want to do otherwise, the desktop application should create a ServerSocket and listen for incoming connections, or start an embedded web server. There are other possibilities of course (e.g. RMI).
i am developing an android application in which the server side execution is done using a simple java udp program.i want to know how i can host this application because i need a static ip server to run the java program.can i run my java program in a server.is it possible if yes how?
You'll have to write a listener in some language (PHP, Java, Etc.). As for a static ip address, you can also look at a dynamic ip redirection service like no-ip;
http://www.no-ip.com/services/managed_dns/free_dynamic_dns.html
You can use a personal machine thats always online, or you can try to use a shared hosting plan that allows you to have a listening port open. A web service will likely be easier to work with than having some custom UDP/TCP connection.
I want to write an application for Android, a card game that can be played both locally and online. That means we have clients (Android phones), and servers. Ideally, an Android phone should be able to be used as a server and host a game (and play it at the same time). I don't want to duplicate code between the server and the client.
Here is what I had in mind: having the application contain the server part, that would be runnable indepently by the application itself, or without the application (on a computer).
In a local game, a thread would be run for the server, and another one for the client (which communicates with the local server through localhost). In an online game, a distant server is running, and the local client communicates with it through the network.
My questions are:
Will my application be able to communicate with a thread that comes from itself, through localhost?
Can I have the entire application as the server? On the phone, it would run the server thread, then the client thread (do I need one?). On the distant server (desktop computer), I would run only the server thread, without all the Android stuff.
Do you have an other idea?
I hope I have been clear enough for you to understand the problem.
Thanking you in advance.
Yes, your app could communicate with itself through TCP sockets, that shouldn't be a problem. I'd advise you to take a look at putting most of the server functionality into a jar file, then you would have an Android APK and potentially a separate Java frontend for your desktop. You will likely need to have a little hosting code that's specific to each platform. It might make sense to put your server in an Android Service for example if you want to be able to host in the background.
OK, I'm new to server-client applications, and i need some basic information, so forgive me if my question is not clear...
I want to make a chat application that would function like this:
Client A sends information to server, server sends the same information to client B, and vice versa... Think of it as of a simple chat program.
All communication is done through sockets, so i would have a server socket application, and a client socket application... I want my client application to be on my PCs and server application to be on a remote server ( it would be hosted on some free hosting websites).
My question is how do I start that server application on that remote server?
Thanks in advance!
If you are just trying to make a chat client, I don't think you would need an intermediate server. Just connect two machines using server and client sockets
SERVER:
ServerSocketChannel serverSocket;
serverSocket = ServerSocketChannel.open();
serverSocket.socket().bind()
serverSocket.socket().accept()
CLIENT:
SocketChannel clientSocket = SocketChannel.open();
clientSocket.connect();
Of course you would have to use the bind and connect functions properly. Read up on their API's
The remote server can be started manually. (If you do not have access to remote server or if you are hosting your server on some third party infrastructure, then they might have a way to do it.)
To be able to start it remotely via some program, you again need a server on the remote machine that listens to this kind of requests.
Usually, you want an application that is running all the time at your hosting provider (like a web server or perhaps inetd) to start (or embed) your application. The details will be determined by what your hosting provider provides.
If you're using plain sockets, you should look for some remote server with SSH login. You're able to start your application on the shell then, sth like:
java -jar yourapp.jar
Free hosting websites are rather targeting customers that want to host their website. In my opinion that is not the best choice for hosting a socket application.
For developing purposes, I'd stick with the local machine for the beginning. Running/testing server/client connections on the same machine is much easier as you don't have to work on two different machines, copy code, etc.
This tutorial is relatively short, but fully covers basics of Java networking. And it is right about simple chat.