/// <summary> /// Blocks and waits for incomming connection. Does NOT block additional incomming packets. /// </summary> /// <returns>Returns an instance of QuicConnection.</returns> public QuicConnection AcceptQuicClient() { if (!_started) { throw new QuicListenerNotStartedException("Please call the Start() method before receving data."); } // Wait until there is initial packet incomming. // Otherwise we still need to orchestrate any other protocol or data pakcets. while (true) { var packet = _pwt.ReadPacket(); if (packet is InitialPacket) { var connection = ProcessInitialPacket(packet, _pwt.LastTransferEndpoint()); return(connection); } OrchestratePacket(packet); } }
/// <summary> /// Starts the listener. /// </summary> public void Start() { _client = new UdpClient(_port); _started = true; _pwt = new PacketWireTransfer(_client, null); while (true) { Packet packet = _pwt.ReadPacket(); if (packet is InitialPacket) { QuicConnection connection = ProcessInitialPacket(packet, _pwt.LastTransferEndpoint()); OnClientConnected?.Invoke(connection); } if (packet is ShortHeaderPacket) { ProcessShortHeaderPacket(packet); } } }