クライアントからサーバーへ情報を送信する際に問題があります。 出力が可能になっている:JavaのTCPサーバー
*サーバー:*
$> javaのれるtcpClient /サーバIP/8080現在のクライアントの
ユーザーID:岩の//はこれをプリントアウトしなければならないが、それは
ません。 ..
クライアント
$> javaのTCPServerの8080
タイプのログインが開始し
ログイン //ユーザー入力
FROM SERVER:ユーザーIDでログインしてください。
岩の //ユーザーの入力サーバに送信さ
:岩の
...
しかし、サーバがその文をプリントアウトしていない、それが清掃される必要がバッファやストリーミングに関係していませんアップ?コードは以下に含まれています。
TCPServerのコード:
...
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コード:
...
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()'が返すものは何ですか? –
'readLine()'の結果は、他に何かをする前に、nullをチェックする必要があります。 – EJP