title: Running UDP client and server in different machines
body: <p>I have a UDP client and a server running fine when run on the same computer. (Here for the client i have given <strong>127.0.0.1</strong> as the destination IP on the UDP client).</p>
  
  <p>However when run on different machines, and replacing <strong>127.0.0.1</strong> with my the ip of the machine where server.c is present, the program doesnt work. The problem is i'm not getting any error message.</p>
  
  <p>Below is the code for server and client. Please tell me any modifications to be performed to run the same over different machines(I'm using LINUX OS).</p>
  
  <p>Note: My machines <strong>serverIP</strong>(machine where server.c is present): <strong>10.60.5.945</strong>, 
  <strong>clientIP: 10.60.5.950</strong></p>
  
  <p>server.c:</p>
  
  <pre><code>#include&lt;sys/types.h&gt;
  #include&lt;sys/socket.h&gt;
  #include&lt;netinet/in.h&gt;
  #include&lt;sys/stat.h&gt;
  #include&lt;unistd.h&gt;
  #include&lt;stdlib.h&gt;
  #include&lt;stdio.h&gt;
  #include&lt;fcntl.h&gt;
  int main()
  {
      int cont,create_socket,new_socket,addrlen,fd;
      int bufsize = 1024; 
      int nameLen=0;
      int client_address_size=0;
      char *buffer = malloc(10);
      char fname[256];
      struct sockaddr_in address,client;
  
      if ((create_socket = socket(AF_INET,SOCK_DGRAM,0)) &gt; 0)
      printf("The socket was created\n");
  
      address.sin_family = AF_INET;
      address.sin_addr.s_addr = INADDR_ANY;
  
      address.sin_port = htons(15000);
  
      if (bind(create_socket,(struct sockaddr *)&amp;address,sizeof(address))== 0)
          printf("Binding Socket\n");
  
      nameLen=sizeof(address);
  
      if (getsockname(create_socket,(struct sockaddr *)&amp;address,&amp;nameLen)&lt;0)
      {
          printf("\n\ngetsockname() error\n");
          exit(3);
      }
  
      printf("Port assigned is %d\n", ntohs(address.sin_port));
  
      client_address_size=sizeof(client);
  
  
  
      if(recvfrom(create_socket,fname, 255,0,(struct sockaddr *) &amp;client,&amp;client_address_size)&lt;0)
      {
          printf("\n\nrecvfrom() failed\n");
          exit(4);
      }
  
      printf("A request for filename %s Received..\n", fname);
  
      if ((fd=open(fname, O_RDONLY))&lt;0)
      {
          perror("File Open Failed");
          exit(0);
      }
  
      while((cont=read(fd, buffer, 10))&gt;0) 
      {
          sleep(1);
          sendto(create_socket,buffer,cont,0,(struct sockaddr *) &amp;client,client_address_size);
          printf("\n\nPacket sent\n");
      }
  
      sendto(create_socket,"*",1,0,(struct sockaddr *) &amp;client,client_address_size);
  
      printf("Request Completed\n");
      return close(create_socket);
  }
  </code></pre>
  
  <p>client.c:</p>
  
  <pre><code>#include&lt;sys/socket.h&gt;
  #include&lt;sys/types.h&gt;
  #include&lt;netinet/in.h&gt;
  #include&lt;unistd.h&gt;
  #include&lt;stdlib.h&gt;
  #include&lt;stdio.h&gt;
  
  int main()
  {
      int create_socket,cont,res;
      char *arg="127.0.0.1";
  
      int bufsize = 1024;
      int server_address_size=0;
      char *buffer = malloc(10);
      char fname[256];
      struct sockaddr_in address;
      int serv_addr_size = sizeof(address);
  
      if ((create_socket = socket(AF_INET,SOCK_DGRAM,0)) &gt; 0)
          printf("The Socket was created\n");
  
      address.sin_family = AF_INET;
      address.sin_port = htons(15000);
      address.sin_addr.s_addr=inet_addr(arg);
  
      if (connect(create_socket,(struct sockaddr *) &amp;address,sizeof(address)) == 0)
          printf("The connection was accepted with the server %s...\n",arg);
  
      printf("Enter The Filename to Request : ");
      scanf("%s",fname);
      res=sendto(create_socket, fname, sizeof(fname), 0,(struct sockaddr *) &amp;address,sizeof(address));
      if(res&lt;0)
      {
          printf("\n\nSendto falied...\n");
          exit(0);
      }
      printf("Request Accepted... Receiving File...\n\n");
  
      server_address_size=sizeof(address);
  
      printf("The contents of file are...\n\n");
  
      while((cont=recvfrom(create_socket, buffer, 10, 0,(struct sockaddr *) &amp;address,&amp;serv_addr_size))&gt;0) 
      {
          if(buffer[cont-1]=='*')
             break;
          write(1, buffer, cont);
  
      }
  
      printf("\nEOF\n");
      return close(create_socket);
  }
  </code></pre>
  
  <p>Above is the code working fine when it is run on the same system. Please tell me the modifications to be made to run the above code on different machines. Thanks in advance.</p>