When learning to use Delphi, Ignore something ignored.

zhaozj2021-02-16  88

Today, in the process of learning chat software for TClientSocket ;: TSERVERSOCKET;, I found a very depressed problem. When the data is received, it is always possible to send to the client when the data is forwarded.

Self.Memo1.Lines.Add (socket.receivetext); for i: = 1 to num do self.serversocket1.socket.connections [i - 1] .sendtext (socket.ReceiveText);

In the above code, once the server accepts the information sent by the client, first add the string to the MEMO and then send a message to other clients. However, it is here, the server can add a string, but other clients don't work. If you put Self.Memo1.Lines.Add (Socket.ReceiveText); if you delete it, you can only have a client to receive information sent.

After multi-party efforts to view the changes in variable speed, it is finally a problem.

When the rescetext is operated, the system will clear the Socket buffer, that is, if the rest is repeated to read the buffer again, the return is a null value, that is, the back cannot be transmitted. So slightly change the code, add a temporary variable to solve the problem.

S: = socket.ReceirtExt; self.Memo1.Lines.add (s); for i: = 1 to num do self.serversocket1.socket.connections [i - 1] .sendtext (s);

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

New Post(0)