fork download
  1. // client
  2. #pragma comment(lib, "ws2_32.lib")
  3. #include <WinSock2.h>
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <sys/types.h>
  9. //#include <sys/socket.h>
  10. //#include <netinet/in.h>
  11. //#include <netdb.h>
  12. #define PORT 12345/*サーバと同じ数 */
  13.  
  14. int main(int argc, char *argv[])
  15. {
  16. WSADATA wsaData;
  17. int i;
  18. struct hostent *host;
  19. struct sockaddr_in serv;
  20. int s, n;
  21. char buf[512];
  22.  
  23. WSAStartup(MAKEWORD(2, 2), &wsaData);
  24.  
  25. if (argc < 2) {
  26. fprintf(stderr,"need hostname\n");
  27. exit(1);
  28. }
  29.  
  30. host = gethostbyname(argv[1]);
  31. // bzero((char *)&serv, sizeof(serv));
  32. memset(&serv, 0, sizeof(serv));
  33. serv.sin_family = AF_INET;
  34. serv.sin_port = htons(PORT);
  35. serv.sin_addr = *(struct in_addr *)host->h_addr;
  36. s = socket(AF_INET, SOCK_STREAM, 0);
  37.  
  38. i = connect(s, (const struct sockaddr *)&serv, sizeof(serv));
  39. if (i < 0) {
  40. // i = WSAGetLastError();
  41. fprintf(stderr, "cannot connect\n");
  42. exit(1);
  43. }
  44.  
  45. while (n = recv(s, buf, 512, 0)) {
  46. fwrite(buf, 1, n, stdout);
  47. }
  48.  
  49. shutdown(s, SD_BOTH);
  50. closesocket(s);
  51. WSACleanup();
  52. return 0;
  53. }
  54.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty