public void DoubleDisposeTest() { var connector = new TcpConnector("127.0.0.1", 7777); connector.Dispose(); connector.Dispose(); }
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(); } }
static void ConnectionLoop() { while (true) { string message = TcpConnector.Recieve(); TcpConnector.Send(ManageComputationRequest(message)); } }
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(); }
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(); }
public ServerNodeConnectionManager(IPEndPoint ipEndPoint, DataRequestMessage dataRequestMessage) { _dataRequestMessage = dataRequestMessage; var tcpConnector = new TcpConnector(GetTcpSocket(ipEndPoint), new DefaultWireProtocol()); tcpConnector.StateChanged += OnStateChanged; tcpConnector.MessageReceived += OnMessageReceived; tcpConnector.StartAsync(); }
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); }
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); }
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(); }
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); }
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(); }
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(); }
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); }
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); }
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()); }
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)); }
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(); }
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); }
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()); }
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); }
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); }
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); }
public SubscriptionsChannel(TcpConnector connector) { _connector = connector; _log = LogManager.GetLogger(); }
public void SetServer(string serverName, int port) { SetConnector(() => TcpConnector.Connect(serverName, port, Logger.Instance, 1)); }
static void Main(string[] args) { TcpConnector.ConnectToTCP(); ConnectionLoop(); }
//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; }
public void StartClient(string serverName, int port) { StartClient(() => TcpConnector.Connect(serverName, port, 1)); }
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(); }
public void SetServerOverride(IPAddress address, int port) { SetConnectorOverride(() => TcpConnector.Connect(address.ToString(), port, Logger.Instance, 1)); }