<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)

    隨筆分類

    隨筆檔案

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲另类无码专区首页| 国产亚洲人成A在线V网站| 久久精品国产亚洲AV无码麻豆 | 亚洲综合色区在线观看| 美女黄频免费网站| 免费午夜爽爽爽WWW视频十八禁| 亚洲精品无码专区久久| 日韩精品视频免费观看| 亚洲av片在线观看| va亚洲va日韩不卡在线观看| 成人午夜影视全部免费看| 国产亚洲欧洲Aⅴ综合一区| 国产一级高青免费| 亚洲第一成年男人的天堂| 日本免费人成视频在线观看| 亚洲尹人九九大色香蕉网站 | 久久久久亚洲精品天堂| 免费精品国产自产拍在| 亚洲中文字幕无码中文| 国产男女猛烈无遮挡免费视频 | 婷婷亚洲综合五月天小说| 久久久久久精品成人免费图片| 亚洲一级毛片中文字幕| 国产大片线上免费看| 国产精品免费视频观看拍拍| 久久亚洲精品成人综合| 日韩精品福利片午夜免费观着| 精品国产_亚洲人成在线| 夜夜春亚洲嫩草影院| 亚洲精品视频在线免费| 亚洲jizzjizz少妇| 九月丁香婷婷亚洲综合色| 91精品视频免费| 黄色免费网址大全| 久久精品国产亚洲av麻豆色欲 | 亚洲美女色在线欧洲美女| 永久免费看bbb| 中文字幕无码毛片免费看| 国产成人精品日本亚洲专一区| 亚洲av午夜成人片精品电影| 一区二区三区观看免费中文视频在线播放 |