<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    // Incoming data from the client.
          public static string data = null;
     
         public static void StartListening() {
            // Data buffer for incoming data.
            byte[] bytes = new Byte[1024];

            // Establish the local endpoint for the socket.
            // Dns.GetHostName returns the name of the
             // host running the application.
             IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName());
            IPAddress ipAddress = ipHostInfo.AddressList[0];
            IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 11000);

            // Create a TCP/IP socket.
            Socket listener = new Socket(AddressFamily.InterNetwork,
                SocketType.Stream, ProtocolType.Tcp );

            // Bind the socket to the local endpoint and
            // listen for incoming connections.
             try {
                listener.Bind(localEndPoint);
                 listener.Listen(10);
     
                // Start listening for connections.
                while (true) {
                    Console.WriteLine("Waiting for a connection");
                     // Program is suspended while waiting for an incoming connection.
                    Socket handler = listener.Accept();
                     data = null;

                    // An incoming connection needs to be processed.
                    while (true) {
                        data = string.Empty;
                         bytes = new byte[1024];
                         int bytesRec = handler.Receive(bytes);
                         data += Encoding.GetEncoding("GB2312").GetString(bytes,0,bytesRec);
                         if (data.IndexOf("<EOF>") > -1) {
                             // Show the data on the console.
                             Console.WriteLine("Text received : {0}", data);
                             continue;
                         }

                         // Echo the data back to the client.
                         byte[] msg = Encoding.ASCII.GetBytes(data);

                         handler.Send(msg);
                     }
     
              
     
                     handler.Shutdown(SocketShutdown.Both);
                     handler.Close();
                 }
               
             } catch (Exception e) {
                Console.WriteLine(e.ToString());
             }
     
             Console.WriteLine("\nPress ENTER to continue");
             Console.Read();
            
         }
     

    posted on 2011-01-11 13:19 sanmao 閱讀(433) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發表評論。


    網站導航:
    博客園   IT新聞   Chat2DB   C++博客   博問  
     

    常用鏈接

    留言簿(5)

    隨筆分類

    隨筆檔案

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 一级毛片不卡免费看老司机| 久久久无码精品亚洲日韩按摩 | 亚洲中文字幕一二三四区苍井空 | 成年女人视频网站免费m| 亚洲日韩乱码中文无码蜜桃臀| 91精品国产免费久久国语麻豆| 少妇中文字幕乱码亚洲影视| xxxx日本免费| 国产成人精品日本亚洲18图| 最近2019中文字幕免费看最新| 亚洲综合色一区二区三区| 美女被免费视频网站a国产| 亚洲狠狠婷婷综合久久| 国产免费观看黄AV片| 国产精品免费一区二区三区| 亚洲av永久无码精品网站| 1000部拍拍拍18勿入免费凤凰福利| 亚洲va久久久久| 免费在线看片网站| 中文字幕在线免费看线人| 中文字幕亚洲综合精品一区| 大陆一级毛片免费视频观看i| 黄色a级免费网站| 亚洲国产精品VA在线看黑人| 99在线精品免费视频九九视| 亚洲av成人中文无码专区| 亚洲中久无码永久在线观看同| 91香蕉在线观看免费高清| 亚洲欧洲AV无码专区| 国产亚洲成人久久| 1000部羞羞禁止免费观看视频 | 毛片在线免费视频| 国产99精品一区二区三区免费| 亚洲色图国产精品| 国产伦精品一区二区三区免费迷| 国产一级a毛一级a看免费人娇| 亚洲国产精品免费在线观看| 国产一区二区三区在线免费观看| 精品国产一区二区三区免费| 亚洲国产精品无码久久九九大片| 亚洲精品tv久久久久久久久|