Answers for "c++ listen to port"

C++
0

c++ bind port

s = socket(AF_INET, SOCK_STREAM, 0);
/* ... */

memset(&client_addr, 0, sizeof(client_addr));
client_addr.sin_family = AF_INET;
client_addr.sin_port = htons(22222);

if (bind(s, (struct sockaddr *) &client_addr, sizeof(client_addr)) < 0) {
    perror("bind");
    exit(1);
}

connect(s, (struct sockaddr *) &server_addr, sizeof(server_addr));
Posted by: Guest on September-01-2021

Browse Popular Code Answers by Language