3
使用此代碼發送更多的信息:Java的TCP服務器在一個沖洗
Java服務器端:
...
out = new PrintWriter(this.client.getOutputStream(), true);
...
public void sendMsg(String msg) {
out.println(msg);
//out.flush(); // we don't flush manually because there is auto flush true
}
C#客戶端:
while(connected) {
int lData = myStream.Read(myBuffer, 0, client.ReceiveBufferSize);
String myString = Encoding.UTF8.GetString(myBuffer);
myString = myString.Substring(0, lData);
myString = myString.Substring(0, myString.Length-2);
addToQueue(myString);
}
mystring變量中有很多郵件時,服務器應像
hello \r\t hello \r\t ...
他們應該分開來像
hello \r\t
hello \r\t ...
這意味着當我等待他們一個個都瞬間所有的人都在排,我怎麼能使其在不同的沖洗發送一個接一個。
注意我在一秒鐘內發送30條信息(1秒),我希望它們分開。