public TCPConnection(Socket socket, bool verbose, ProcessLine processLine, Disconected onDisconnect) { Socket = socket; Verbose = verbose; OnProcessLine = processLine; OnDisconnect = onDisconnect; NotifyOnDisconnect = true; BeginReceive(); }
public TCPConnection(string server, int portNbr, int reconnectInterval, int maxConnectionAttempts, Disconected onDisconnect, bool verbose) { Server = server; PortNbr = portNbr; Verbose = verbose; ReconnectInterval = reconnectInterval; ConnectionAttemptsLeft = maxConnectionAttempts; }
protected override void OnScheduledUpdate() { base.OnScheduledUpdate(); if (!IsHaveInternet()) { Disconected.SafeRaise(); Terminate(); } }
private void OnDisconect(NetworkMessage msg) { Disconected.SafeRaise(); }
private void InputStreamDataReceived(IAsyncResult ar) { try { var curDataLength = _inputStream.EndRead(ar); if (curDataLength == 0) { // Input stream closed Disconected?.BeginInvoke(this, EventArgs.Empty, (iar) => { }, null); return; } _readedDataLength += curDataLength; } catch (IOException ex) when(ex.HResult == -2146232800) { // Input stream closed Disconected?.BeginInvoke(this, EventArgs.Empty, (iar) => { }, null); return; } if (_readedDataLength == _dataLength.Length) { var dataSize = _maxSize == PackedStreamMaxSize.LengthMax_1Bytes ? _dataLength[0] : _maxSize == PackedStreamMaxSize.LengthMax_2Bytes ? BitConverter.ToUInt16(_dataLength, 0) : _maxSize == PackedStreamMaxSize.LengthMax_4Bytes ? BitConverter.ToUInt32(_dataLength, 0) : _maxSize == PackedStreamMaxSize.LengthMax_8Bytes ? BitConverter.ToInt64(_dataLength, 0) : throw new NotImplementedException(); var mms = new MemoryStream(); var buf = new byte[INT_BUFFER_SIZE]; int readed; var toRead = dataSize; while (toRead > 0) { readed = _inputStream.Read(buf, 0, toRead < INT_BUFFER_SIZE ? (int)toRead : INT_BUFFER_SIZE); toRead -= readed; mms.Write(buf, 0, readed); } // Read next pack _readedDataLength = 0; RequestPackSize(); // Fire new pack event mms.Position = 0; DataReceived?.BeginInvoke(this, new PackedStreamDataEventArgs(mms), (iar) => { mms.Dispose(); }, null); } else if (_readedDataLength < _dataLength.Length) { RequestPackSize(); } else { throw new InvalidDataException(); } }
public void OnPeerDisconnected(NetPeer peer, DisconnectInfo disconnectInfo) { Disconected?.Invoke(this, EventArgs.Empty); }
private void OnDisconect(NetworkMessage msg) { Disconected.SafeRaise(msg.conn.connectionId); }