can you make a TCP socket server and a client code in python?
- User
can you make a TCP socket server and a client code in python?
Assistant
Sure! Here is a simple TCP socket server in Python:
import socket # Create a TCP/IP socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Bind the socket to a public host, and a port server_address = ('', 10000) sock.bind(server_address) # Listen for incoming connections sock.listen(1) while True: # Wait for a connection connection, client_address = sock.accept() try: print('Connection from', client_address) # Receive the data in small chunks and retransmit it while True: data = connection.recv(16) if data: print('Received', repr(data)) connection.sendall(data) else: break finally: # Clean up the connection connection.close()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.