Example #1
0
 /// <summary>
 /// 监听线程
 /// </summary>
 private void Linsening()
 {
     while (true)
     {
         UserClient userClient=new UserClient(sokWelcome.Accept());
         Thread.Sleep(100);
         connectNum++;
         dictConnection.Add(userClient.port, userClient);
         ThreadRec[connectNum] = new Thread(new ParameterizedThreadStart(Recevie));
         ThreadRec[connectNum].IsBackground = true;
         ThreadRec[connectNum].Start(userClient.port);
         TbResult.Dispatcher.Invoke(ShowInfoHandler, "Connected " + dictConnection[userClient.port].ipep.ToString());
     }
 }
Example #2
0
        private void Connect()
        {
            IPAddress ip=IPAddress.Parse(TbIP.Text.Trim());
            IPEndPoint ipep=new IPEndPoint(ip,int.Parse(TbPort.Text.Trim()));
            sokConnection = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            try
            {
                sokConnection.Connect(ipep);
                myClient = new UserClient(sokConnection);

            }
            catch (Exception ex)
            {
                ShowInfo(ex.Message);
            }
        }