Page 1 of 2 12 LastLast
Results 1 to 20 of 22
  1. #1
    Ambuscade is offline Member
    Join Date
    Oct 2008
    Posts
    9
    Rep Power
    0

    Default Networking Problem

    Hello,

    My program that I have written works perfectly fine when the client and the server are inside of the same LAN. The problem that I have is that when the server and the client are outside of the same LAN, either just the program freezes or the whole computer freezes.

    The server and the client communicate by passing an Object that holds whatever information they need. I have traced the problem to the Object being written. When the program freezes, it freezes right before the Object is written to the server/client. I have tested it on different routers so I think it has to do with either the Object being serialized or writeObject() method just doesn't want to write my Object.

    I'm just wondering if there are any special things that I need to consider when networking outside of a LAN because my program works fine inside of a LAN but not outside of one.

  2. #2
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    Are you using RMI or Corba?

    They typically run into problems with firewalls.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    When you want to get out from the local network, fist thing to consider about the firewalls, I think. Actually that's what I check if I didn't come across with an issue on my application.

  4. #4
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    Right, both Corba and RMI are obsolete. They require network practices (appropriate for when they were designed) that simply can not exist today.

    Additionally, both are overly complex for what they claim to solve.

    Just write code using REST with HTTP, send messages. Design them to be easy to extend and trivail to parse.

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Actually I don't know much about RMI, I've never use it. But Corba can cause such problems. As you said HTTP is the best I can see.

  6. #6
    Ambuscade is offline Member
    Join Date
    Oct 2008
    Posts
    9
    Rep Power
    0

    Default

    I think you guys have mistaken what I am talking about or I have just not specified enough what I am talking about. I am not using either RMI or Corba. I am just using basic java sockets that are using the writeObject() method. I will still try and see if firewalls are the issue (they could very well be) and I will let you know what the results are.

  7. #7
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    Quote Originally Posted by Ambuscade View Post
    I think you guys have mistaken what I am talking about or I have just not specified enough what I am talking about. I am not using either RMI or Corba. I am just using basic java sockets that are using the writeObject() method.
    We've been speculating because you have not said one way or the other.

    What port are you using? What protocol?

    How do you make "writeObject()" work over a socket?

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by fishtoprecords View Post
    We've been speculating because you have not said one way or the other.

    What port are you using? What protocol?

    How do you make "writeObject()" work over a socket?
    Yes it is.

    Ambuscade read the first replay of fishtoprecords on this thread. His first question. Because we don't have clear idea about what's your achievement there in you application.

  9. #9
    Ambuscade is offline Member
    Join Date
    Oct 2008
    Posts
    9
    Rep Power
    0

    Default

    Quote Originally Posted by fishtoprecords
    What port are you using? What protocol?
    I am using port number 4568 and I am using TCP. The client and the server can connect fine, so I know it is not a port issue.


    Quote Originally Posted by fishtoprecords
    How do you make "writeObject()" work over a socket?
    I make writeObject() work over a socket by having one class that holds all of the data I need to pass. I have the sender set a int value which will be the protocol. When the receiver gets it, based on the value of the int, they use whatever data they need.

    The client and server can connect no problem, its just after the game has been started, it freezes at some random writeObject() only if they are NOT connected in the same LAN, if they are connected in the same LAN then I have no problems what so ever.

    This is a method to start the game inside the server. It sometimes freezes here and sometimes it gets past it. This just makes a call to all the clients to start there game along with the server.
    Java Code:
    System.out.println("1");
    _loadingScreen.startGame(board, country, player, player[0], computerPlayers);
    System.out.println("2");
    for(int x=0; x<_clients.size(); x++){
    	_clients.get(x).startGame(board, country, player, player[x+1], computerPlayers);
    }
    System.out.println("6");
    The startGame() method from above is inside the server thread class which it creates for each client that connects. It sets the _serverClientProtocol so that the client knows what to use when it receives the _serverClientProtocol.
    Java Code:
    public void startGame(Board board, Country[] country, Player[] player, Player currentPlayer, LinkedList<ComputerPlayer> computerPlayers){
    System.out.println("3");
    _serverClientProtocol.setStartGameVariables(board, country, player, currentPlayer, computerPlayers);
    _serverClientProtocol.setProtocol(6);
    System.out.println("4");
    try{
    	_output.reset();
    	_output.writeObject(_serverClientProtocol);
    	_output.flush();
    }
    catch(IOException e){
    	System.out.println("Exited2");
                 e.printStackTrace();
    }
    _gameStarted = true;
    System.out.println("5");
    }
    When the game does freeze at the start, it only System.out.println() until 4 so it freezes right before the writeObject() method.

  10. #10
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    Quote Originally Posted by Ambuscade View Post
    I am using port number 4568 and I am using TCP.
    You will never get that port to work through most consumer and corporate firewalls.

    I suggest you rewrite the code to use HTTP over port 80.
    Convert the member variables to text, send them as parameters.

  11. #11
    Ambuscade is offline Member
    Join Date
    Oct 2008
    Posts
    9
    Rep Power
    0

    Default

    Quote Originally Posted by fishtoprecords View Post
    You will never get that port to work through most consumer and corporate firewalls.

    I suggest you rewrite the code to use HTTP over port 80.
    Convert the member variables to text, send them as parameters.
    I am confused. When the clients connect to the server, they are put into a waiting room where they can chat with each other and the host can pick the options for the game and those changes are sent to all the clients and are reflected on their screen. This all works fine and it is done the same way as the part above that sometimes freezes. I have made sure to disable all the firewalls too but it still doesn't work right.

    I don't know much about HTTP programming so I will have to learn how to do what you suggested, but I just don't understand why it will let some of the program work, yet it will randomly freeze at some other point in it.
    Last edited by Ambuscade; 10-25-2008 at 07:51 PM.

  12. #12
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default

    it will let some of the program work, yet it will randomly freeze at some other point in it.
    Have you localized the statement where it freezes? Does it always freeze there or only randomly? If randomly, then can you isolated something different about when it freezes at that point and when it does not freeze.

  13. #13
    Ambuscade is offline Member
    Join Date
    Oct 2008
    Posts
    9
    Rep Power
    0

    Default

    In the code I posted above, if the program freezes at that point, it freezes before or during (I don't know which) the writeObject() method. Sometimes it gets past that part with no problems what so ever and other times it freezes there. Whenever the program freezes though, it is always before/during a writeObject() method whether it be the client or the server that is doing it.

    There doesn't seem to be anything different between when it freezes at that point and when it doesn't freeze. But like I said, it always seems to freeze before/during the writeObject() method and it freezes the program and sometimes the whole computer.

  14. #14
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default

    That's interesting. If the I/O was being stopped by a firewall, I would think it would ALWAYS stop/freeze the code at the same point. But sometimes it works and sometimes not? Is that right?
    You've said you've stopped the firewalls and still have the problem.
    Are there any messages to either the client's or server's consoles?

    Only thing I can suggest to isolate/locate the problem would be to write some simple test programs that use that port then change the port. Also use the writeObject and then change the data to a simple String.
    Have you tried the client/servers using localhost?

    What is the purpose of the reset() method?
    What class are you using for the I/O?

  15. #15
    Ambuscade is offline Member
    Join Date
    Oct 2008
    Posts
    9
    Rep Power
    0

    Default

    Quote Originally Posted by Norm
    That's interesting. If the I/O was being stopped by a firewall, I would think it would ALWAYS stop/freeze the code at the same point. But sometimes it works and sometimes not? Is that right?
    Yes that is basically correct. The programs always ends up freezing but it just happens at a random writeObject() method. I was confused by what fishtoprecords was saying about it never working because it atleast somewhat works.

    Quote Originally Posted by Norm
    You've said you've stopped the firewalls and still have the problem. Are there any messages to either the client's or server's consoles?
    No, there are no messages displayed to either the server/client. The only thing displayed is System.out.println() that I have in most of the server thread/client classes that actually write to each other. And when it freezes, the System.out.println() only gets to 4 (which means it stopped and froze at a writeObject().

    Quote Originally Posted by Norm
    Only thing I can suggest to isolate/locate the problem would be to write some simple test programs that use that port then change the port. Also use the writeObject and then change the data to a simple String.
    Have you tried the client/servers using localhost?
    The programs runs perfectly fine when I am connecting to computers in the same LAN. Local host works fine also. When the clients connect to the server, they are put into a loading room where they can chat. I use the writeObject() method to send whatever text they type that way and I run into no problems. Its only after the game is started that the program has the potential to freeze. (which is the code I gave above)

    Quote Originally Posted by Norm
    What is the purpose of the reset() method?
    What class are you using for the I/O?
    The reset() method clears the stream of any Objects already written to it. So basically if I have already written my Object before, it will try to use the previous written one even if the Object has changed data. Am I correct in how this works? Taking the reset() method out makes my program not work right networking wise.

    I have a class called Server that accepts incoming connections to a socket and makes a ServerThread class that deals with those communications. I have a Client class that makes a connection to the specified IP address.

  16. #16
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default

    Sorry, I'm not familiar with reset(). I guess you must need it if the program fails without it.
    Intermittant problems are tough to solve. You do say that it does work sometimes?
    For testing: take out the writeObject method and see if another writeXXX method fails like writeObject. Still trying to isolate the problem.

  17. #17
    Ambuscade is offline Member
    Join Date
    Oct 2008
    Posts
    9
    Rep Power
    0

    Default

    It always works when the clients and server are inside the same LAN. When they are outside of the same LAN, I have yet to have it completly work right since it freezes at some random writeObject(). It could freeze on the one posted earlier or it could work on that one but freeze on a different one.

    Now taking out the writeObject() and still having my program function the same way was almost impossible without major changes to my code. So what I did was I put in a writeChars() before every writeObject() and the program never froze on a writeChars(), it still froze on a writeObject().

  18. #18
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    Quote Originally Posted by Ambuscade View Post
    So what I did was I put in a writeChars() before every writeObject() and the program never froze on a writeChars(), it still froze on a writeObject().
    This is what is called a "doctor doctor" problem. Don't do that.

    Why are you calling "writeObject()" when you know it does not work?

    The point of OO programming is that when it is well designed, you can swap out one implementation of an Object for another, and the code will work. This lets you build from things that are known to work, and slowly add the stuff that may or may not work.

    What do you expect us to do about the fact that you may have written a lot of code without testing it?

    Think about how to change it with the least amount of pain, but if it doesn't work, you have no choice.

  19. #19
    Ambuscade is offline Member
    Join Date
    Oct 2008
    Posts
    9
    Rep Power
    0

    Default

    Quote Originally Posted by fishtoprecords
    Why are you calling "writeObject()" when you know it does not work?
    It works sometimes, othertimes it doesn't work and it always works inside of a LAN. The fact that it doesn't work raises the question as to why? Hence the point of a forum where you can ask questions and learn why.

    Quote Originally Posted by fishtoprecords
    The point of OO programming is that when it is well designed, you can swap out one implementation of an Object for another, and the code will work. This lets you build from things that are known to work, and slowly add the stuff that may or may not work.
    Duh. What are you trying to imply with this other than just making assumptions?

    Quote Originally Posted by fishtoprecords
    What do you expect us to do about the fact that you may have written a lot of code without testing it?
    When have I ever said you need to do anything and why do you assume I have done no testing? I have been developing this video game for a couple months. Everything except for networking outside of a LAN works because I just learned that you can connect basically the same way as you can in a LAN a few days ago.

    Quote Originally Posted by fishtoprecords
    Think about how to change it with the least amount of pain, but if it doesn't work, you have no choice.
    If I can get it to work the way I have it, why wouldn't I try to find a way first? Seems retarded to me that you would automatically give if something doesn't work. And as I said above, if I can't get it to work then I am going to try something else but first I'd like to see if I can get it to work or at least understand why it doesn't work.

  20. #20
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default

    To isolate the problem, you may need to write a small test program using writeObject() and get that to fail, then make changes to it unitil you figure out what's wrong. Also with a small test program that demonstrates the problem, others can work on it.

    Or with your design, can you replace writeObjec() with another writeXXX method that does your own encoding of the data and then replace the readObject() with your code that decodes the data back into the object that the rest of your code requires.

Page 1 of 2 12 LastLast

Similar Threads

  1. Java networking.
    By tim in forum New To Java
    Replies: 7
    Last Post: 07-16-2009, 10:43 PM
  2. help with networking and threads
    By byuu in forum Networking
    Replies: 9
    Last Post: 05-21-2008, 05:03 AM
  3. java networking via browser
    By pratik.ac in forum Networking
    Replies: 2
    Last Post: 04-21-2008, 05:25 PM
  4. Java networking programming (I)
    By Java Tutorial in forum Java Tutorial
    Replies: 0
    Last Post: 12-24-2007, 07:21 PM
  5. Multithreading + Networking (desperate)
    By bluebarca in forum New To Java
    Replies: 1
    Last Post: 11-07-2007, 02:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •