Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  my client stop receiving messages  (Read 1001 times)
0 Members and 1 Guest are viewing this topic.
Offline Alexander

Innocent Bystander




From Alexander, with love...


« Posted 2004-04-13 02: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):
Quote
                                   if (clientID.compareTo(id)==0){
                                         test = new GameTest();
                                         test.setPlayer(gamelounge.menumanager.getPlayer());
                                         test.setPlayerPosition(position);
                                         test.setGamemap(gamelounge.menumanager.getGamemap());
                                         
                                         gamelounge.dispose();
                                         test.initSystem();
                                         setScene(test.getScene());
                                         sendInGameOpponentMessage(test.getPlayer().getUserID(),test.getPlayer().getIntTeam(),test.getPlayerObject().getPosition(),test.getPlayer().getintAgility(),test.getPlayer().getintMarksmanship());
                                         test.run();
                                   }


The GameClient's message receiving thread:
Quote
           public void run()
           {
                 int messageLength = 0;
                 String message = "";
                 
                 // read messages until server close the connection
                 try {
                       
                       // process messages sent from server
                       do {
                             readBuffer.clear();
                             socketChannel.read( readBuffer );
                             readBuffer.flip();
                             CharBuffer charMessage = charSet.decode( readBuffer );
                             message = charMessage.toString().trim();
                             System.out.println("Server msg: " + message);
                             messageListener.messageReceived(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 {
                             ioException.printStackTrace();
                             
                             try {
                                   socketChannel.close();
                                   System.out.println( "socket channel closed" );
                             }
                             catch ( IOException exception ) {
                                   exception.printStackTrace();
                             }
                       }
                       
                 } // end catch
                 
           } // end method run
           


The hostserver's message sending code:
Quote
     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
                       socketChannel.write(writeBuffer);
                 }
                 // process problems sending object
                 catch (IOException ioException) {
                       ioException.printStackTrace();
                       socketChannel.close();
                       sockets.remove(socket);
                       clientList.remove(i);
                 }
           } // 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

"...what that have happened are absolute, it's how you think and feel that is relative..."
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (13 views)
2014-07-24 01:59:36

Riven (11 views)
2014-07-23 21:16:32

Riven (12 views)
2014-07-23 21:07:15

Riven (13 views)
2014-07-23 20:56:16

ctomni231 (43 views)
2014-07-18 06:55:21

Zero Volt (38 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (34 views)
2014-07-16 23:30:00

Cero (50 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org 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‑gaming.org
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!