|
C#聊天程序(11) Received, End, Error } // Nested enum for supported states public enum Status{ Listening, Connected } // Start up the talker's functionality public void Start(){ ThreadPool.QueueUserWorkItem(new WaitCallback(EstablishSocket)); } // Send text to remote connection public void SendTalk(String newText){ String send; // Is this an append if((prevSendText.Length <= newText.Length) && String.CompareOrdinal( newText, 0, prevSendText, 0, prevSendText.Length)==0){ String append = newText.Substring(prevSendText.Length); send = String.Format("A{0}:{1}", append.Length, append); // or a complete replacement }else{ send = String.Format("R{0}:{1}", newText.Length, newText); } // Send the data and flush it out writer.Write(send); writer.Flush();
|