为什么我在socket输入流中得到奇怪的字符

时间:2014-04-13 07:58:15

标签: java sockets stream

//  Portion of code copied from the senders side
clientSocket = new Socket(successor.IP, successor.PORT);
toServer = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream()));
String message = "deleteme\n"+predecessor.IP+","+predecessor.PORT;
toServer.write(message);
toServer.newLine();
toServer.flush();


//  Portion of code copied from the receivers side
fromClient = new BufferedReader(new InputStreamReader(socket.getInputStream()));
toClient = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
input = fromClient.readLine();

在接收方,deleteme之前有奇怪的字符。像俱乐部一样。

我想知道这些角色来自哪里以及如何解决问题?我正在做的临时修复是在发送deleteme消息之前,我发送了一些垃圾数据,如abcd。然后deleteme就到了那里。

0 个答案:

没有答案