Last active
June 15, 2020 08:20
-
-
Save dtrizna/c8aba4e20c8999acec94efc5876f05d6 to your computer and use it in GitHub Desktop.
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
import socket | |
import sys | |
listening_add = "192.168.56.1" | |
listening_port = 8888 | |
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
# bind socket obect to address and port and start to listen there | |
server.bind((listening_add, listening_port)) | |
server.listen(5) | |
print("Listening on {}:{}".format(listening_add, listening_port)) | |
# Define function that will be called later | |
# Function is responsible to handle connection | |
def handle_client(client_socket): | |
# Dispiay, what data is received within new connectīon | |
recv_mess = client_socket.recv(1024) | |
print(recv_mess.decode()) | |
# Send data back and close the connection | |
client_socket.send(b'ACK!') | |
client_socket.close () | |
# Start endless loop with listening incoming data | |
# When such connection appears, send this connection socket obect to | |
# handle_client function | |
while True: | |
sock, add = server.accept() | |
print("Received connection from address " + str(add[0]) + " and port " + str(add[1])) | |
handle_client(sock) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment