public WaitHandle Connect(Client client) { WaitHandle waithandler = null; try { PrintThreadPool("[Before Connect]"); IAsyncResult ar = client.sck.BeginConnect(this.RemoteEndPoint, ConnectCallback, client); PrintThreadPool("[After Connect]"); waithandler = ar.AsyncWaitHandle;//無效 } catch (SocketException sckEx) { Console.WriteLine("[Connect]Socket error:{0}", sckEx.Message); } catch (Exception ex) { Console.WriteLine("[Connect]error:{0}", ex.Message); } return waithandler; }
public void InitSocketClient(int count) { for(int i = 0;i < count;i++) { Socket sck = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); Client client = new Client { sck = sck, ClientNo = (i + 1) }; Clients.Add(client); } }