• 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()); } }

    0
    103
    908B
    2015-01-13
    10
上传资源赚积分or赚钱