Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #pragma comment(lib, "ws2_32.lib")
- #include <winsock2.h>
- #include <iostream>
- #include <string>
- #pragma warning(disable: 4996)
- using namespace std;
- int main(int argc, char* argv[]) {
- WSAData wsaData;
- WORD DLLVersion = MAKEWORD(2, 1);
- if (WSAStartup(DLLVersion, &wsaData) != 0) {
- std::cout << "Error" << std::endl;
- exit(1);
- }
- SOCKADDR_IN addr;
- int sizeofaddr = sizeof(addr);
- addr.sin_addr.s_addr = inet_addr("127.0.0.1");
- addr.sin_port = htons(1111);
- addr.sin_family = AF_INET;
- SOCKET Connection;
- Connection = socket(AF_INET, SOCK_STREAM, NULL);
- if (connect(Connection, (SOCKADDR*)&addr, sizeof(addr)) != 0) {
- cout << "Error: failed connect to server.\n";
- return 1;
- }
- cout << "Connected!\n";
- string msg1;
- while (true) {
- getline(cin, msg1);
- int msg_size = msg1.size();
- send(Connection, (char*)&msg_size, sizeof(int), NULL);
- send(Connection, msg1.c_str(), msg_size, NULL);
- Sleep(10);
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement