Networking Problem...

I have wrote a small server/client program using normal sockets (to get the framework of my networking solution to my game down). When I test the program on my machine it works great. The client and server can talk and the sun rises and sets!

So I decided to test it by giving it to my friend. I load the server up, he loads the client and tries to connect. Connection successful! Then he sends some test data, and the server gets it. The server is supposed to reply to the client with a basic message when it receives data. Suddenly, the client does not receive this message from the server. Also, any additional attempt at sending data from the client to the server never makes it to the server.

I am not going to include code just yet, I am wondering if there is something special or if my problem is apparent based on the symptons I’ve described. So, if code is needed, code will be supplied.

In summary:
Client/server works fine when I test it on my machine.
Client/server does not work when I test the client on another machine.

Thank you

do you flush() your outputstreams?

Yes. Here is the method to send data from the server to the client:

	
public void write(String output)
	{
		//out.write(output);
		out.print(output);
		server.display("SERVER: Sent output: " + output + "\n");
		out.flush();
	}

Here is the method to send data from the client to the server:


/**
	* Sends a line with a linefeed / carriage return to the server
	* @param output String to be sent to the server
	*/
	public void sendLine (String output) throws IOException 
	{
		System.out.print("TCP: Sending: " + output);
		out.print(output);
		//out.write(output);
		out.flush();
		System.out.println("TCP: Sent the output");
		//System.out.println("TCP: TEST: " + in.readLine());
		
		
	}

I assume you are using PrintStreams?

do both computers have the same default character set?

This is what each side is using:
A printWriter and a bufferedReader.


	private PrintWriter out;
	private BufferedReader in;
	private Socket socket;

and then:


try
		{
			socket = new Socket(host, port);
	
			InputStreamReader inputStream = new InputStreamReader(socket.getInputStream());
			in = new BufferedReader(inputStream);
			out = new PrintWriter(socket.getOutputStream());
		}
		catch (IOException e)
		{
			e.printStackTrace();
			return e;
		}

I do not know if each side is using the same character set. Is there a way I can check and a way to specify which one to use?

  1. (easy) connect using telnet instead of your client, and WATCH what happens

  2. (slightly more effort) Download ethereal.com, learn how to use a packet sniffer, and run it to see what is being sent over the wire.

If I figured it right, the server at one moment dosen’t send a message it should have.

You can try:
1.5 (between 1 & 2 from blahblahblahh :slight_smile: ) : write to console time and data of every packet sent
3: debug server side handling with step-by-step, starting when you receive your first message

if you need someone to test it with, contact me on icq or msn, I’m mostly at computer now, GMT+2 timezone