|
C#聊天程序(9) default: Close(); break; } } // Handle text change notifications and send talk private void HandleTextChange(Object sender, EventArgs e){ if(talker != null){ talker.SendTalk((sender as TextBox).Text); } } // Close with an eXPlanation private void Close(String message){ MessageBox.Show(message, "Error!"); Close(); } // Private UI elements private TextBox receiveText; private TextBox sendText; private Label statusText; private Talker talker; } // An encapsulation of the Sockets class used for socket chatting class Talker:IDisposable{ // ConstrUCt a talker public Talker(IPEndPoint endPoint, bool client){ this.endPoint = endPoint; this.client = client; socket = null; reader = null;
|