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) {
- cout << "Error" << endl;
- exit(1);
- }
- DWORD cmode;
- cmode &= ~ENABLE_LINE_INPUT;
- SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), cmode);
- 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 newConnection;
- newConnection = socket(AF_INET, SOCK_STREAM, NULL);
- if (connect(newConnection, (SOCKADDR*)&addr, sizeof(addr)) != 0) {
- cout << "Error: failed connect to server.\n";
- closesocket(newConnection);
- WSACleanup();
- return -1;
- }
- else
- cout << "Connected!\n";
- char msg;
- while (true) {
- msg = getchar();
- send(newConnection, &msg, sizeof(char), NULL);
- if (msg == '\b')
- cout << '\b' << ' ' << '\b';
- else if (msg == '\n')
- cout << endl;
- else
- cout << msg;
- }
- WSACleanup();
- closesocket(newConnection);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement