Java - arrays over a network?

Associate
Joined
1 Oct 2004
Posts
793
Location
Windsor
I'm currently making a java chess game which as a requirement is to be played over a network.

Part of my design is to have a multidimensional array (8x8) which holds the information regarding the board data. Is it possible to send a complete array over a network in order to update the opponents array with the last move to have taken place.

I know strings can be sent over a network but can a whole array, if so how?
 
Wouldn't it make more sense just to tell the other use of the piece that has moved. Rather than the entire board configuration again.
 
Another way of doing it would be to hold a single copy of the board that each user can obtain a copy of, and can send moves to. The board could be represented by something simple like an XML document holding positions of pieces.

An example set up would be to hold the XML document on a server and use servlets to obtain copies of the document (board piece positions) and submit moves.

The advantage of each user seeing the same board (via the servlets etc) is that you avoid any synchronizing problems between multiple boards.

Hope that helps.

Jim
 
It doesn't seem very efficient, but it is possible to send objects over a network. As far as I remember the easiest way to do this is via RMI.
 
Ciba said:
I'm currently making a java chess game which as a requirement is to be played over a network.

Part of my design is to have a multidimensional array (8x8) which holds the information regarding the board data. Is it possible to send a complete array over a network in order to update the opponents array with the last move to have taken place.

I know strings can be sent over a network but can a whole array, if so how?

Wouldnt it be easier to implement a protocol where if necessary the whoe board can be sent, but mostly you just send sinlge moves to increment board status?
 
Gavstar said:
It doesn't seem very efficient, but it is possible to send objects over a network. As far as I remember the easiest way to do this is via RMI.

Or implement the Serializable interface.
 
Ciba said:
I'm currently making a java chess game which as a requirement is to be played over a network.

Part of my design is to have a multidimensional array (8x8) which holds the information regarding the board data. Is it possible to send a complete array over a network in order to update the opponents array with the last move to have taken place.

I know strings can be sent over a network but can a whole array, if so how?
Put the array into another class, maybe called something like "BoardLayout" and have it also implement the Serializable interface. You can then use a TCP socket with object streaming to send/receive that object across the network. Java's object streaming handles all the fragmentation and reassembly of the object so you don't need to get into the nitty gritty of TCP programming.

While sending the actual "moves" instead of the board layout each time is more efficient, to be honest the size of the array is going to be tiny anyway. There won't be much in it. Consider that each move will take a few seconds and it isn't even going to register on a bandwidth monitor.
 
Back
Top Bottom