示例#1
0
        public void DoubleDisposeTest()
        {
            var connector = new TcpConnector("127.0.0.1", 7777);

            connector.Dispose();
            connector.Dispose();
        }
示例#2
0
    void Start()
    {
        byte[] recv = new byte[16 * 1024];

        connector = new TcpConnector("192.168.31.236", 8888);
        connector.On(SocketEvents.Message, (d) =>
        {
            byte[] reData = d as byte[];
            Debug.LogError(reData.Length);
            unpacker.Input(reData);
            int length;
            ushort msgId;
            while (unpacker.MoveNext(recv, out length, out msgId))
            {
                LoginS2C lmsg = ProtobufTool.BytesToProtoBuf <LoginS2C>(recv, 0, length);
                Debug.LogError("recv msgID: " + msgId + " data:" + lmsg.playerId);
            }
        });
        var wait = connector.Connect();

        if (!Util.Wait(wait, 1000))
        {
            connector.Dispose();
        }
    }
示例#3
0
 static void ConnectionLoop()
 {
     while (true)
     {
         string message = TcpConnector.Recieve();
         TcpConnector.Send(ManageComputationRequest(message));
     }
 }
示例#4
0
    internal void StartClient(string address, int port)
    {
        var connector = new TcpConnector(address, port);

        connector.OnConnected += Connector_OnConnected;
        connector.Connect();
        StartCoroutine(connector.WaitFor());
    }
 public static void Main(string[] args)
 {
     _tcpConnector = new TcpConnector(GetSocket(), new DefaultWireProtocol());
     _tcpConnector.StateChanged    += OnConnectorStateChanged;
     _tcpConnector.MessageReceived += OnMessageReceived;
     _tcpConnector.StartAsync();
     Console.ReadLine();
 }
示例#6
0
        public void ConnectTCP(string hostname, int port)
        {
            TcpConnector con = (TcpConnector)dp.Connections.First(x => x is TcpConnector);

            con.HostName  = hostname;
            con.Port      = port;
            dp.Connection = con;
            Connect();
        }
示例#7
0
        public ServerNodeConnectionManager(IPEndPoint ipEndPoint, DataRequestMessage dataRequestMessage)
        {
            _dataRequestMessage = dataRequestMessage;
            var tcpConnector = new TcpConnector(GetTcpSocket(ipEndPoint), new DefaultWireProtocol());

            tcpConnector.StateChanged    += OnStateChanged;
            tcpConnector.MessageReceived += OnMessageReceived;
            tcpConnector.StartAsync();
        }
示例#8
0
        public void StartClient(IList <NtIPAddress> servers)
        {
            List <Connector> connectors = new List <Connector>();

            foreach (var server in servers)
            {
                connectors.Add(() => TcpConnector.Connect(server.IpAddress, server.Port, 1));
            }
            StartClient(connectors);
        }
示例#9
0
        public void SetServer(IList <NtIPAddress> servers)
        {
            List <Connector> connectors = new List <Connector>();

            foreach (var server in servers)
            {
                connectors.Add(() => TcpConnector.Connect(server.IpAddress, server.Port, Logger.Instance, 1));
            }
            SetConnector(connectors);
        }
示例#10
0
        static Bitmap ManageComputationRequest(string message)
        {
            MandelbrotJSON mandelbrotJSON = ConverterJSON.ReadFromString(message);
            if(mandelbrotJSON==null)
            {
                TcpConnector.End();
                TcpConnector.Serve();
            }

            Computation computation = new Computation(mandelbrotJSON);
            return computation.ComputeMandelbrot();
        }
