Streaming a python game through a jsp - java

So im creating this game using pygame, and i have to put it up on a website, but it has to run server-side since the game is gonna be using a database locally, and the client will be able to enter a web page and click on a button and the game is gonna run, i cant make the game run completely client side because then the game wont be able to connect to my local database
Any ideas?

The way I see it you have two options:
If network connection is intermittent (not so frequent), you can use javascript (AJAX specifically) to make HTTP calls to the server whenever you need to access your database.
If you are expecting frequent (continuous) requests (i.e. multiplayer games), you would need to keep a connection alive using either
Persistent HTTP request
TCP Socket
Websocket : You probably want to use this if you want cross-browser support.
Let me know if you have any other questions regarding the options above.

Related

Play Framework 2.5 with Server Side Events

I'm trying to make a simple tic-tac-toe online multiplayer game in Play Framework in Java (but I can read Scala too) and I need to notify one client when the other client has made a move - has inserted a new database entry. The frontend uses HTML and JS.
Do I use WebSockets or Server Sent Events for this and how?
Thanks a lot guys, the Play framework documentation for both is still not updated and it's a well known issue https://github.com/playframework/playframework/issues/5057 as well.
EDIT: The main question here is really how to do it?
Personally for a game I would establish a Web Socket connection over a SSE.
Fast data transfers
A two way stream of message, where SSE would require the client to send ajax requests and listen to SSE where WS all sits in one place.
Allows you to establish when one of the 2 clients looses connections, thus pausing or notifying the other player.
Resource you can use to Implement this:
https://www.playframework.com/documentation/2.5.x/ScalaWebSockets
Edit: Latest version https://www.playframework.com/documentation/2.6.x/ScalaWebSockets

Server to Server Communication with Java

I am currently developing a game, and would like to separate the login server from the game server. While I am experienced with client-server networking, I have never done any work communicating between servers. What are some standard or accepted methods of accomplishing this? My current topology(?) is to have the game client connect to the game server, handle all logging in and authentication, and then start processing game data/packets. What I would like to do, is split the login server and game server into separate entities, such that the client will initially connect to the login server, after proper authentication has been reached, send the client over to the game server and start processing game data.
What would be an acceptable way of handling this?
EDIT: It seems the intention of the question may be unclear. My question is, is there some sort of functionality that would allow server-server communication, OTHER than creating the login server as a client to the game server?
No, There is not. One of the two parties always needs to be listening for connections while the other end connects to it.

Developing a Multiplayer Browser-Based Card Game With HTML/JS/AJAX/Java

I currently have a multiplayer card game developed and working in Java and it is working in the console. The game is similar in format to Bridge and Spades, minus the bidding process. It is a four-player game, and players take turns playing a card.
I am currently working to convert this to a browser-based webapp, and am adding Spring MVC, and using HTML, JavaScript, and AJAX for the UI and communication with the backend. I have a good idea of the approach I want to take on getting this to work single-player against the AI, allowing the user to play their card and using an AJAX call to get the next three plays from the server.
However, I'm wondering what kind of approach I would need to take for this to be multiplayer. I have seen some references to "Socket-programming," which I am unfamiliar with, but those seem to revolve around Java applets, instead of a browser-based app.
Basically, I am looking for a way to ensure that when a user starts a game and someone else joins, how do I ensure that they are connected to the same game, and are able to see each others' plays? I am asking this now before I have the UI fully developed for single-player, because I want to avoid a complete redesign to support multiplayer functionality.
Since you are creating a multiplayer game, you will need to have at least one server for your client(s) to connect to. Since you want to make this browser based, you will most likely need your own server (rather than having one of the clients be a server). When a user joins a game, it is logged on the server where that user is. When a player performs an action, the server processes the action, then sends a notification to each of the other clients connected to that room. At that point the clients UI updates.
In the past, you could not do this with pure HTML / JavaScript as you cannot open a socket. Which means, the server could not notify the clients. However in HTML5 you should be able to use WebSockets to achieve what you are doing with a server in the middle. The WebSocket API
However, if you don't want to use HTML5 WebSockets, there is another technique that imitates Sockets in JavaScript. That is, the server can talk to the clients. This technique is called long polling. The client sends a request to the server asking for an update, if there is no update available, the server holds the request until an update is available and sends it back to the client at which point they make another update request. Simple Long Polling Example
Another option, if you are very familiar with Java you may wish to check out Google Web Toolkit. GWT is a subset of Java that is compiled into HTML and JavaScript for the front end and if needed creates a Server Side java executable that you can use with TomCat or another web service. In this option, you have a few libraries that allow you to write socket-style code that will be compiled into Long Polling JavaScript.
Best of luck!

Connect Two Android Phones with Java Server

Which is the best way to connect 2 android phones in the internet with a Java Server?
I'm making an game form android. At this moment i have the single player working. But now i have two use an Java server to play online games.
Which is the best way to communicate with 2 phones ?
Most difficult action is send information of client1 to the Server and Server redirect this information to client 2.
Anyone can help me?
Regards
You can use either SOAP or REST, using Jax-RS (rest) or Java-WS (SOAP).
http://www.oracle.com/technetwork/java/index-jsp-137004.html
http://docs.oracle.com/javaee/6/tutorial/doc/giepu.html
Here is one way, assuming your game has some turn based interface, and you want to do is have a create game/join game or a create game with user style interface.
When the game starts, connect to the server using one of
the above techniques (soap/rest) to let the server know you are
there.
Then have one client say create a new game. This will tell the
server to create the game.
The other client will tell the server to list games. Then on
the client, choose a game to join. Then tell the server of the game
choice, so that it knows to add you.
The phone that started the game, should poll the server to see if
another user joined the game. Eventually some will join. (there are
other ways to handle this, but polling is very easy to do)
Have all players in the game poll to find out if the game started, then
go, once they have all joined.
There sure isn't a best way to do that. There are some techniques.
But what I would do is to create a long, unclosed http request from both of the clients to the server and then when something happens the clients get responses from the server. This is called Comet, but I never implemented that by myself. There sure is an Android implementation (or just a Java implementation).

Less response Time from webserver

I had developed an app in android that take some data from a database stored on a web server and draw a GUI according to data captured.The problem is that when i run app on localhost using (WAMP) it creates GUI in 2 seconds but when i connect it to the webserver it takes almost 7 to 10 minutes.I am astonished what could be the possible reason behind this.
I had not used any ASync class in my code.I had used httpclient.execute stuff to connect to web server and JSON pasring.I hope you understand.Please tell me what could be the reason behind less response time.
first thing is whats the speed of your internet ? if your connection is slow that could be the reason. and other thing is you might be doing all gui processing on client via request only. my suggtion is have screens ready and fill data via things like json/REST stuff. for others i can only tell you once you show some code.

Categories