c#聊天客户端程序

时间:2018-02-02 04:22:07
【文件属性】:

文件名称:c#聊天客户端程序

文件大小:908B

文件格式:SLN

更新时间:2018-02-02 04:22:07

c#

c#网络编程异步套接字客户端程序 private void button1_Click(object sender, EventArgs e) { try { IPHostEntry local = Dns.GetHostByName(Dns.GetHostName()); IPAddress ip = IPAddress.Parse(local.AddressList[0].ToString()); IPEndPoint iep = new IPEndPoint(ip, 5678); Socket clientsocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); clientsocket.BeginConnect(iep, new AsyncCallback(ConnectCallback), clientsocket); } catch (Exception ee) { Console.WriteLine(ee.ToString()); } } private void ConnectCallback(IAsyncResult ar) { try { Socket clientsocket = (Socket)ar.AsyncState; clientsocket.EndConnect(ar); state = new StateObject(); state.worksocket = clientsocket; Send("客户连接成功"); clientsocket.BeginReceive(state.buffer, 0, StateObject.buffersize, 0, new AsyncCallback(ReadCallback), state); } catch (Exception e) { Console.WriteLine(e.ToString()); } }


网友评论