how i can use my ip address in this programm? if i put my address instead 127.0.0.1 the server not responce
<p>My problem in line: </p>

<pre><code>server.sin_addr.s_addr = inet_addr("127.0.0.1");
</code></pre>

<p>in client path. If i put my address instead 127.0.0.1 the server is not response.
I need to see the traffic in this program with wireshark packet sniffer... </p>

<pre><code> //Client   

#define TIME_PORT 27015
#define NUM_OF_REQUEST 5
#define SIZE 10
int getRequestFromUser();
float calculateAverage(int* arr);

void main() 
{
 //allocating memory to get the needed information from user 


    // Initialize Winsock (Windows Sockets).

 WSAData wsaData; 
 if (NO_ERROR != WSAStartup(MAKEWORD(2,2), &amp;wsaData))
 {
  cout&lt;&lt;"Time Client: Error at WSAStartup()\n";
 }

 // Client side:
 // Create a socket and connect to an internet address.

    SOCKET connSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
 if (INVALID_SOCKET == connSocket)
 {
        cout&lt;&lt;"Time Client: Error at socket(): "&lt;&lt;WSAGetLastError()&lt;&lt;endl;
        WSACleanup();
        return;
 }

 // For a client to communicate on a network, it must connect to a server.

 // Need to assemble the required data for connection in sockaddr structure.

    // Create a sockaddr_in object called server. 
 sockaddr_in server;
    server.sin_family = AF_INET; 
 server.sin_addr.s_addr = inet_addr("127.0.0.1");
 server.sin_port = htons(TIME_PORT);

    // Send and receive data.

    int bytesSent = 0;
    int bytesRecv = 0;
 char sendBuff[255];
 char recvBuff[255];
 int requestFromUser = -1;

 while(requestFromUser != 0){

 requestFromUser=getRequestFromUser();
 // for mmeasure RTT/Delay
 float average=0;
 bool findDelay=false;
 bool findRTT=false;

 //matching between numbers and what they mean:
 switch (requestFromUser)
 {
 case 1:
  strcpy(sendBuff,"GetTime");
  break;
 case 2:
  strcpy(sendBuff,"GetTimeWithoutYear");
  break;
 case 3:
  strcpy(sendBuff,"GetTimeSinceEpoch");
  break;
 case 4:
  {
  strcpy(sendBuff,"GetClientToServerDelayEstimation");
  findDelay=true;
  break;
  }
 case 5:
  {
  strcpy(sendBuff,"MeasureRTT");
  findRTT=true;
  break;
  }
 case 6:
  {
   strcpy(sendBuff, "GetDayAndMonth");
   break;
  }
 default:
  ;//don't exist
 }

 // Asks the server what's the currnet time.
 // The send function sends data on a connected socket.
 // The buffer to be sent and its size are needed.
 // The fourth argument is an idicator specifying the way in which the call is made (0 for default).
 // The two last arguments hold the details of the server to communicate with. 
 // NOTE: the last argument should always be the actual size of the client's data-structure (i.e. sizeof(sockaddr)).

 if (findDelay)
 {
  int i;
  long int arrTimeR[SIZE];
  int arrTime[SIZE];
  time_t  arrTimeSend[SIZE];
  //Start sending the request
  strcpy(sendBuff,"GetTimeSinceEpoch");
  for (i=0; i&lt;SIZE; i++)
  {

   //sending request
   bytesSent = sendto(connSocket, sendBuff, (int)strlen(sendBuff), 0, (const sockaddr *)&amp;server, sizeof(server));
   arrTimeSend[i]= time (NULL);
   if (SOCKET_ERROR == bytesSent)
   {
    cout&lt;&lt;"Time Client: Error at sendto(): "&lt;&lt;WSAGetLastError()&lt;&lt;endl;
    closesocket(connSocket);
    WSACleanup();
    return;
   }

   //recieving data
   bytesRecv = recv(connSocket, recvBuff, 255, 0);

   if (SOCKET_ERROR == bytesRecv)
   {
    cout&lt;&lt;"Time Client: Error at recv(): "&lt;&lt;WSAGetLastError()&lt;&lt;endl;
    closesocket(connSocket);
    WSACleanup();
    return;
   }
   recvBuff[bytesRecv]='\0';
   arrTime[i]=atoi(recvBuff)-(arrTimeSend[i]);

  }//for 
  average=calculateAverage(arrTime);
  cout&lt;&lt; "The average Delay between Client to Server is "&lt;&lt;average&lt;&lt;" in seconds\n";

 }//findDelay

 if (findRTT)
 {
  int i;
  time_t timerD;
  time_t arrTimeSend[SIZE];
  int arrTime[SIZE];
  strcpy(sendBuff,"GetTime"); 

  for (i=0; i&lt;SIZE; i++)
  {

   //getting time of sending I'm including all operations for sending the request to the server

   arrTimeSend[i]=time (NULL);
   //sending request
   bytesSent = sendto(connSocket, sendBuff, (int)strlen(sendBuff), 0, (const sockaddr *)&amp;server, sizeof(server));

   if (SOCKET_ERROR == bytesSent)
   {
    cout&lt;&lt;"Time Client: Error at sendto(): "&lt;&lt;WSAGetLastError()&lt;&lt;endl;
    closesocket(connSocket);
    WSACleanup();
    return;
   }
  }//for sending
  for (i=0; i&lt;SIZE; i++)
  {
   //recieving data
   bytesRecv = recv(connSocket, recvBuff, 255, 0);

   //getting time of recieving
   timerD = time (NULL);

   if (SOCKET_ERROR == bytesRecv)
   {
    cout&lt;&lt;"Time Client: Error at recv(): "&lt;&lt;WSAGetLastError()&lt;&lt;endl;
    closesocket(connSocket);
    WSACleanup();
    return;
   }

   recvBuff[bytesRecv]='\0';//not needed for calculation , but for future use
   arrTime[i]=difftime(timerD,arrTimeSend[i]);
  }//for receving
  average=calculateAverage(arrTime);
  cout&lt;&lt; "The average RTT time is "&lt;&lt;average&lt;&lt;" in seconds\n";
 }//findRTT
 if (!findRTT &amp;&amp; !findDelay)
 {
  bytesSent = sendto(connSocket, sendBuff, (int)strlen(sendBuff), 0, (const sockaddr *)&amp;server, sizeof(server));
  if (SOCKET_ERROR == bytesSent)
  {
   cout&lt;&lt;"Time Client: Error at sendto(): "&lt;&lt;WSAGetLastError()&lt;&lt;endl;
   closesocket(connSocket);
   WSACleanup();
   return;
  }
  cout&lt;&lt;"Time Client: Sent: "&lt;&lt;bytesSent&lt;&lt;"/"&lt;&lt;strlen(sendBuff)&lt;&lt;" bytes of \""&lt;&lt;sendBuff&lt;&lt;"\" message.\n";

  // Gets the server's answer using simple recieve (no need to hold the server's address).
  bytesRecv = recv(connSocket, recvBuff, 255, 0);
  if (SOCKET_ERROR == bytesRecv)
  {
   cout&lt;&lt;"Time Client: Error at recv(): "&lt;&lt;WSAGetLastError()&lt;&lt;endl;
   closesocket(connSocket);
   WSACleanup();
   return;
  }

  recvBuff[bytesRecv]='\0'; //add the null-terminating to make it a string
  cout&lt;&lt;"Time Client: Recieved: "&lt;&lt;bytesRecv&lt;&lt;" bytes of \""&lt;&lt;recvBuff&lt;&lt;"\" message.\n";
 }//(!findRTT &amp;&amp; !findDelay) 
}//End of while
  // Closing connections and Winsock.
  cout&lt;&lt;"Time Client: Closing Connection.\n";
  closesocket(connSocket);

  //free the allocating memory 

}//main

//==================
int getRequestFromUser()
{ 
 int num=0; 
 //int index=0;
 //char c;
 cout&lt;&lt;"Choose the information that you intrested in:"&lt;&lt;endl;
 cout&lt;&lt;"(1) - Get time"&lt;&lt;endl;
 cout&lt;&lt;"(2) - Get time without Year"&lt;&lt;endl;
 cout&lt;&lt;"(3) - Get time since epoch - meanning since 1.1.1970"&lt;&lt;endl;
 cout&lt;&lt;"(4) - Get dilay time "&lt;&lt;endl;
 cout&lt;&lt;"(5) - measuring RTT - round trip time"&lt;&lt;endl;
 cout&lt;&lt;"(6) - Get day and month"&lt;&lt;endl;
 cout&lt;&lt;"(0) - Exit"&lt;&lt;endl;

 cin&gt;&gt;num;

 return num;

}
float calculateAverage(int* arr)
{
 int sum=0,i;
 for (i=0; i&lt;SIZE; i++)
  sum+=arr[i];

 return sum/SIZE;
}


//Server

#include &lt;iostream&gt;
using namespace std;
#include &lt;winsock2.h&gt;
#include &lt;string.h&gt;
#include &lt;time.h&gt;
#include &lt;iomanip&gt;


#define TIME_PORT 27015

void main() 
{
    // Initialize Winsock (Windows Sockets).
 // Create a WSADATA object called wsaData.
    // The WSADATA structure contains information about the Windows 
 // Sockets implementation.

 WSAData wsaData; 

 // Call WSAStartup and return its value as an integer and check for errors.
 // The WSAStartup function initiates the use of WS2_32.DLL by a process.
 // First parameter is the version number 2.2.
 // The WSACleanup function destructs the use of WS2_32.DLL by a process.

 if (NO_ERROR != WSAStartup(MAKEWORD(2,2), &amp;wsaData))
 {
        cout&lt;&lt;"Time Server: Error at WSAStartup()\n";
 }

 // Server side:
 // Create and bind a socket to an internet address.
    // After initialization, a SOCKET object is ready to be instantiated.
 // Create a SOCKET object called m_socket. 
 // For this application: use the Internet address family (AF_INET), 
 //       datagram sockets (SOCK_DGRAM), 
 //       and the UDP/IP protocol (IPPROTO_UDP).

    SOCKET m_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);

 // Check for errors to ensure that the socket is a valid socket.
 // Error detection is a key part of successful networking code. 
 // If the socket call fails, it returns INVALID_SOCKET. 
 // The "if" statement is used to catch any errors that
 // may have occurred while creating the socket. WSAGetLastError returns an 
 // error number associated with the last error that occurred.

 if (INVALID_SOCKET == m_socket)
 {
        cout&lt;&lt;"Time Server: Error at socket(): "&lt;&lt;WSAGetLastError()&lt;&lt;endl;
        WSACleanup();
        return;
 }

 // For a server to communicate on a network, it must first bind the socket to 
 // a network address.
 // Need to assemble the required data for connection in sockaddr structure.

    // Create a sockaddr_in object called serverService. 

 sockaddr_in serverService;

 // Address family (must be AF_INET - Internet address family).

    serverService.sin_family = AF_INET; 

 // IP address. The sin_addr is a union (s_addr is a unsigdned long (4 bytes) data type).
 // INADDR_ANY means to listen on all interfaces.
 // inet_addr (Internet address) is used to convert a string (char *) into unsigned int.
 // inet_ntoa (Internet address) is the reverse function (converts unsigned int to char *)
 // The IP address 127.0.0.1 is the host itself, it's actually a loop-back.

 serverService.sin_addr.s_addr = INADDR_ANY; //inet_addr("127.0.0.1");

 // IP Port. The htons (host to network - short) function converts an
 // unsigned short from host to TCP/IP network byte order (which is big-endian).

 serverService.sin_port = htons(TIME_PORT);

 // Bind the socket for client's requests.
    // The bind function establishes a connection to a specified socket.
 // The function uses the socket handler, the sockaddr structure (which
 // defines properties of the desired connection) and the length of the
 // sockaddr structure (in bytes).

    if (SOCKET_ERROR == bind(m_socket, (SOCKADDR *) &amp;serverService, sizeof(serverService))) 
 {
  cout&lt;&lt;"Time Server: Error at bind(): "&lt;&lt;WSAGetLastError()&lt;&lt;endl;
        closesocket(m_socket);
  WSACleanup();
        return;
    }

    // Waits for incoming requests from clients.
    // Send and receive data.

 sockaddr client_addr;
 int client_addr_len = sizeof(client_addr);
 int bytesSent = 0;
    int bytesRecv = 0;
 char sendBuff[255];
 char recvBuff[255];

 // Get client's requests and answer them.
 // The recvfrom function receives a datagram and stores the source address.
 // The buffer for data to be received and its available size are 
 // returned by recvfrom. The fourth argument is an idicator 
 // specifying the way in which the call is made (0 for default).
 // The two last arguments are optional and will hold the details of the client for further communication. 
 // NOTE: the last argument should always be the actual size of the client's data-structure (i.e. sizeof(sockaddr)).

 cout&lt;&lt;"Time Server: Wait for clients' requests.\n"; 

 while(true)
 {
  bytesRecv = recvfrom(m_socket, recvBuff, 255, 0, &amp;client_addr, &amp;client_addr_len);
  if (SOCKET_ERROR == bytesRecv)
  {
   cout&lt;&lt;"Time Server: Error at recvfrom(): "&lt;&lt;WSAGetLastError()&lt;&lt;endl;
   closesocket(m_socket);
   WSACleanup();
   return;
  }

  recvBuff[bytesRecv]='\0'; //add the null-terminating to make it a string

  cout&lt;&lt;"Time Server: Recieved: "&lt;&lt;bytesRecv&lt;&lt;" bytes of \""&lt;&lt;recvBuff&lt;&lt;"\" message.\n";

  time_t timer;
  time(&amp;timer);
  char date [10];
  char dayAndMonth [6];

  //1-GetTime
  if (strcmp(recvBuff,"GetTime")==0){
   strcpy(sendBuff, ctime(&amp;timer));
   sendBuff[strlen(sendBuff)-1] = 0;
  }

  //2-GetTimeWithoutYear
  else if (strcmp(recvBuff,"GetTimeWithoutYear")==0){
   struct tm * timeinfo = localtime(&amp;timer);
   strftime (sendBuff,255,"%X",timeinfo);
   sendBuff[strlen(sendBuff)] = 0;
  }

  //3-GetTimeSinceEpoch
  else if (strcmp(recvBuff,"GetTimeSinceEpoch")==0){ 
   timer = time (NULL);
   itoa(timer,sendBuff,10);//converting from int to srting 
   strcat (sendBuff," seconds.");
   sendBuff[strlen(sendBuff)] = 0;
  }
  //6 - GetDayAndMonth
  else if(strcmp(recvBuff, "GetDayAndMonth")==0)
  {
   _tzset;
   _strdate(date);
   strncpy(dayAndMonth, date, 5);
   dayAndMonth[5] = '\0';
   strcpy(sendBuff, dayAndMonth);
   sendBuff[strlen(sendBuff)] = 0;
  }

  // Sends the answer to the client, using the client address gathered
  // by recvfrom. 
  bytesSent = sendto(m_socket, sendBuff, (int)strlen(sendBuff), 0, (const sockaddr *)&amp;client_addr, client_addr_len);
  if (SOCKET_ERROR == bytesSent)
  {
   cout&lt;&lt;"Time Server: Error at sendto(): "&lt;&lt;WSAGetLastError()&lt;&lt;endl;
   closesocket(m_socket);
   WSACleanup();
   return;
  }

  cout&lt;&lt;"Time Server: Sent: "&lt;&lt;bytesSent&lt;&lt;"\\"&lt;&lt;strlen(sendBuff)&lt;&lt;" bytes of \""&lt;&lt;sendBuff&lt;&lt;"\" message.\n"; 
 }

 // Closing connections and Winsock.
 cout&lt;&lt;"Time Server: Closing Connection.\n";
 closesocket(m_socket);
 WSACleanup();
}
</code></pre>
