Python
Socket Programming
TCP Socket server and client.
By EZ4Code Team
socketnetwork
Code
import socket
# Server
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(("localhost", 8080))
server.listen(5)
conn, addr = server.accept()
with conn:
while True:
data = conn.recv(1024)
if not data:
break
conn.sendall(data)
# Client
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(("localhost", 8080))
client.sendall(b"hello")
print(client.recv(1024))Explanation
The socket module provides low-level network communication capabilities.
More Python Snippets
Sort Dictionary by Value
Sort a Python dictionary by its values in descending order.
List Comprehension
Quickly generate lists using list comprehensions.
Dictionary Merging
Multiple ways to merge dictionaries.
File Read/Write
Various ways to read and write files.
CSV Processing
Read and write CSV files using the csv module.
JSON Processing
JSON serialization and deserialization.