コード例 #1
0
 public BlockingSCTPStream(Association a, int id) : base(a, id)
 {
 }
コード例 #2
0
        void startRcv()
        {
            Association me = this;

            _rcv = new Thread(() =>
            {
                try
                {
                    byte[] buf = new byte[_transp.GetReceiveLimit()];
                    while (_rcv != null)
                    {
                        try
                        {
                            var length = _transp.Receive(buf, 0, buf.Length, TICK);
                            if (length > 0)
                            {
                                //var b = Packet.getHex(buf, 0, length);
                                //logger.LogInformation($"DTLS message recieved\n{b}");
                                ByteBuffer pbb = new ByteBuffer(buf);
                                pbb.Limit      = length;
                                Packet rec     = new Packet(pbb);
                                deal(rec);
                            }
                            else if (length == DtlsSrtpTransport.DTLS_RECEIVE_ERROR_CODE)
                            {
                                // The DTLS transport has been closed or i no longer available.
                                break;
                            }
                            else
                            {
                                logger.LogInformation("Timeout -> short packet " + length);
                            }
                        }
                        catch (SocketException e)
                        {
                            // ignore. it should be a timeout.
                            switch (e.SocketErrorCode)
                            {
                            case SocketError.TimedOut:
                                logger.LogDebug("tick time out");
                                break;

                            default:
                                throw e;
                            }
                        }
                    }
                    logger.LogDebug("SCTP message receive was empty, closing association listener.");

                    _transp.Close();
                }
                catch (EndOfStreamException eof)
                {
                    unexpectedClose(eof);
                    logger.LogDebug(eof.ToString());
                }
                catch (Exception ex)
                {
                    logger.LogDebug("Association receive failed " + ex.GetType().Name + " " + ex.ToString());
                }
            });
            _rcv.Priority = ThreadPriority.Highest;
            _rcv.Name     = "AssocRcv" + __assocNo;
            _rcv.Start();
        }