Sign in to follow this  
vidjogamer

[java] help appreciated

Recommended Posts

so im stuck in a group in class and we have to make a networked game... the game itself is functioning properly but for some reason we cant get them to network... sorry, we put println's after everything to see if it worked. i apologize for the sloppy code... heres the part that doesnt work: while(board2 == null) { try { //System.out.println("Searching for connection"); socket = new Socket("localhost",7000); System.out.println("Connected to Server."); System.out.println("Waiting for player 2"); ObjectOutputStream toServer = new ObjectOutputStream(socket.getOutputStream()); ObjectInputStream fromServer = new ObjectInputStream(socket.getInputStream()); System.out.println("streams work"); board1 = new ColumnsBoard(this); System.out.println("board1 works"); toServer.writeObject(board1); System.out.println("write board works"); board2 = (ColumnsBoard)fromServer.readObject(); System.out.println("board 2 works"); } catch(Exception ex) { } } It never gets to the System.out.println("write board works"); any help is appreciated.

Share this post


Link to post
Share on other sites
Quote:
Original post by vidjogamer
catch(Exception ex)
{

}


Never drop an exception. Always print out what is going on. Right now you have no way of know if an exception occured.

Also you should always catch the specific exception that you are looking for. In this case it is an IOException. So you should use.

try {
//your code
}
catch(IOException e) {
e.printStackTrace();
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this