Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (754)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (842)
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 1614 times)
0 Members and 1 Guest are viewing this topic.
Offline Alexander

Innocent Bystander

From Alexander, with love...

« Posted 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

"...what that have happened are absolute, it's how you think and feel that is relative..."
Pages: [1]
  ignore  |  Print  

DesertCoockie (36 views)
2018-05-13 18:23:11

nelsongames (80 views)
2018-04-24 18:15:36

nelsongames (73 views)
2018-04-24 18:14:32

ivj94 (755 views)
2018-03-24 14:47:39

ivj94 (85 views)
2018-03-24 14:46:31

ivj94 (626 views)
2018-03-24 14:43:53

Solater (101 views)
2018-03-17 05:04:08

nelsongames (182 views)
2018-03-05 17:56:34

Gornova (408 views)
2018-03-02 22:15:33

buddyBro (1068 views)
2018-02-28 16:59:18
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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!