c - communication between windows client and linux server? -


i performing communication between client(windows) , server(linux rt) in c. have written client code windows operating system (one laptop) , server code linux operating system (another laptop). connecting both laptop via ethernet cable , configured them on same subnet.

server.c : linux

#include <arpa/inet.h> #include <netinet/in.h> #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <unistd.h> #include <stdlib.h> #include <string.h> #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(&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* ) &my_addr, sizeof(my_addr))==-1)       err("bind");     else       printf("server : bind() successful\n");      while(1)     {         if (recvfrom(sockfd, buf, buflen, 0, (struct sockaddr*)&cli_addr,   &slen)==-1)             err("recvfrom()");         printf("received packet %s:%d\ndata: %s\n\n",                inet_ntoa(cli_addr.sin_addr), ntohs(cli_addr.sin_port), buf);     }      close(sockfd);     return 0; } 

client.c - windows

#pragma comment(lib, "ws2_32.lib")  #include <windows.h>  #include <stdio.h>  #include <stdlib.h>  #include <string.h> #include <fcntl.h> #include <errno.h> #include <time.h> #include <winsock.h> #include <io.h>  #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, &wsadata) != 0){       printf("winsock initialised failed \n");      } else {        printf("initialised\n");   if ((sockfd = socket(af_inet, sock_dgram, ipproto_udp))==-1)     err("socket");  bzero(&serv_addr, sizeof(serv_addr)); serv_addr.sin_family = af_inet; serv_addr.sin_port = htons(port); if (inet_aton(argv[1], &serv_addr.sin_addr)==0) {     fprintf(stderr, "inet_aton() failed\n");     exit(1); }        while(1) {     printf("\nenter data send(type exit , press enter exit) : ");     scanf("%[^\n]",buf);     getchar();     if(strcmp(buf,"exit") == 0)       exit(0);      if (sendto(sockfd, buf, buflen, 0, (struct sockaddr*)&serv_addr, slen)==-1)         err("sendto()"); }  close(sockfd); return 0; 

}

my question :

  • is possible perform communication ??
  • do want take specific measures doing ??

please give ideas regarding ?

you can connect 2 systems directly (via ethernet cable), typically must use special cable that: called "crossover cable". otherwise no connection possible.

newer network controllers implement detection kind of setup, might possible use standard cable setup, depends on network controllers build 2 systems. have try or consult documentation.

also migh have select special configuration on ms-windows side (inside network adapter configuration) work. experienced communication problems standard setup few times. can consult google settings.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -