ServerSocket java not reading inputStream?

后端 未结 3 1992
小蘑菇
小蘑菇 2021-01-27 13:06

I have written a server is java here is the code:

public mainClass() 
{ 
    try 
    { 
        ss = new ServerSocket(8080); 

        while (true) 
        { 
         


        
3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-27 13:48

    From my own experience, readLine is not a good idea, especially when working with different languages and platforms, a better approach will be to use InputStreamReader and its read(char[] buff) method, and agree on both sides regarding the length to be sent each time.

    Again, I have no reference to that, only my experience.

    Also, looking at your code, you send a string without a new line character: [socket sendString:@"Hi This is a second test"]; maybe adding \n at the end will solve it for you.

提交回复
热议问题