file : created a tc client

this is a rudimentary tcp client template that communicates with a tcp server
This commit is contained in:
2025-09-25 13:58:01 +02:00
parent cc283e8995
commit 14c5f6b1b1
2 changed files with 22 additions and 1 deletions

22
tcp_client.py Normal file
View File

@ -0,0 +1,22 @@
#!/usr/bin/env python
import socket
tcp_server_adress = "my_tcp_server.fr"
client_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('{tcp_server_adress}', 80))
request = f"GET / HTTP/1.1\r\nHost: {tcp_server_adress}\r\n\r\n"
sock.sendall(request.encode())
buffer = b""
while True:
data = sock.recv(4096)
if not data:
break
buffer += data
print(buffer.decode())
sock.close()

1
tmp
View File

@ -1 +0,0 @@
test file to init the repo