Junior — Middle
Do you have experience working with the TCP protocol for network communication?
sobes.tech AI
Answer from AI
Yes, there is experience working with the TCP protocol. TCP (Transmission Control Protocol) provides reliable, connection-oriented data transfer between two nodes in a network. In practice, it is used to create client-server applications where guaranteeing delivery and message order is important.
Example in Python for a simple TCP server and client:
# TCP server
import socket
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(('localhost', 12345))
server.listen(1)
conn, addr = server.accept()
print('Connected by', addr)
data = conn.recv(1024)
conn.sendall(data) # echo
conn.close()
# TCP client
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(('localhost', 12345))
client.sendall(b'Hello TCP')
data = client.recv(1024)
print('Received', data)
client.close()
This approach allows organizing reliable data exchange, controlling message order and integrity.