public void ReconnectToServer() { _connection.ConnectionClosed -= OnConnectionClosed; _connection = new TcpClientConnector().ConnectTo(Guid.NewGuid(), _serverEndPoint, ConnectionTimeout, OnConnectionEstablished, OnConnectionFailed); _connection.ConnectionClosed += OnConnectionClosed; _connection.ReceiveAsync(OnRawDataReceived); }
public void Start(int connectTimeoutMilliseconds = 5000) { _connection = new TcpClientConnector().ConnectTo(Guid.NewGuid(), _localEndPoint, _serverEndPoint, OnConnectionEstablished, OnConnectionFailed); _connection.ConnectionClosed += OnConnectionClosed; _connection.ReceiveAsync(OnRawDataReceived); _waitHandle.WaitOne(connectTimeoutMilliseconds); }
public SocketClient() { var remoteEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), DEFAULT_PORT); var connector = new TcpClientConnector(); _connection = connector.ConnectTo(_connectionId, remoteEndPoint, ConnectionTimeout, OnConnectionEstablished, OnConnectionFailed); _connection.ConnectionClosed += OnConnectionClosed; _connection.ReceiveAsync(OnRawDataReceived); }
public void StartReceiving() { if (_connection == null) { throw new InvalidOperationException("Failed connection."); } _connection.ReceiveAsync(OnRawDataReceived); }
public void Start() { _connection = new TcpClientConnector().ConnectTo(Guid.NewGuid(), _serverEndPoint, ConnectionTimeout, OnConnectionEstablished, OnConnectionFailed); _connection.ConnectionClosed += OnConnectionClosed; _connection.ReceiveAsync(OnRawDataReceived); _startWaitHandle.WaitOne(); IsStarted = true; }
public void ReceiveAsync(Action <TcpTypedConnection <T>, T> callback) { if (_receiveCallback != null) { throw new InvalidOperationException("ReceiveAsync should be called just once."); } _receiveCallback = callback ?? throw new ArgumentNullException(nameof(callback)); _connection.ReceiveAsync(OnRawDataReceived); }
private void ConfigureTcpListener(ITcpConnection conn) { Framer.RegisterMessageArrivedCallback(TcpMessageArrived); Action <ITcpConnection, IEnumerable <ArraySegment <byte> > > callback = null; callback = (x, data) => { try { Framer.UnFrameData(data); } catch (PackageFramingException exc) { Log.ErrorException(exc, "LengthPrefixMessageFramer.UnFrameData() threw an exception:"); // SendBadRequestAndClose(Guid.Empty, string.Format("Invalid TCP frame received. Error: {0}.", exc.Message)); return; } conn.ReceiveAsync(callback); }; conn.ReceiveAsync(callback); }
private void OnRawDataReceived(ITcpConnection connection, IEnumerable <ArraySegment <byte> > data) { try { _framer.UnFrameData(data); } catch (PackageFramingException exc) { Log.InfoException(exc, "Invalid TCP frame received."); Close("Invalid TCP frame received."); return; } connection.ReceiveAsync(OnRawDataReceived); }
private void OnRawDataReceived(ITcpConnection connection, IEnumerable<ArraySegment<byte>> data) { try { _framer.UnFrameData(data); } catch (PackageFramingException exc) { Console.WriteLine(exc.Message); return; } connection.ReceiveAsync(OnRawDataReceived); }
private void OnRawDataReceived(ITcpConnection connection, IEnumerable <ArraySegment <byte> > data) { try { _messageFramer.UnFrameData(data); } catch (PackageFramingException ex) { _logger.Error("Unframe data has exception.", ex); return; } connection.ReceiveAsync(OnRawDataReceived); }
private void OnRawDataReceived(ITcpConnection connection, IEnumerable <ArraySegment <byte> > data) { try { _framer.UnFrameData(data); } catch (PackageFramingException exc) { _log.Error(exc, "TcpPackageConnection: [{0}, L{1}, {2:B}]. Invalid TCP frame received.", RemoteEndPoint, LocalEndPoint, ConnectionId); Close("Invalid TCP frame received."); return; } //NOTE: important to be the last statement in the callback connection.ReceiveAsync(OnRawDataReceived); }
private void OnDataReceived(ITcpConnection conn, IEnumerable<ArraySegment<byte>> data) { IMessageFramer framer; Tuple<ITcpConnection, IMessageFramer> pair; if (!_clientFramers.TryGetValue(conn.ConnectionId, out pair)) { framer = new CrappyTemporaryFramer(); framer.RegisterMessageArrivedCallback(CompleteMessageArrived); _clientFramers.TryAdd(conn.ConnectionId, new Tuple<ITcpConnection, IMessageFramer>(conn, framer)); //Note: we stick the connection ID in the first part of the message just so we // can find it later. This isn't especially nice and is fixed in real code var connectionId = conn.ConnectionId.ToByteArray(); framer.UnFrameData(new ArraySegment<byte>(connectionId, 0, connectionId.Length)); } else { framer = pair.Item2; } framer.UnFrameData(data); conn.ReceiveAsync(OnDataReceived); }
private void OnDataReceived(ITcpConnection conn, IEnumerable <ArraySegment <byte> > data) { IMessageFramer framer; Tuple <ITcpConnection, IMessageFramer> pair; if (!_clientFramers.TryGetValue(conn.ConnectionId, out pair)) { framer = new CrappyTemporaryFramer(); framer.RegisterMessageArrivedCallback(CompleteMessageArrived); _clientFramers.TryAdd(conn.ConnectionId, new Tuple <ITcpConnection, IMessageFramer>(conn, framer)); //Note: we stick the connection ID in the first part of the message just so we // can find it later. This isn't especially nice and is fixed in real code var connectionId = conn.ConnectionId.ToByteArray(); framer.UnFrameData(new ArraySegment <byte>(connectionId, 0, connectionId.Length)); } else { framer = pair.Item2; } framer.UnFrameData(data); conn.ReceiveAsync(OnDataReceived); }
private void OnDataReceived(ITcpConnection conn, IEnumerable <ArraySegment <byte> > data) { conn.EnqueueSend(data); conn.ReceiveAsync(OnDataReceived); }
public void Start(int connectTimeoutMilliseconds = 5000) { _connection = new TcpClientConnector().ConnectTo(Guid.NewGuid(), _localEndPoint, _serverEndPoint, OnConnectionEstablished, OnConnectionFailed); _connection.ConnectionClosed += OnConnectionClosed; _connection.ReceiveAsync(OnRawDataReceived); _waitHandle.WaitOne(connectTimeoutMilliseconds); }
public void ReconnectToServer() { _connection.ConnectionClosed -= OnConnectionClosed; _connection = new TcpClientConnector().ConnectTo(Guid.NewGuid(), _localEndPoint, _serverEndPoint, OnConnectionEstablished, OnConnectionFailed); _connection.ConnectionClosed += OnConnectionClosed; _connection.ReceiveAsync(OnRawDataReceived); }
private void OnDataReceived(ITcpConnection conn, IEnumerable<ArraySegment<byte>> data) { conn.EnqueueSend(data); conn.ReceiveAsync(OnDataReceived); }
private void OnRawDataReceived(ITcpConnection connection, IEnumerable<ArraySegment<byte>> data) { _framer.UnFrameData(data); connection.ReceiveAsync(OnRawDataReceived); }
private void OnRawDataReceived(ITcpConnection connection, IEnumerable<ArraySegment<byte>> data) { try { _framer.UnFrameData(data); } catch (PackageFramingException exc) { Log.Debug(exc, "Invalid TCP frame received."); Close(); return; } connection.ReceiveAsync(OnRawDataReceived); }
public void StartReceiving() { _tcpConnection.ReceiveAsync(OnRawDataReceived); }
private void OnRawDataReceived(ITcpConnection connection, IEnumerable <ArraySegment <byte> > data) { _framer.UnFrameData(data); connection.ReceiveAsync(OnRawDataReceived); }
private void OnRawDataReceived(ITcpConnection connection, IEnumerable<ArraySegment<byte>> data) { try { _framer.UnFrameData(data); } catch (PackageFramingException exc) { _log.Error(exc, "Invalid TCP frame received."); Close("Invalid TCP frame received."); return; } //NOTE: important to be the last statement in the callback connection.ReceiveAsync(OnRawDataReceived); }
private void ClientReceiveCallback(ITcpConnection tcpConnection, IEnumerable<ArraySegment<byte>> arraySegments) { tcpConnection.ReceiveAsync(ClientReceiveCallback); ReceiveAndSend(tcpConnection, arraySegments); }
private void OnRawDataReceived(ITcpConnection connection, IEnumerable<ArraySegment<byte>> data) { try { _framer.UnFrameData(data); } catch (PackageFramingException ex) { _logger.Error("UnFrame data has exception.", ex); return; } connection.ReceiveAsync(OnRawDataReceived); }