fork(3) download
  1. #include <iostream>
  2. #include <arpa/inet.h>
  3. #include <unistd.h>
  4. #include <sys/socket.h>
  5. #include <sys/types.h>
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <stdlib.h>
  9.  
  10.  
  11. using namespace std;
  12.  
  13. int main()
  14. {
  15. char buf[255];
  16. struct sockaddr_in si_other;
  17. int s, slen=sizeof(si_other);
  18. if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1)
  19. cout << "socket\n";
  20. memset((char *) &si_other, 0, sizeof(si_other));
  21. si_other.sin_family = AF_INET;
  22. si_other.sin_port = htons(3478);
  23. if (inet_aton("217.10.68.152", &si_other.sin_addr)==0) // stun adres
  24. {
  25. fprintf(stderr, "inet_aton() failed\n");
  26. exit(1);
  27. }
  28. while (1)
  29. {
  30. usleep(10000);
  31. cout << "input_mess >>>";
  32. cin >> buf;
  33. if (sendto(s, buf, strlen(buf), 0, (struct sockaddr *)&si_other, slen)==-1)
  34. cout << "sendto()\n";
  35. for(int i = 0; i < 255; i++)
  36. buf[i] = 0;
  37. if (recvfrom(s, buf, 255, 0, (struct sockaddr *) &si_other,(socklen_t*) &slen) == -1)
  38. {
  39. cout << "recvfrom()\n";
  40. }
  41.  
  42. cout << buf << endl;
  43.  
  44. }
  45. close(s);
  46. }
Time limit exceeded #stdin #stdout 5s 3460KB
stdin
test
stdout
input_mess >>>