-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMonehMk2Server.py
More file actions
51 lines (41 loc) · 1.32 KB
/
Copy pathMonehMk2Server.py
File metadata and controls
51 lines (41 loc) · 1.32 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# GUI-based program for receiving data on computer or Pi
import socket
from _thread import *
import threading
import os
import time
import pygame
from pygame.locals import *
print_lock = threading.Lock()
host = '' # accept anything
port = 9001 # socket with the minimally maximal power level
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.bind((host, port))
except socket.error as e:
print(str(e))
s.listen(5) # size of queue of how many connections accepted
print("Awaiting contact...")
def threaded_client(conn, no):
conn.send(str.encode("Hey there, Client " + str(no)))
while True:
data = conn.recv(4096)
reply = "Received from Client " + str(no) + ": " + data.decode('utf-8')
with print_lock:
print(reply)
if not data:
break
conn.sendall(str.encode(reply))
conn.close()
def threaded_client_acceptor():
connno = 0
while True:
conn, addr = s.accept()
with print_lock:
print("Connected to " + str(addr[0]) + ":" + str(addr[1]) + ", Client " + str(connno))
start_new_thread(threaded_client, (conn, connno))
connno += 1
start_new_thread(threaded_client_acceptor(), ())
filepath = "C:\\Users\\Charles Turvey\\Documents\\Money\\Mk2\\"
pygame.init()
screen = pygame.display.set_mode((500, 500))