Advertisement
Guest User

Client

a guest
Oct 21st, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. #define _WINSOCK_DEPRECATED_NO_WARNINGS
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <WinSock2.h>
  5. #include <Windows.h>
  6. #pragma comment(lib, "Ws2_32.lib")
  7. using namespace std;
  8.  
  9. typedef struct busRases {
  10. int numberOfRace;
  11. int typeOfBus;
  12. float price;
  13. char destination[100];
  14. }*bus;
  15.  
  16. istream& operator>>(istream& input, busRases& obj)
  17. {
  18. cout << "Enter the destination: ";
  19. input.getline(obj.destination, 100, '\n');
  20. cout << "Enter the number of race: ";
  21. input >> obj.numberOfRace;
  22. cout << "Enter the type of bus: ";
  23. input >> obj.typeOfBus;
  24. cout << "Enter the price of ticket: ";
  25. input >> obj.price;
  26. return input;
  27. }
  28.  
  29. ostream& operator<<(ostream& output, busRases& obj)
  30. {
  31. output << "The destination: " << obj.destination << endl
  32. << "The race number: " << obj.numberOfRace << endl
  33. << "The type of bus: " << obj.typeOfBus << endl
  34. << "The price of ticket: " << obj.price << endl;
  35. return output;
  36. }
  37.  
  38. int main()
  39. {
  40. WORD wVersionRequested = MAKEWORD(2, 2);
  41. WSAData wsaData;
  42. WSAStartup(wVersionRequested, &wsaData);
  43.  
  44. SOCKET s = socket(AF_INET, SOCK_STREAM, 0);
  45. sockaddr_in addr;
  46. addr.sin_addr.s_addr = inet_addr("127.0.0.1");
  47. addr.sin_family = AF_INET;
  48. addr.sin_port = htons(1280);
  49.  
  50. int connectFailed = connect(s, (sockaddr*)&addr, sizeof(addr));
  51. if (!connectFailed)
  52. {
  53. bus temp = new busRases{ 0, 0, 0.0, "" };
  54. char* buf = (char*)temp;
  55. int bufSize = sizeof(busRases);
  56. int choice = 66;
  57. while (choice)
  58. {
  59. cout << "1. Create \n"
  60. << "2. Read info \n"
  61. << "3. Make task\n"
  62. << "4. Exit \n";
  63. scanf_s("%d%*c", &choice);
  64. char p, buf1[100];
  65. p = choice;
  66. send(s, &p, 1, 0);
  67. switch (choice)
  68. {
  69. case 1:
  70. cin >> *temp;
  71. send(s, buf, bufSize, 0);
  72. break;
  73. case 2:
  74. recv(s, &p, 1, 0);
  75. cout << "The race list: \n";
  76. for (int i = 0; i < (int)p; i++)
  77. {
  78. recv(s, buf, bufSize, 0);
  79. if (temp->destination != '\0')
  80. cout << *temp;
  81. }
  82. break;
  83. case 3:
  84. cout << "Enter the destination: ";
  85. cin.getline(buf1, 100, '\n');
  86. send(s, buf1, 1, 0);
  87. recv(s, buf1, 1, 0);
  88. cout << "List: ";
  89. for (int i = 0; i < p; i++)
  90. {
  91. recv(s, buf1, bufSize, 0);
  92. cout << *temp;
  93. }
  94. break;
  95. case 4:
  96. break;
  97. default:
  98. break;
  99. }
  100. }
  101.  
  102. }
  103. closesocket(s);
  104. WSACleanup();
  105. return 0;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement