-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fed2779
commit fdc8888
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import socket | ||
import threading | ||
|
||
bind_ip = "0.0.0.0" | ||
bind_port = 9999 | ||
|
||
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
server.bind((bind_ip, bind_port)) | ||
server.listen(5) | ||
print("[*] Listening on %s:%d" % (bind_ip, bind_port)) | ||
|
||
# this is our client-handling thread | ||
def handle_client(client_socket): | ||
# print out what the client sends | ||
request = client_socket.recv(1024) | ||
print("[*] Received: %s" % request.decode()) | ||
# send back a packet | ||
client_socket.send("ACK!".encode()) | ||
client_socket.close() | ||
|
||
while True: | ||
client, addr = server.accept() | ||
print("[*] Accepted connection from: %s:%d" % (addr[0], addr[1])) | ||
# spin up our client thread to handle incoming data | ||
client_handler = threading.Thread(target=handle_client, args=(client,)) | ||
client_handler.start() |