Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  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. #include <netdb.h>
  10. using namespace std;
  11. int main() {
  12. int client, server;
  13. int portNum = 8878;
  14. bool isExit = false;
  15. int buffSize = 512;
  16. char buffers[512];
  17. char* ip = "127.0.0.1";
  18. struct sockaddr_in server_addr;
  19.  
  20. client = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
  21.  
  22. if (client<0){
  23. cout << "socket coudlnt create..." << endl;
  24. exit(1);
  25. }
  26. cout <<" Socket created! " << endl;
  27.  
  28. server_addr.sin_family = AF_INET;
  29. server_addr.sin_port =htons(portNum);
  30.  
  31.  
  32. if (connect(client,(struct sockaddr *)&server_addr, sizeof(server_addr)) == 0)
  33. cout << "Connecting... " << endl;
  34.  
  35. //recv(client, buffer, buffSize, 0);
  36. //cout << "=> Connection confirmed, you are good to go...";
  37. socklen_t m = sizeof(server_addr);
  38. do {
  39. cout << "Client: ";
  40. do {
  41. cin >> buffers;
  42. sendto(client, buffers, buffSize, 0, (struct sockaddr *)&server_addr, m);
  43. cout <<"Sent"<< endl;
  44. }while (true);
  45. }while (!isExit);
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement