private void OnReceiveData(IAsyncResult iar) { try { IPEndPoint endPoint = null; var data = ((UdpClient)iar.AsyncState).EndReceive(iar, ref endPoint); if (!_connections.ContainsKey(endPoint)) { var connection = new UdpConnectionEntity((uint)_idProvider.GetId(), this, endPoint); _connections.Add(endPoint, connection); OnConnectionAdded(connection); } NetworkProtocol.ProcessParsing(_connections[endPoint], new BasicReader(data)); } catch (Exception ex) { if (ex is SocketException || ex is ObjectDisposedException) { return; } } if (IsInitialized) { _client.BeginReceive(new AsyncCallback(OnReceiveData), _client); } }
public void SendTo(UdpConnectionEntity connection, NetworkMessage message) { if (connection.IsDisposed) { throw new ObjectDisposedException(nameof(UdpConnectionEntity)); } SendTo(connection.EndPoint, NetworkProtocol.GetCurrentProtocol().OnSerializeMessage(message)); }
public void SendTo(UdpConnectionEntity connection, byte[] data) { if (connection.IsDisposed) { throw new ObjectDisposedException(nameof(UdpConnectionEntity)); } SendTo(connection.EndPoint, data); }
public virtual void OnConnectionAdded(UdpConnectionEntity connection) { }