Socket communication needs to pay attention to problems

xiaoxiao2021-03-06  69

When using Java development socket communication, when the output stream is used, for example: PrintWriter OS = New PrintWriter (socket.getoutputStream ()); Os.Println (MSG); // must use Println to log strings to end OS .flush (); last sentence is not omitted, otherwise it will not refresh the cache, and the client cannot receive any data. If you don't have println, the string will not end with Print, so that the receiving end will wait until the string ends or the connection will show that the string has been transferred, so when using this method, Be sure to pay attention to the flag bit of the transfer string.

In addition, this type of problem has occurred when I use Perl to communicate. When using Perl to program the Socket communication, the message sent last must be added / N, which is a newline, so that it is considered to be the end of communication.

转载请注明原文地址:https://www.9cbs.com/read-85776.html

New Post(0)