示例#11
0
        public async ValueTask InitAsync()
        {
            _tcpConnector = await TcpConnector.Factory.CreateAsync(_options.TcpConnectOptions, _options.TcpAcceptOptions, _bytesPool);

            _baseConnectionDispatcher = new BaseConnectionDispatcher(new BaseConnectionDispatcherOptions()
            {
                MaxSendBytesPerSeconds    = (int)_options.BandwidthOptions.MaxSendBytesPerSeconds,
                MaxReceiveBytesPerSeconds = (int)_options.BandwidthOptions.MaxReceiveBytesPerSeconds,
            });

            _acceptLoopTask = this.AcceptLoopAsync(_cancellationTokenSource.Token);
        }
示例#12
0
    public void Initialize()
    {
        this.connector    = new TcpConnector();
        this.packageQueue = new Queue <Package>();
        this.locker       = new Locker();
        this.locker.Initialize();

        //this.sendQueue = new Queue<TcpPacket>();
        //this.sendLocker = new Locker();
        //this.sendLocker.Initialize();
        //this.sendThread = new Thread(SendingThread);
        //this.sendThread.Start();
    }
示例#13
0
        static void Main(string[] args)
        {
            Console.OutputEncoding = System.Text.Encoding.UTF8;
            int serverPort = 6891;

            Console.WriteLine("Hello Client!");
            TcpConnector client = new TcpConnector();

            client.Open(TcpConnector.GetAvailablePort(serverPort), 2);
            client.Connect("127.0.0.1", serverPort);

            _wrap = AutoWrapClient.GetProxy(client);
            // Выведем сообщение в консоли сервера
            string typeStr = typeof(Console).AssemblyQualifiedName;
            var    console = _wrap.GetType(typeStr);

            console.WriteLine("Hello from Client");

            var str = string.Empty;

            while (!str.ToLower().Equals("exit"))
            {
                Console.Write("Write text to server: ");
                str = Console.ReadLine();
                console.WriteLine(str);
            }

            var testClass = (_wrap.GetType("ServerRun.TestClass, ServerRun, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"))._new();
            var text      = testClass.Name();

            Console.WriteLine("Текст из клиента + " + text);
            console.WriteLine(text);

            GC.Collect();
            GC.WaitForPendingFinalizers();

            // Удаления из хранилища на стороне сервера происходит пачками по 50 элементов
            // Отрправим оставшиеся
            client.ClearDeletedObject();

            // Отключимся от сервера, закроем все соединения, Tcp/Ip сервер на клиенте
            client.Close();

            Console.Write("Close server? [y][n]: ");
            if (Console.ReadLine().ToLower().Equals("y"))
            {
                client.CloseServer();
            }
            Console.WriteLine("Press any key...");
            Console.ReadKey();
        }
示例#14
0
        public Room(int listeningPort, int sendingPort, ShipInfo[] ships)
        {
            physicsController = new PhysicsController();
            Body.SetPhysicsController(physicsController);
            shipsInfo       = ships;
            roomClosed      = false;
            lastId          = 0;
            bots            = new List <ShipController>();
            players         = new List <Player>();
            structConverter = new StructConverter();
            IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, listeningPort);

            udp                   = new Udp(localEndPoint);
            connector             = new TcpConnector(localEndPoint);
            projectilesController = new BaseProjectilesController(100);
        }
示例#15
0
        public void TestDoubleConnect()
        {
            var connector = new TcpConnector("127.0.0.1", 7777);

            connector.Connect();

            var isThrow = false;

            try
            {
                connector.Connect();
            }
            catch (RuntimeException)
            {
                isThrow = true;
            }
            Assert.AreEqual(true, isThrow);
        }
示例#16
0
        public void TestOffEvent()
        {
            var             connector = new TcpConnector("127.0.0.1", 7777);
            Action <object> call      = (ex) =>
            {
                Assert.Fail();
            };

            connector.On(SocketEvents.Error, call);
            connector.On(SocketEvents.Error, call);

            connector.On(SocketEvents.Error, (ex) =>
            {
            });

            connector.Off(SocketEvents.Error, call);
            connector.Trigger(SocketEvents.Error, new Exception());
        }
