c聊天程序(编辑修改稿)内容摘要:

Close()。 break。 default: Close()。 break。 } } // Handle text change notifications and send talk private void HandleTextChange(Object sender, EventArgs e){ if(talker != null){ ((sender as TextBox).Text)。 } } // Close with an explanation private void Close(String message){ (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){ = endPoint。 = client。 socket = null。 reader = null。 writer = null。 statusText = prevSendText = prevReceiveText =。 } // Finalize a talker ~Talker(){ Dispose()。 } // Dispose of resources and surpress finalization public void Dispose(){ (this)。 if(reader != null){ ()。 reader = null。 } if(writer != null){ ()。 writer = null。 } if(socket != null){ ()。 socket = null。 } } // Nested delegat class and matchine event public delegate void NotificationCallback(Notification notify, Object data)。 public event NotificationCallback Notifications。 // Nested enum for notifications public enum Notification{ Initialized = 1, StatusChange, Received, End, Error } // Nested enum for supported states public enum Status{ Listening, Connected } // Start up the talker39。 s functionality public void Start(){ (new WaitCallback(EstablishSocket))。 } // Send text to remote connection public void SendTalk(String newText){ String send。 // Is this an append if(( = ) amp。 amp。 ( newText, 0, prevSendText, 0, )==0){ String append = ()。 send = (A{0}:{1}, , append)。 // or a plete replacement }else{ send = (R{0}:{1}, , newText)。 } // Send the data and flush it out (send)。 ()。 // Save the text for future parison prevSendText = newText。 } // Send a status notification p。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。