Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <WS2tcpip.h>
- #pragma comment(lib, "ws2_32.lib")
- using namespace std;
- void main()
- {
- string ipAddress = "127.0.0.1"; // IP Address of the server
- int port = 54000; // Listening port # on the server
- // Initialize WinSock
- WSAData data;
- WORD ver = MAKEWORD(2, 2);
- int wsResult = WSAStartup(ver, &data);
- if (wsResult != 0)
- {
- cerr << "Can't start Winsock, Err #" << wsResult << endl;
- return;
- }
- // Create socket
- SOCKET sock = socket(AF_INET, SOCK_STREAM, 0);
- if (sock == INVALID_SOCKET)
- {
- cerr << "Can't create socket, Err #" << WSAGetLastError() << endl;
- WSACleanup();
- return;
- }
- // Fill in a hint structure
- sockaddr_in hint;
- hint.sin_family = AF_INET;
- hint.sin_port = htons(port);
- inet_pton(AF_INET, ipAddress.c_str(), &hint.sin_addr);
- // Connect to server
- int connResult = connect(sock, (sockaddr*)&hint, sizeof(hint));
- if (connResult == SOCKET_ERROR)
- {
- cerr << "Can't connect to server, Err #" << WSAGetLastError() << endl;
- closesocket(sock);
- WSACleanup();
- return;
- }
- // Do-while loop to send and receive data
- char buf[4096];
- string userInput;
- string SvCMD;
- while (true)
- {
- ZeroMemory(buf, 4096);
- int bytesReceived = recv(sock, buf, 4096, 0);
- if (bytesReceived > 0)
- {
- // Echo response to console
- // Respostas
- SvCMD = string(buf);
- if (SvCMD == "Key") {
- cout << "Key Logger On> " << endl;
- }
- cout << "SERVER> " << string(buf, 0, bytesReceived) << endl;
- }
- }
- // Gracefully close down everything
- closesocket(sock);
- WSACleanup();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement