Пример #1
0
 public void listen()
 {
     while (clientSocket.Connected)
     {
         try
         {
             NetworkStream netStream = clientSocket.GetStream();
             byte[]        inStream  = new byte[10000];
             netStream.Read(inStream, 0, (int)clientSocket.ReceiveBufferSize);
             string       returndata = System.Text.Encoding.UTF8.GetString(inStream);
             SlidePackage pack       = (SlidePackage)JsonConvert.DeserializeObject(returndata, typeof(SlidePackage));
             lock (lockOb)
             {
                 package.id                = pack.id;
                 package.clear             = pack.clear;
                 package.connectionsNumber = pack.connectionsNumber;
             }
         }
         catch (SocketException ex)
         {
             clientSocket.Close();
         }
         catch (IOException ex) {
         }
     }
 }
Пример #2
0
        public ChatHandler()
        {
            lockOb       = new Object();
            package      = new SlidePackage();
            clientSocket = new TcpClient();
            clientSocket.Connect("127.0.0.1", 50000);
            ThreadStart threadDelegate = new ThreadStart(listen);
            Thread      newThread      = new Thread(threadDelegate);

            newThread.Start();
        }