trying to make gui

This commit is contained in:
2023-04-10 21:34:00 -07:00
parent 8c82234668
commit 8afef87a56
6 changed files with 188 additions and 49 deletions

31
vckoserver.py Normal file
View File

@@ -0,0 +1,31 @@
import socket
def server_program():
# get the hostname
host = socket.gethostname()
port = 5000 # initiate port no above 1024
server_socket = socket.socket() # get instance
# look closely. The bind() function takes tuple as argument
server_socket.bind((host, port)) # bind host address and port together
# configure how many client the server can listen simultaneously
server_socket.listen(5)
conn, address = server_socket.accept() # accept new connection
while True:
print("Connection from: " + str(address))
while True:
# receive data stream. it won't accept data packet greater than 1024 bytes
data = conn.recv(1024).decode()
if not data:
# if data is not received break
break
print("from connected user: " + str(data))
data = f"you sent: {str(data)}"
conn.send(data.encode()) # send data to the client
conn.close() # close the connection
if __name__ == '__main__':
server_program()