Last update: 10/2/2017

 

The solution posted for the HW1 program is https://people.cs.clemson.edu/~jmarty/courses/Fall-2017/CPSC360/homework/UDPEchoHW1Sol/

The client supports both modes of operation (RTT_MODE and CBR_MODE). The server is pretty close....you need to complete the server to support mode 1. The following items are worth noting;


Let's look at code in the server....(just excerpts shown)

 

Pay attention to how the session manager routines are used, .the use of the RxModePtr, the use of htons(), and how count of dropped and out of order packets is done.

 

unsigned int RxSeqNumber = 0;

int *RxSeqNumberPtr = (int *)echoBuffer; //$A2

unsigned short RxMode = 0;

unsigned short *RxModePtr = (unsigned short *)&echoBuffer[4];

session *mySession = NULL;

/* Block until receive message from a client */       
 recvMsgSize = recvfrom(sock, echoBuffer, ECHOMAX, 0, (struct sockaddr *) &echoClntAddr, &cliAddrLen);     
 
if (recvMsgSize < 0)       
 {          
   errorCount++;         
   continue;       
 }        

//Check if Session already exists        m
mySession = findSession(echoClntAddr.sin_addr, echoClntAddr.sin_port);         
if(mySession == NULL) // If not added already, create a session       
 {          
    mySession = createSession(echoClntAddr.sin_addr, echoClntAddr.sin_port);       
 }  
         
 //Tracks total number received from any client        
receivedCount++;          
RxSeqNumber = (unsigned int)ntohl( (unsigned int)(*RxSeqNumberPtr) );    
   
 //two cases, arrival is a 'new' segment          
if (mySession->largestSeqNumRxed  < RxSeqNumber)          
mySession->largestSeqNumRxed = RxSeqNumber;          //the arrival is an 'old' segment         
if (mySession->largestSeqNumRxed >= RxSeqNumber)          
mySession->outOfOrderArrivals++;            

mySession->lastSeqNumRxed = RxSeqNumber;          

RxMode = (unsigned short )ntohs( (unsigned short )(*RxModePtr));   
mySession->mode = RxMode;

 

The client, pay attention to:

 

int myDelay(double delayTime) {
    
 int rc = SUCCESS;      
 int64_t ns = (int64_t) (delayTime * 1000000000);   
 //  printf("myDelay:  delayTime:%f   %ld \n",delayTime, ns);      
 rc = delay(ns);    
 return rc;  
}
  
int  delay(int64_t ns)  { 
     
 struct timespec req, rem;        
 req.tv_sec = 0;        

 while (ns >= 1000000000L) {          
   ns -= 1000000000L;          
    req.tv_sec += 1;      
 }        

 req.tv_nsec = ns;        
 while (nanosleep(&req, &rem) == -1)          
    if (EINTR == errno)              
      memcpy(&req, &rem, sizeof(rem));         
     else              
      return -1;  
    
return 0; 

}