Results 1 to 20 of 22
Thread: Networking Problem
- 10-24-2008, 01:31 AM #1
Member
- Join Date
- Oct 2008
- Posts
- 9
- Rep Power
- 0
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.
- 10-24-2008, 04:02 AM #2
Are you using RMI or Corba?
They typically run into problems with firewalls.
- 10-24-2008, 06:09 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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.
- 10-24-2008, 06:22 AM #4
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.
- 10-24-2008, 06:53 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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.
- 10-25-2008, 03:59 AM #6
Member
- Join Date
- Oct 2008
- Posts
- 9
- Rep Power
- 0
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.
- 10-25-2008, 04:06 AM #7
- 10-25-2008, 07:04 AM #8
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 10-25-2008, 06:08 PM #9
Member
- Join Date
- Oct 2008
- Posts
- 9
- Rep Power
- 0
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.
Originally Posted by fishtoprecords
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.
Originally Posted by fishtoprecords
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.
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: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");
When the game does freeze at the start, it only System.out.println() until 4 so it freezes right before the writeObject() method.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"); }
- 10-25-2008, 06:47 PM #10
- 10-25-2008, 07:47 PM #11
Member
- Join Date
- Oct 2008
- Posts
- 9
- Rep Power
- 0
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.
- 10-25-2008, 09:47 PM #12
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.it will let some of the program work, yet it will randomly freeze at some other point in it.
- 10-25-2008, 09:59 PM #13
Member
- Join Date
- Oct 2008
- Posts
- 9
- Rep Power
- 0
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.
- 10-25-2008, 11:59 PM #14
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?
- 10-26-2008, 12:53 AM #15
Member
- Join Date
- Oct 2008
- Posts
- 9
- Rep Power
- 0
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.
Originally Posted by Norm
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().
Originally Posted by Norm
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)
Originally Posted by Norm
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.
Originally Posted by Norm
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.
- 10-26-2008, 02:36 AM #16
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.
- 10-26-2008, 04:06 AM #17
Member
- Join Date
- Oct 2008
- Posts
- 9
- Rep Power
- 0
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().
- 10-26-2008, 05:28 AM #18
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.
- 10-26-2008, 06:45 AM #19
Member
- Join Date
- Oct 2008
- Posts
- 9
- Rep Power
- 0
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.
Originally Posted by fishtoprecords
Duh. What are you trying to imply with this other than just making assumptions?
Originally Posted by fishtoprecords
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.
Originally Posted by fishtoprecords
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.
Originally Posted by fishtoprecords
- 10-26-2008, 01:54 PM #20
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.
Similar Threads
-
Java networking.
By tim in forum New To JavaReplies: 7Last Post: 07-16-2009, 10:43 PM -
help with networking and threads
By byuu in forum NetworkingReplies: 9Last Post: 05-21-2008, 05:03 AM -
java networking via browser
By pratik.ac in forum NetworkingReplies: 2Last Post: 04-21-2008, 05:25 PM -
Java networking programming (I)
By Java Tutorial in forum Java TutorialReplies: 0Last Post: 12-24-2007, 07:21 PM -
Multithreading + Networking (desperate)
By bluebarca in forum New To JavaReplies: 1Last Post: 11-07-2007, 02:14 PM


LinkBack URL
About LinkBacks


Bookmarks