예제 #1
0
 static void Main(string[] args)
 {
     _server = new SocketLibrary.Server("192.168.3.150", 8088);
     _server.MessageReceived += _server_MessageReceived;
     _server.Connected       += _server_Connected;
     _server.ConnectionClose += _server_ConnectionClose;
     _server.MessageSent     += _server_MessageSent;
     _server.StartServer();
     while (true)
     {
         System.Threading.Thread.Sleep(200);
     }
 }
예제 #2
0
        public void Open()
        {
            //查找空闲端口
            _listenPort = GetFirstAvailablePort();

            string lip = GetLocalIP();

            if (string.IsNullOrEmpty(lip))
            {
                _listenIP = "0.0.0.0";
            }
            else
            {
                _listenIP = lip;
            }

            //机器人显示名称
            RobotDisplayName = "Robot_" + _listenIP + ":" + _listenPort;

            //守护进程
            _debugActionWorker.WorkerSupportsCancellation = true;
            _debugActionWorker.DoWork += _debugActionWorker_DoWork;
            _debugActionWorker.RunWorkerAsync();

            //创建调试Socket
            _debugSocketServer = new SocketLibrary.Server(_listenIP, _listenPort);
            _debugSocketServer.MessageReceived += _server_MessageReceived;
            _debugSocketServer.Connected       += _server_Connected;
            _debugSocketServer.ConnectionClose += _server_ConnectionClose;
            _debugSocketServer.MessageSent     += _server_MessageSent;

            try
            {
                _debugSocketServer.StartServer();
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.ToString());
            }

            //启动端口扫描服务
            _udpPortScanListener.ResponseText = RobotDisplayName;
            try
            {
                _udpPortScanListener.UdpClient.OpenListener();
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.ToString());
            }
        }