示例#17
0
        public void SimpleTcpTest()
        {
            var connector = new TcpConnector("127.0.0.1", 7777);

            var data   = new byte[0];
            var server = new TcpTestsServer(b =>
            {
                data = b;
            });

            var reData = new byte[0];

            connector.On(SocketEvents.Message, (d) =>
            {
                reData = d as byte[];
            });

            var wait = connector.Connect();

            if (!Util.Wait(wait, 3000))
            {
                server.Dispose();
                connector.Dispose();
                Assert.Fail("wait faild");
            }

            wait = connector.Send(System.Text.Encoding.Default.GetBytes("hello world"));

            if (!Util.Wait(wait, 3000) ||
                !Util.Wait(ref data, 3000) ||
                !Util.Wait(ref reData, 3000))
            {
                server.Dispose();
                connector.Dispose();
                Assert.Fail("wait faild");
            }

            server.Dispose();
            connector.Disconnect();

            Assert.AreEqual("hello world", System.Text.Encoding.Default.GetString(data));
            Assert.AreEqual("hello world", System.Text.Encoding.Default.GetString(reData));
        }
示例#18
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello Server!");
            //    Console.ReadLine();
            int port = 6891;

            if (args.Length > 0)
            {
                port = int.Parse(args[0]);
            }

            Console.WriteLine("Port=" + port);
            Console.WriteLine(typeof(TestClass).AssemblyQualifiedName);

            var server = new TcpConnector();

            server.Open(port, 2);
            server.WaitIsRunning.Task.Wait();
        }
