Пример #1
0
        public TcpMessagingTests()
        {
            StartupInfo.PortNum = 54231;
            _connectionInitializationListener = new ConnectionInitializationListener();
            _tcpClient = new TcpClient();
            var callBackContainer = new CallBackContainer <Socket>();

            _connectionInitializationListener.NewSocketEvent += callBackContainer.CallBackMethod;

            _tcpClient.Connect(Dns.GetHostName(), StartupInfo.PortNum);

            callBackContainer.WaitForCallBack(1000);

            _tcpConnectionHandler = new TcpConnectionHandler(callBackContainer.CallBackObject);
        }
        public static SocketHelper GetSocketHelper(int portNumber)
        {
            StartupInfo.PortNum = portNumber;
            if (AlreadyDefinedHelpers.ContainsKey(portNumber))
            {
                return(AlreadyDefinedHelpers[portNumber]);
            }
            var callBackContainer     = new CallBackContainer <Socket>();
            var connectionInitializer = new ConnectionInitializationListener();

            connectionInitializer.NewSocketEvent += (sender, socket) => callBackContainer.CallBackMethod(sender, socket);

            new TcpClient(Dns.GetHostName(), StartupInfo.PortNum);

            callBackContainer.WaitForCallBack(10000);

            AlreadyDefinedHelpers.Add(portNumber, new SocketHelper
            {
                Socket = callBackContainer.CallBackObject
            });

            return(AlreadyDefinedHelpers[portNumber]);
        }
Пример #3
0
 public void Init()
 {
     _connectInitializer = new ConnectionInitializationListener();
 }
Пример #4
0
 public void Awake()
 {
     _connections              = new List <EstablishedConnection>();
     _listener                 = new ConnectionInitializationListener();
     _listener.NewSocketEvent += ((_, socket) => OnNewClient(socket));
 }