Exemple #1
0
 /**
  *
  * @Title: shutdown
  * @Description: 关闭连接
  * @param @throws IOException    参数
  * @return void    返回类型
  */
 public void shutdownNow()
 {
     //如果客户端已经就绪并且激活(数据交互)
     if (clientSession.IsReady && clientSession.IsActive == true)
     {
         //发送多次关闭信息
         Shutdown shutdown = new Shutdown();
         shutdown.DestinationID = clientSession.Destination.SocketID;
         shutdown.SetSession(clientSession);
         try
         {
             clientEndpoint.DoSend(shutdown);
             //  TimeUnit.MILLISECONDS.sleep(100);
         }
         catch (Exception e)
         {
             //logger.log(Level.SEVERE, "ERROR: Connection could not be stopped!", e);
         }
         clientSession.Socket.GetReceiver().Stop();
         clientEndpoint.Stop();
         //cd 添加  客户端一旦关闭就无效了,可以不移除,该对象关闭则不能使用了
         clientEndpoint.RemoveSession(clientSession.SocketID);
         //关闭发送
         clientSession.Socket.GetSender().Stop();
         closed = true;
     }
     clientEndpoint.Stop();
 }
Exemple #2
0
        /**
         * handle the connection handshake:<br/>
         * <ul>
         * <li>set initial sequence number</li>
         * <li>send response handshake</li>
         * </ul>
         * @param handshake
         * @param peer
         * @throws IOException
         */
        protected void HandleHandShake(ConnectionHandshake handshake)
        {
            ConnectionHandshake responseHandshake = new ConnectionHandshake();
            //compare the packet size and choose minimun
            long clientBufferSize      = handshake.PacketSize;
            long myBufferSize          = datagramSize;
            long bufferSize            = Math.Min(clientBufferSize, myBufferSize);
            long initialSequenceNumber = handshake.InitialSeqNo;

            this.initialSequenceNumber = initialSequenceNumber;
            this.DatagramSize          = (int)bufferSize;
            // setDatagramSize((int) bufferSize);
            responseHandshake.PacketSize     = bufferSize;
            responseHandshake.UdtVersion     = 4;
            responseHandshake.InitialSeqNo   = initialSequenceNumber;
            responseHandshake.ConnectionType = -1;
            responseHandshake.MaxFlowWndSize = handshake.MaxFlowWndSize;
            //tell peer what the socket ID on this side is
            responseHandshake.SocketID      = mySocketID;
            responseHandshake.DestinationID = this.destination.SocketID;
            //cd 2018-08-28
            if (this.cookie == 0)
            {
                this.cookie = CreateCookie();
            }
            responseHandshake.Cookie = cookie;

            responseHandshake.SetSession(this);
            FlashLogger.Info("Sending reply " + responseHandshake);
            endPoint.DoSend(responseHandshake);
        }
Exemple #3
0
        //handshake for connect
        protected void SendHandShake()
        {
            ConnectionHandshake handshake = new ConnectionHandshake();

            handshake.ConnectionType = ConnectionHandshake.CONNECTION_TYPE_REGULAR;
            handshake.SocketType     = ConnectionHandshake.SOCKET_TYPE_DGRAM;
            long initialSequenceNo = SequenceNumber.Random();

            initialSequenceNumber    = initialSequenceNo;
            handshake.InitialSeqNo   = initialSequenceNo;
            handshake.PacketSize     = datagramSize;
            handshake.SocketID       = mySocketID;
            handshake.MaxFlowWndSize = flowWindowSize;
            //cd 2018-08-28
            handshake.SetPeerIP(this.endPoint.GetLocalAddress().Address.ToString());
            handshake.SetSession(this);
            FlashLogger.Info("Sending " + handshake);
            endPoint.DoSend(handshake);
            connectNum++;
        }
Exemple #4
0
 /**
  * sends the given data packet, storing the relevant information
  *
  * @param data
  * @throws IOException
  * @throws InterruptedException
  */
 private void Send(DataPacket p)
 {
     lock (sendLock){
         if (storeStatistics)
         {
             dgSendInterval.End();
             dgSendTime.Begin();
         }
         endpoint.DoSend(p);
         if (storeStatistics)
         {
             dgSendTime.End();
             dgSendInterval.Begin();
             throughput.End();
             throughput.Begin();
         }
         sendBuffer[p.GetPacketSequenceNumber()] = p;
         Interlocked.Increment(ref unacknowledged);
     }
     statistics.incNumberOfSentDataPackets();
 }
Exemple #5
0
        /**
         * write a NAK triggered by a received sequence number that is larger than
         * the largestReceivedSeqNumber + 1
         * @param currentSequenceNumber - the currently received sequence number
         * @throws IOException
         */
        protected void SendNAK(long currentSequenceNumber)
        {
            NegativeAcknowledgement nAckPacket = new NegativeAcknowledgement();

            nAckPacket.AddLossInfo(largestReceivedSeqNumber + 1, currentSequenceNumber);
            nAckPacket.SetSession(session);
            nAckPacket.DestinationID = session.Destination.SocketID;
            //put all the sequence numbers between (but excluding) these two values into the
            //receiver loss list
            for (long i = largestReceivedSeqNumber + 1; i < currentSequenceNumber; i++)
            {
                ReceiverLossListEntry detectedLossSeqNumber = new ReceiverLossListEntry(i);
                receiverLossList.Insert(detectedLossSeqNumber);
            }
            endpoint.DoSend(nAckPacket);
            //logger.info("NAK for "+currentSequenceNumber);
            statistics.incNumberOfNAKSent();
        }