Ejemplo n.º 1
0
 /**
  * 获取单例
  * @return
  */
 public static SocketControls GetInstance()
 {
     if (instance == null)
     {
         instance = new SocketControls();
     }
     return(instance);
 }
Ejemplo n.º 2
0
        /**
         * 返回连接的socket
         */
        public judpSocket Accept()
        {
            UDTSocket socket = SocketControls.GetInstance().GetSocket();

            if (socket == null)
            {
                //再次获取下一个
                socket = SocketControls.GetInstance().GetSocket();
            }
            //包装
            judpSocket jsocket = new judpSocket(socket);

            judpSocketManager.GetInstance(socket.GetEndpoint()).AddSocket(jsocket);
            return(jsocket);
        }
Ejemplo n.º 3
0
        /**
         * 启动接收
         */
        public bool Start()
        {
            if (!isStart || !isSucess)
            {
                FlashLogger.Warn("已经关闭的监听或监听端口不能使用");
                return(false);
            }
            Thread serverThread = new Thread(() =>
            {
                while (isStart)
                {
                    try
                    {
                        UDTSocket csocket = server.Accept();
                        try
                        {
                            csocket.GetInputStream().SetLargeRead(islagerRead);
                            csocket.GetInputStream().ResetBufMaster(isRWMaster);
                        }
                        catch (IOException e)
                        {
                            Console.WriteLine(e);
                        }

                        SocketControls.GetInstance().AddSocket(csocket);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }
                }
            });

            serverThread.IsBackground = true;
            serverThread.Name         = ("judpServer_" + DateTime.Now.Ticks / 10000);
            serverThread.Start();
            return(true);
        }