Hi !
Featured games (88)
games approved by the League of Dukes
Games in Showcase (679)
Games in Android Showcase (194)
games submitted by our members
Games in WIP (734)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Networking & Multiplayer / my client stop receiving messages on: 2004-04-13 00:45:40
hi, i am a newbie to game network programming. recently i am doing a multiplayer game project. The networking part works fine initially. I have a host server to broadcast the game messages out and a game client to receive and inteprete the messages. It works fine when the game is in progress. But when i integrate the 'out-game' menus (the menu screen with options like "Start Game", "Join Game", etc), there seems to be a problem in the message receiving at my client side when the game is started from the 'out-game' menu. here's a brief description of how the thingie goes:
1) The player logs into the game.
2) He can either host a game (something like CS) or to join an existing game that hasnt started.
3) after hosting or joining a game, the player will be directed to a 'game lounge' where everyone is gathered before the game actually starts.
4) once the host is happy with the number of people in each team, he can start the game by pressing the start button.
5) the client at the host's side will send a game start message to the hostserver (the host's side)  which will in turn broadcast to every client connected to the host. when the clients receive this msg, the game lounge screen will be closed and the game screen will be opened.

Everything up to this point is alright. But when my game started, the client doesnt seems to receive any message, though it is sending messages to the server. here are the respective code snipplets:

GameClient (when the game start message is received):
                                   if (clientID.compareTo(id)==0){
                                         test = new GameTest();

The GameClient's message receiving thread:
           public void run()
                 int messageLength = 0;
                 String message = "";
                 // read messages until server close the connection
                 try {
                       // process messages sent from server
                       do {
                    readBuffer );
                             CharBuffer charMessage = charSet.decode( readBuffer );
                             message = charMessage.toString().trim();
                             System.out.println("Server msg: " + message);
                       } while ( true );  // keep receiving messages
                 } // end try
                 // catch problems reading from server
                 catch ( IOException ioException ) {
                       if ( ioException instanceof ClosedByInterruptException )
                             System.out.println( "socket channel closed" );
                       else {
                             try {
                                   System.out.println( "socket channel closed" );
                             catch ( IOException exception ) {
                 } // end catch
           } // end method run

The hostserver's message sending code:
     public void writeMessage(String message) throws IOException {
           Socket socket;
           SocketChannel socketChannel;
           System.out.println("Sending: " + message);
           // echo message back to all connected clients
           for (int i = 0; i < sockets.size(); i++) {
                 socket = (Socket) sockets.elementAt(i);
                 socketChannel = socket.getChannel();
                 // send message to client
                 try {
                       // convert message to bytes in charSet
                       writeBuffer = charSet.encode(message);
                       // write message to socketChannel
                 // process problems sending object
                 catch (IOException ioException) {
           } // end for
     } // end method writeMessage

hope some kind souls out there can give me a helping hand coz my deadline is on friday. thanks  Grin

Note: the out-game menu is done in javax.swing while the game itself is done using opengl (lwjgl apis). I am using NIO for the networking
Pages: [1]
DarkCart (20 views)
2016-05-29 02:30:33

Hydroque (36 views)
2016-05-26 14:45:46

Mac70 (47 views)
2016-05-24 21:16:33

theagentd (54 views)
2016-05-14 18:38:35

theagentd (87 views)
2016-05-10 22:37:41

theagentd (92 views)
2016-05-10 22:33:46

IanParcs (119 views)
2016-04-18 14:18:53

KaiHH (115 views)
2016-04-18 08:35:41

KaiHH (135 views)
2016-04-15 12:43:58

theagentd (142 views)
2016-04-14 02:16:17
FPS Camera Tutorial
by Hydroque
2016-05-22 05:40:58

Website offering 3D Models specifically for games for free
by vusman
2016-05-18 17:23:09

Website offering 3D Models specifically for games for free
by vusman
2016-05-09 08:50:56

Website offering 3D Models specifically for games for free
by vusman
2016-05-06 11:10:21

Website offering 3D Models specifically for games for free
by vusman
2016-04-29 12:56:17

List of Learning Resources
by SilverTiger
2016-02-05 09:39:47

List of Learning Resources
by SilverTiger
2016-02-05 09:38:38

List of Learning Resources
by SilverTiger
2016-02-05 09:35:50 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!