Untitled
unknown
plain_text
9 days ago
1.0 kB
5
Indexable
#include <winsock2.h> #include <ws2tcpip.h> // Include for InetPton #pragma comment(lib, "ws2_32.lib") // Link with ws2_32.lib void main(void) { WSADATA wsaData; SOCKET s; SOCKADDR_IN ServerAddr; int Port = 5150; // Initialize Winsock version 2.2 WSAStartup(MAKEWORD(2, 2), &wsaData); // Create a new socket to make a client connection. s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); // server IP: ServerAddr.sin_family = AF_INET; ServerAddr.sin_port = htons(Port); InetPton(AF_INET, L"127.0.0.1", &ServerAddr.sin_addr); // Use InetPton with L"127.0.0.1" for localhost // Make a connection to the server with socket s. connect(s, (SOCKADDR*)&ServerAddr, sizeof(ServerAddr)); // At this point you can start sending or receiving data on // the socket s. We will describe sending and receiving data closesocket(s); // When your application is finished handling the connection, call // WSACleanup. WSACleanup(); }
Editor is loading...
Leave a Comment