-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver_client.py
More file actions
35 lines (28 loc) · 1.04 KB
/
server_client.py
File metadata and controls
35 lines (28 loc) · 1.04 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
import threading
"""
Responsible for handling all client/server interaction
on the server side once connection is established.
"""
class ServeClientThread(threading.Thread):
def __init__(self,ip,port,socket,queue):
threading.Thread.__init__(self)
self.ip = ip
self.port = port
self.socket = socket
self.server_queue = queue
# thread's 'main' function
def run(self):
print 'Connection from: '+str(self.ip)+':'+str(self.port)
self.socket.send('Welcome to the server.')
# data = 'START'
# while True: # loop while socket is alive
# try:
# while (data != ''): # wait for data from client
# if (data != 'START'): # check for starting condition
# print 'Client ('+str(self.port)+') sent: '+data+'.'
# self.server_queue.put(data) # pass data to server main thread
# data = self.socket.recv(2048) # read more data
# except Exception: # handle broken connection
# print 'Client ('+str(self.port)+') disconnected.'
# self.socket.close() # properly close socket
# break # exit wait-loop