Esempio n. 1
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)
 {
     try
     {
         ConnectionHandshake responseHandshake = new ConnectionHandshake();
         //compare the packet size and choose minimun
         long clientBufferSize      = handshake.getPacketSize();
         long myBufferSize          = getDatagramSize();
         long bufferSize            = Math.Min(clientBufferSize, myBufferSize);
         long initialSequenceNumber = handshake.getInitialSeqNo();
         setInitialSequenceNumber(initialSequenceNumber);
         setDatagramSize((int)bufferSize);
         responseHandshake.setPacketSize(bufferSize);
         responseHandshake.setUdtVersion(4);
         responseHandshake.setInitialSeqNo(initialSequenceNumber);
         responseHandshake.setConnectionType(-1);
         responseHandshake.setMaxFlowWndSize(handshake.getMaxFlowWndSize());
         //tell peer what the socket ID on this side is
         responseHandshake.setSocketID(mySocketID);
         responseHandshake.setDestinationID(this.getDestination().getSocketID());
         responseHandshake.setSession(this);
         Log.Write(this.ToString(), "Sending reply " + responseHandshake);
         endPoint.doSend(responseHandshake);
     }
     catch (Exception exc)
     {
         Log.Write(this.ToString(), exc);
     }
 }
 /// <summary>
 /// 2nd handshake for connect
 /// </summary>
 /// <param name="hs"></param>
 protected void sendConfirmation(ConnectionHandshake hs)
 {
     try
     {
         ConnectionHandshake handshake = new ConnectionHandshake();
         handshake.setConnectionType(-1);
         handshake.setSocketType(ConnectionHandshake.SOCKET_TYPE_DGRAM);
         handshake.setInitialSeqNo(hs.getInitialSeqNo());
         handshake.setPacketSize(hs.getPacketSize());
         handshake.setSocketID(mySocketID);
         handshake.setMaxFlowWndSize(flowWindowSize);
         handshake.setSession(this);
         Log.Write(this.ToString(), "Sending confirmation " + handshake.toString());
         endPoint.doSend(handshake);
     }
     catch (Exception exc)
     {
         Log.Write(this.ToString(), exc);
     }
 }
 /// <summary>
 /// handshake for connect
 /// </summary>
 protected void sendHandShake()
 {
     try
     {
         ConnectionHandshake handshake = new ConnectionHandshake();
         handshake.setConnectionType(ConnectionHandshake.CONNECTION_TYPE_REGULAR);
         handshake.setSocketType(ConnectionHandshake.SOCKET_TYPE_DGRAM);
         long initialSequenceNo = SequenceNumber.random();
         setInitialSequenceNumber(initialSequenceNo);
         handshake.setInitialSeqNo(initialSequenceNo);
         handshake.setPacketSize(getDatagramSize());
         handshake.setSocketID(mySocketID);
         handshake.setMaxFlowWndSize(flowWindowSize);
         handshake.setSession(this);
         Log.Write(this.ToString(), "Sending " + handshake);
         endPoint.doSend(handshake);
     }
     catch (Exception exc)
     {
         Log.Write(this.ToString(), exc);
     }
 }