Junior — Middle
Do you have practical experience working with network protocols and technologies?
sobes.tech AI
Answer from AI
Practical experience with network protocols and technologies includes understanding and using protocols such as TCP/IP, UDP, HTTP, FTP, and others. In C/C++, this is often implemented through sockets.
For example, to create a simple TCP server in C++, you can use POSIX sockets:
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <cstring>
#include <iostream>
int main() {
int server_fd = socket(AF_INET, SOCK_STREAM, 0);
if (server_fd == 0) {
perror("socket failed");
return -1;
}
sockaddr_in address{};
address.sin_family = AF_INET;
address.sin_addr.s_addr = INADDR_ANY;
address.sin_port = htons(8080);
if (bind(server_fd, (struct sockaddr*)&address, sizeof(address)) < 0) {
perror("bind failed");
return -1;
}
if (listen(server_fd, 3) < 0) {
perror("listen");
return -1;
}
int addrlen = sizeof(address);
int new_socket = accept(server_fd, (struct sockaddr*)&address, (socklen_t*)&addrlen);
if (new_socket < 0) {
perror("accept");
return -1;
}
const char* hello = "Hello from server";
send(new_socket, hello, strlen(hello), 0);
close(new_socket);
close(server_fd);
return 0;
}
This experience allows you to create network applications, understand protocol features, work with low-level APIs, and ensure reliable data transmission.