Java sockets - Client doesn't read the strings from server's socket

前端 未结 2 1571
北恋
北恋 2020-12-11 14:15

I have two Java projects that communicate with sockets through strings. One is a client and the other is a server. The server accepts the connection trough the \"ServerSocke

2条回答
  •  星月不相逢
    2020-12-11 14:40

    In your send methods, try changing out.write(m) to out.println(m).

    Each time you are using the readLine method it will keep reading until it hits a new line character or line separator. The println method will automatically put a line.separator at the end of the string you are trying to send.

    https://docs.oracle.com/javase/7/docs/api/java/io/PrintWriter.html#println()

提交回复
热议问题