1- using QuicNet . Infrastructure ;
1+ using QuicNet . Context ;
2+ using QuicNet . Infrastructure ;
23using QuicNet . Infrastructure . Packets ;
34using System ;
45using System . Collections . Generic ;
@@ -13,43 +14,57 @@ namespace QuicNet
1314 public class QuicListener
1415 {
1516 private UdpClient _client ;
16- private IPEndPoint _endPoint ;
1717
1818 private Unpacker _unpacker ;
1919 private PacketCreator _packetCreator ;
2020 private Dispatcher _dispatcher ;
2121
22+ private int _port ;
23+ private bool _started ;
24+
25+ public event Action < QuicContext > OnDataReceived ;
26+
2227 public QuicListener ( int port )
2328 {
24- _endPoint = new IPEndPoint ( IPAddress . Any , port ) ;
25- _client = new UdpClient ( port ) ;
29+ _started = false ;
30+ _port = port ;
31+
2632 _unpacker = new Unpacker ( ) ;
2733 _packetCreator = new PacketCreator ( ) ;
2834 _dispatcher = new Dispatcher ( _packetCreator ) ;
2935 }
3036
3137 public void Start ( )
3238 {
33- Receive ( ) ;
39+ _client = new UdpClient ( _port ) ;
40+ }
41+
42+ public void Close ( )
43+ {
44+ _client . Close ( ) ;
3445 }
3546
3647 public void Receive ( )
3748 {
38- byte [ ] data = _client . Receive ( ref _endPoint ) ;
49+ while ( true )
50+ {
51+ IPEndPoint endpoint = new IPEndPoint ( IPAddress . Any , _port ) ;
52+ byte [ ] data = _client . Receive ( ref endpoint ) ;
3953
40- Packet packet = _unpacker . Unpack ( data ) ;
54+ Packet packet = _unpacker . Unpack ( data ) ;
4155
42- // Discard unknown packets
43- if ( packet == null )
44- return ;
56+ // Discard unknown packets
57+ if ( packet == null )
58+ continue ;
4559
46- // TODO: Validate packet before dispatching
47- Packet result = _dispatcher . Dispatch ( packet ) ;
60+ // TODO: Validate packet before dispatching
61+ Packet result = _dispatcher . Dispatch ( packet ) ;
4862
49- // Send a response packet if the dispatcher has information for the peer.
50- if ( result != null )
51- {
52-
63+ // Send a response packet if the dispatcher has information for the peer. (1-RTT)
64+ if ( result != null )
65+ {
66+
67+ }
5368 }
5469 }
5570 }
0 commit comments