mirror of
https://github.com/autistic-symposium/web3-starter-py.git
synced 2025-05-17 14:10:21 -04:00
💾
This commit is contained in:
parent
7cb7a479f6
commit
69bb4175f1
124 changed files with 20 additions and 15 deletions
33
boilerplates/security/python_sockets/tcp_server.py
Normal file
33
boilerplates/security/python_sockets/tcp_server.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
import socket
|
||||
import threading
|
||||
|
||||
|
||||
BIND_IP = '0.0.0.0'
|
||||
BIND_PORT = 9090
|
||||
|
||||
|
||||
def handle_client(client_socket):
|
||||
request = client_socket.recv(1024)
|
||||
|
||||
print(f'[*] Received: {request}')
|
||||
|
||||
client_socket.send('ACK')
|
||||
client_socket.close()
|
||||
|
||||
def tcp_server():
|
||||
|
||||
server = socket.socket( socket.AF_INET, socket.SOCK_STREAM)
|
||||
server.bind(( BIND_IP, BIND_PORT))
|
||||
server.listen(5)
|
||||
|
||||
print(f'[*] Listening on {BIND_IP}, {BIND_PORT}')
|
||||
while 1:
|
||||
client, addr = server.accept()
|
||||
print(f'[*] Accepted connection: {addr[0]}:{addr[1]}')
|
||||
|
||||
client_handler = threading.Thread(target=handle_client, args= (client,))
|
||||
client_handler.start()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
tcp_server()
|
Loading…
Add table
Add a link
Reference in a new issue