Results 1 to 7 of 7
- 06-19-2011, 05:49 AM #1
Member
- Join Date
- Apr 2011
- Posts
- 14
- Rep Power
- 0
2 Java Programs Interacting Same Computer
Okay so I'll ATTEMPT to explain this thoroughly because I desperately need help!
I have an online game running on Java on a server with many players on it, and I want to have HighScores for the game using MySQL. When I run a query to connect to the MySQL, it temporarily 'lags' (delays) the server for roughly 5 seconds while it connects. It connects about once every minute or two. This is a BIG deal for my game. It can't do that.
So, what I thought of doing, is having a slave Java program to do all the MySQL work, so it will only delay the slave and not the master server. They will both be running on the same computer, though.
Does anyone have any idea how I'd go about doing this?
I don't even need to return the variable to the master server, just have the master server send a command to the slave to do the MySQL. This is because I want to have the player's stats on the online game uploaded to the MySQL data table so it can be displayed on the website.
Any help is appreciated, thanks in advance.
Edit: Am I thinking too hard? For MySQL can I just use http post..? I just read about and it seems I can just be like, example pseudo: connect(website.com/sql.php?hs1=1&hs2=1) or something along those lines then have it add it to the database and that will not cause any lag?Last edited by ForeverP; 06-19-2011 at 05:57 AM.
- 06-19-2011, 06:18 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
That sounds odd. As with any operation that is going to take a while the program should use a new thread for anything that is going to take a while and which does not materially affect its operation.When I run a query to connect to the MySQL, it temporarily 'lags' (delays) the server for roughly 5 seconds while it connects.
Also couldn't the server just reuse the same connection over and over again as needed?
- 06-19-2011, 11:17 AM #3
because of safety considerations i think having a connection from a game directly to a mysql server is not a good idea. so i would try to transmit the score in a encrypted file to the server. on the server a thread is running checking for new files and inserting it in the db table.
- 06-19-2011, 12:19 PM #4
Personally I'd use a separate thread within the main program to do all the SQL-commands, if they lag you out that much. I'm unsure if named pipes work with Java, but one way you could communicate between two programs would be to use sockets; make a serversocket in one of the programs and connect to it from the other program. That's probably trying to shoot mosquitos with a cannon though; a thread would do the job just as splendidly.
- 06-19-2011, 04:15 PM #5
Member
- Join Date
- Apr 2011
- Posts
- 14
- Rep Power
- 0
The game client connects to the game server which is on a different host..
And yes it lags the entire game, to where all the players are just standing there not moving or doing anything until it connects and gets the data.
Also, no, it cannot just connect once. I thought that was the case, but I think the MySQL connection disconnects every minute or two, because it starts to error if I don't reconnect after a while.
How would I go about making a different thread for an operation? I've never heard of doing that
- 06-19-2011, 11:20 PM #6
- 06-20-2011, 11:21 AM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Similar Threads
-
Websites for java programs?
By Phoenix Dogstar in forum Forum LobbyReplies: 1Last Post: 05-03-2011, 05:11 AM -
Java Computer Shop Help (Please)
By acash229 in forum New To JavaReplies: 2Last Post: 01-27-2011, 08:39 PM -
Two simple programs interacting
By 1sprit in forum New To JavaReplies: 3Last Post: 12-29-2010, 01:16 AM -
Oracle trigger interacting with Java app
By KentDMc in forum Advanced JavaReplies: 1Last Post: 04-27-2009, 01:49 AM -
Interacting with the Java Garbage Collector
By Java Tip in forum Java TipReplies: 0Last Post: 03-28-2008, 08:04 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks