title: communication between windows client and linux server?
body: <p>I am performing communication between client(windows) and server(linux RT) in c. I have written a client code for windows operating system (one laptop) and server code for linux operating system (another laptop). I am connecting the both laptop via ethernet cable and configured them on the same subnet.</p>
  
  <p>SERVER.c : Linux</p>
  
  <pre><code>#include &lt;arpa/inet.h&gt;
  #include &lt;netinet/in.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/socket.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #define BUFLEN 512
  #define PORT 9930
  
  void err(char *str)
  {
      perror(str);
      exit(1);
  }
  
  int main(void)
  {
      struct sockaddr_in my_addr, cli_addr;
      int sockfd, i;
      socklen_t slen=sizeof(cli_addr);
      char buf[BUFLEN];
  
      if ((sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1)
        err("socket");
      else
        printf("Server : Socket() successful\n");
  
      bzero(&amp;my_addr, sizeof(my_addr));
      my_addr.sin_family = AF_INET;
      my_addr.sin_port = htons(PORT);
      my_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  
      if (bind(sockfd, (struct sockaddr* ) &amp;my_addr, sizeof(my_addr))==-1)
        err("bind");
      else
        printf("Server : bind() successful\n");
  
      while(1)
      {
          if (recvfrom(sockfd, buf, BUFLEN, 0, (struct sockaddr*)&amp;cli_addr, 
  
  &amp;slen)==-1)
              err("recvfrom()");
          printf("Received packet from %s:%d\nData: %s\n\n",
                 inet_ntoa(cli_addr.sin_addr), ntohs(cli_addr.sin_port), buf);
      }
  
      close(sockfd);
      return 0;
  }
  </code></pre>
  
  <p>CLIENT.c - windows</p>
  
  <pre><code>#pragma comment(lib, "Ws2_32.lib")
  
  #include &lt;windows.h&gt; 
  #include &lt;stdio.h&gt; 
  #include &lt;stdlib.h&gt; 
  #include &lt;string.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;time.h&gt;
  #include &lt;winsock.h&gt;
  #include &lt;io.h&gt; 
  #define BUFLEN 512
  #define PORT 9930
  
  void err(char *str)
  {
      perror(str);
      exit(1);
  }
  
  int main(void)
  {
      struct sockaddr_in my_addr, cli_addr;
      int sockfd, i;
      socklen_t slen=sizeof(cli_addr);
      char buf[BUFLEN];
      WORD wVersionRequested;
      WSADATA wsaData;
  
       printf("Initializing Winsock\n");
       wVersionRequested = MAKEWORD (1, 1);
       if (WSAStartup (wVersionRequested, &amp;wsaData) != 0){
        printf("Winsock initialised failed \n");
       } else {
         printf("Initialised\n");
  
  
  if ((sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1)
      err("socket");
  
  bzero(&amp;serv_addr, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_port = htons(PORT);
  if (inet_aton(argv[1], &amp;serv_addr.sin_addr)==0)
  {
      fprintf(stderr, "inet_aton() failed\n");
      exit(1);
  }
  
  
       while(1)
  {
      printf("\nEnter data to send(Type exit and press enter to exit) : ");
      scanf("%[^\n]",buf);
      getchar();
      if(strcmp(buf,"exit") == 0)
        exit(0);
  
      if (sendto(sockfd, buf, BUFLEN, 0, (struct sockaddr*)&amp;serv_addr, slen)==-1)
          err("sendto()");
  }
  
  close(sockfd);
  return 0;
  </code></pre>
  
  <p>}</p>
  
  <p>My question : </p>
  
  <ul>
  <li>Is it possible to perform communication like this ??</li>
  <li>Do I want to take specific measures for doing this ??</li>
  </ul>
  
  <p>Please give ideas regarding this ?</p>