Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _WINSOCK_DEPRECATED_NO_WARNINGS
- #include <iostream>
- #include <iomanip>
- #include <WinSock2.h>
- #include <Windows.h>
- #pragma comment(lib, "Ws2_32.lib")
- using namespace std;
- typedef struct busRases {
- int numberOfRace;
- int typeOfBus;
- float price;
- char destination[100];
- }*bus;
- istream& operator>>(istream& input, busRases& obj)
- {
- cout << "Enter the destination: ";
- input.getline(obj.destination, 100, '\n');
- cout << "Enter the number of race: ";
- input >> obj.numberOfRace;
- cout << "Enter the type of bus: ";
- input >> obj.typeOfBus;
- cout << "Enter the price of ticket: ";
- input >> obj.price;
- return input;
- }
- ostream& operator<<(ostream& output, busRases& obj)
- {
- output << "The destination: " << obj.destination << endl
- << "The race number: " << obj.numberOfRace << endl
- << "The type of bus: " << obj.typeOfBus << endl
- << "The price of ticket: " << obj.price << endl;
- return output;
- }
- int main()
- {
- WORD wVersionRequested = MAKEWORD(2, 2);
- WSAData wsaData;
- WSAStartup(wVersionRequested, &wsaData);
- SOCKET s = socket(AF_INET, SOCK_STREAM, 0);
- sockaddr_in addr;
- addr.sin_addr.s_addr = inet_addr("127.0.0.1");
- addr.sin_family = AF_INET;
- addr.sin_port = htons(1280);
- int connectFailed = connect(s, (sockaddr*)&addr, sizeof(addr));
- if (!connectFailed)
- {
- bus temp = new busRases{ 0, 0, 0.0, "" };
- char* buf = (char*)temp;
- int bufSize = sizeof(busRases);
- int choice = 66;
- while (choice)
- {
- cout << "1. Create \n"
- << "2. Read info \n"
- << "3. Make task\n"
- << "4. Exit \n";
- scanf_s("%d%*c", &choice);
- char p, buf1[100];
- p = choice;
- send(s, &p, 1, 0);
- switch (choice)
- {
- case 1:
- cin >> *temp;
- send(s, buf, bufSize, 0);
- break;
- case 2:
- recv(s, &p, 1, 0);
- cout << "The race list: \n";
- for (int i = 0; i < (int)p; i++)
- {
- recv(s, buf, bufSize, 0);
- if (temp->destination != '\0')
- cout << *temp;
- }
- break;
- case 3:
- cout << "Enter the destination: ";
- cin.getline(buf1, 100, '\n');
- send(s, buf1, 1, 0);
- recv(s, buf1, 1, 0);
- cout << "List: ";
- for (int i = 0; i < p; i++)
- {
- recv(s, buf1, bufSize, 0);
- cout << *temp;
- }
- break;
- case 4:
- break;
- default:
- break;
- }
- }
- }
- closesocket(s);
- WSACleanup();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement