Im having trouble with sending information from a client to server. The output is supposed to be:
*Server: *
$> java TCPClient /serverIP/ 8080
User ID of the current client: rocky // should print this out but it doesn't
...
Client
$> java TCPServer 8080
Type login to start
login //user input
FROM SERVER: Please log in with your user ID.
rocky //user input
Sent to server : rocky
...
But the server doesn't print that statement out, does it have to do with the buffer or streaming needing to be cleaned up? The code is included below.
TCPServer Code:
...
BufferedReader inFromClient = new BufferedReader(
new InputStreamReader(connectionSocket.getInputStream()));
DataOutputStream outToClient =
new DataOutputStream(connectionSocket.getOutputStream());
...
outToClient.writeBytes("Please log in with your user ID.\n");
String clientId = inFromClient.readLine()
System.out.println("User ID of the current client: " + clientId);
outToClient.writeBytes("Game has started!\n");
TCPClient Code:
...
DataOutputStream outToServer =
new DataOutputStream(clientSocket.getOutputStream());
BufferedReader inFromServer = new BufferedReader(
new InputStreamReader(clientSocket.getInputStream()));
...
System.out.println("Type login to start");
if ((inFromUser.readLine()).equals(login))
{
System.out.println("FROM SERVER: " + inFromServer.readLine());
String option = inFromUser.readLine();
outToServer.writeBytes(option);
System.out.println("Sent to Server: "+ option);
//should print "FROM SERVER: Game has started!"
System.out.println("FROM SERVER: " + inFromServer.readLine());
}
...
OutputStream.flush()?inFromUser.readLine()return, if anything?readLine()result needs to be checked for null before you do anything else with it.outToServer.writeBytes(option + "\n");