/// <summary> /// process EXP event (see spec. p 13) /// </summary> protected void processEXPEvent() { try { if (session.getSocket() == null) { return; } UDTSender sender = session.getSocket().getSender(); //put all the unacknowledged packets in the senders loss list sender.putUnacknowledgedPacketsIntoLossList(); if (expCount > 16 && (long)ts.TotalMilliseconds - sessionUpSince > IDLE_TIMEOUT) { if (!connectionExpiryDisabled && !stopped) { sendShutdown(); stop(); Log.Write(this.ToString(), "Session " + session + " expired."); return; } } if (!sender.haveLostPackets()) { sendKeepAlive(); } expCount++; } catch (Exception exc) { Log.Write(this.ToString(), exc); } }
public UDTSocket Accept() { try { if (!started) { this.endpoint.start(true);//启动监听 this.started = true; } while (!shutdown) { UDTSession session = endpoint.accept(); if (session != null) { //等待握手完成 while (!session.isReady() || session.getSocket() == null) { Thread.Sleep(100); } return(session.getSocket()); } Thread.Sleep(400); } return(null); } catch (Exception exc) { Log.Write(this.ToString(), "listens and blocks until a new client connects and returns a valid {@link UDTSocket} for the new connection", exc); return(null); } }
/// <summary> /// receive a packet from server from the peer /// 从对等服务器接收数据包 /// </summary> /// <param name="p"></param> public void receive(UDTPacket p) { try { if (p is Acknowledgement) { Acknowledgement acknowledgement = (Acknowledgement)p; onAcknowledge(acknowledgement); } else if (p is NegativeAcknowledgement) { NegativeAcknowledgement nak = (NegativeAcknowledgement)p; onNAKPacketReceived(nak); } else if (p is KeepAlive) { session.getSocket().getReceiver().resetEXPCount(); } else if (p is DataPacket) { ////返回的确认数据包 ////DataPacketAnswer Answer = (DataPacketAnswer)p; //if (largestSentSequenceNumber == (int)p.getPacketSequenceNumber()) //{ // sendQueueStart.CountDown(); //} } } catch (Exception ex) { Log.Write(this.ToString(), ex); } }
public void setAckInterval(long ackInterval) { this.ackInterval = ackInterval; if (session.getSocket() != null && session.getSocket().getReceiver() != null) { session.getSocket().getReceiver().setAckInterval(ackInterval); } }