-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
39 lines (23 loc) · 701 Bytes
/
server.py
File metadata and controls
39 lines (23 loc) · 701 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import socket
import _thread
import sys
PORT = 5555
SERVER = socket.gethostbyname(socket.gethostname())
SERVER = "127.0.0.1"
HEADERSIZE = 10
hash = "utf-8"
msg = "Welcome to the server"
print(f"{len(msg):<10} {msg}, you are hosting on {SERVER}")
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
try:
s.bind((SERVER,PORT))
except socket.error as e:
print(e)
s.listen(10)
clientsocket, address = s.accept()
print(f"Connected succesffuly to {address}")
while True:
data = clientsocket.recv(1024)
print(data)
# clientsocket.send(bytes("welcome to the server",hash))
# clientsocket.close()