.NET 端口监听
1.直接調用微軟socket對象處理
static void Main(string[] args){try{IPAddress ip = new IPAddress(new byte[] { 127, 0, 0, 1 });//在3721端口新建一個TcpListener對象TcpListener listener = new TcpListener(ip, 3721); listener.Start();Console.WriteLine("started listening..");//開始監聽while (true){Socket s = listener.AcceptSocket();string remote = s.RemoteEndPoint.ToString();//允許js跨越訪問var bytes = System.Text.Encoding.UTF8.GetBytes("HTTP/1.1 200 OK\r\nAccess-Control-Allow-Origin: * \r\n\r\nOK");s.Send(bytes);s.Shutdown(SocketShutdown.Send);}}catch (System.Security.SecurityException){Console.WriteLine("firewall says no no to application – application cries..");}catch (Exception){Console.WriteLine("stoped listening..");}}
轉載于:https://www.cnblogs.com/Adger/p/10848227.html
總結
- 上一篇: 下载安装 binary editor
- 下一篇: 爬虫之Xpath详解