示例#19
0
        private void AddKnownServerConnector(IPEndPoint ipEndPoint)
        {
            var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            try
            {
                socket.Connect(ipEndPoint);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
            var tcpConnector = new TcpConnector(socket, new DefaultWireProtocol());

            tcpConnector.MessageReceived += OnMessageReceivedFromTcpClient;
            tcpConnector.StartAsync();
            _knowedServerNodesConnectors.Add(tcpConnector);
        }
示例#20
0
        public void TestDnsException()
        {
            var       connector = new TcpConnector("http://123.0.0.1", 7777);
            Exception e         = null;

            connector.On(SocketEvents.Error, (ex) =>
            {
                e = ex as Exception;
            });

            var wait = connector.Connect();

            if (!Util.Wait(wait, 10000))
            {
                connector.Dispose();
                Assert.Fail("wait faild");
            }

            Assert.AreEqual(typeof(SocketException), (wait.Result as Exception).GetType());
        }
示例#21
0
        private void StartConnecting(bool wait)
        {
            Debug.Assert(m_connect);

            //  Choose I/O thread to run connector in. Given that we are already
            //  running in an I/O thread, there must be at least one available.
            IOThread ioThread = ChooseIOThread(m_options.Affinity);

            Debug.Assert(ioThread != null);

            //  Create the connector object.

            if (m_addr.Protocol.Equals(Address.TcpProtocol))
            {
                var connector = new TcpConnector(ioThread, this, m_options, m_addr, wait);
                //alloc_Debug.Assert(connector);
                LaunchChild(connector);
                return;
            }

            if (m_addr.Protocol.Equals(Address.IpcProtocol))
            {
                var connector = new IpcConnector(ioThread, this, m_options, m_addr, wait);
                //alloc_Debug.Assert(connector);
                LaunchChild(connector);
                return;
            }

            if (m_addr.Protocol.Equals(Address.PgmProtocol) || m_addr.Protocol.Equals(Address.EpgmProtocol))
            {
                var pgmSender = new PgmSender(m_ioThread, m_options, m_addr);
                pgmSender.Init(m_addr.Resolved as PgmAddress);

                SendAttach(this, pgmSender);

                return;
            }

            Debug.Assert(false);
        }
示例#22
0
        private static BasicConnector CreateConnectorByMode(ConnectionModes mode, CommunicationInfoStruct info)
        {
            BasicConnector res;

            //TODO: add more modes
            switch (mode)
            {
            case ConnectionModes.Usb:
            case ConnectionModes.Bluetooth:
                res = new SerialConnector(info.SerialInfo.RxPort, info.SerialInfo.TxPort, info.SerialInfo.Baudrate);
                break;

            case ConnectionModes.WiFi:
                res = new TcpConnector(info.TcpInfo.Ip, info.TcpInfo.Port);
                break;

            default:
                res = null;
                break;
            }

            return(res);
        }
示例#23
0
        public async Task <IActionResult> Index(ICollection <IFormFile> files)
        {
            var uploads = Path.Combine(_environment.WebRootPath, "uploads");

            foreach (var file in files)
            {
                if (file.Length > 0)
                {
                    using (var reader = new StreamReader(file.OpenReadStream()))
                    {
                        var stream = reader.BaseStream;

                        //await file.CopyToAsync(fileStream);
                        //var stream = file.OpenReadStream();
                        string      hostName = "localhost";
                        IPHostEntry ip       = Dns.GetHostEntryAsync(hostName).Result;

                        TcpConnector connector = new TcpConnector(ip.AddressList[1], 8080);
                        await connector.ConnectAsync(stream);
                    }
                }
            }
            return(View());
        }
 private void OnClientConnected(object sender, TcpClientConnectedEventArgs args)
 {
     _clienTcpConnector = new TcpConnector(args.ClientSocket, new DefaultWireProtocol());
     _clienTcpConnector.MessageReceived += OnMessageReceived;
     _clienTcpConnector.StartAsync();
 }
        /// <summary>
        /// Constructs a new instance of a <see cref="EventStoreConnection"/>
        /// </summary>
        /// <param name="settings">The <see cref="ConnectionSettings"/> containing the settings for this connection.</param>
        private EventStoreConnection(ConnectionSettings settings)
        {
            _settings = settings;

            LogManager.RegisterLogger(settings.Log);
            _log = LogManager.GetLogger();

            _connector = new TcpConnector();
            _subscriptionsChannel = new SubscriptionsChannel(_connector);
        }
示例#26
0
 public SubscriptionsChannel(TcpConnector connector)
 {
     _connector = connector;
     _log       = LogManager.GetLogger();
 }
示例#27
0
 public void SetServer(string serverName, int port)
 {
     SetConnector(() => TcpConnector.Connect(serverName, port, Logger.Instance, 1));
 }
示例#28
0
 static void Main(string[] args)
 {
     TcpConnector.ConnectToTCP();
     ConnectionLoop();
 }
示例#29
0
    //private Vector3 previousPosition;
    //private Vector3 speedMod;


    // Start is called before the first frame update
    void Start()
    {
        connector = FindObjectOfType <TcpConnector>(); // find the TCP connection manager in the scene
        speed     = defaultSpeed;
        //previousPosition = transform.position;
    }
示例#30
0
 public void StartClient(string serverName, int port)
 {
     StartClient(() => TcpConnector.Connect(serverName, port, 1));
 }
示例#31
0
        public EventStoreConnection(IPEndPoint tcpEndPoint)
        {
            Ensure.NotNull(tcpEndPoint, "tcpEndPoint");

            _tcpEndPoint = tcpEndPoint;
            _connector = new TcpConnector(_tcpEndPoint);
            _outstandingOperations = new ConcurrentDictionary<Guid, ITaskCompletionWrapper>();

            _lastReconnectionTimestamp = DateTime.UtcNow;
            _connection = _connector.CreateTcpConnection(OnPackageReceived, ConnectionEstablished, ConnectionClosed);
            _timeoutCheckStopwatch.Start();

            _monitoringThread = new Thread(MonitoringLoop)
            {
                IsBackground = true,
                Name = string.Format("Monitoring thread")
            };
            _monitoringThread.Start();
        }
示例#32
0
 public void SetServerOverride(IPAddress address, int port)
 {
     SetConnectorOverride(() => TcpConnector.Connect(address.ToString(), port, Logger.Instance, 1));
 }