-
Notifications
You must be signed in to change notification settings - Fork 0
/
TCPServer.py
49 lines (38 loc) · 1.37 KB
/
TCPServer.py
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
from socket import *
from threading import Thread
print'SERVER'
class listeningThread (Thread):
def __init__(self, threadID, connectionSocket, addr):
Thread.__init__(self)
self.threadID = threadID
self.connectionSocket = connectionSocket
self.addr = addr
self.newMessage = ""
self.oldMessage = ""
def run(self):
while True: #should include a check if client wants to quit
print 'venter pa melding'
message, address = self.connectionSocket.recvfrom(1024)
# might need a mutex here
# docs.python.org/2/library/multiprocessing.html
# 16.6.1.4
print'package recieved from: ', address, "msg: ", message
serverSocket = socket(AF_INET, SOCK_STREAM)
serverSocket.bind(('', 9008))
serverSocket.listen(5)
def acceptClient():
threadsSpawned = 0
listOfRunningThreads = []
while True:
vent=' '
print 'venter pa klient'
connectionSocket, addr = serverSocket.accept()
print 'klient koblet til'
print'starter ny thread'
#t = Thread(target=recvMsg(connectionSocket,addr))
#t.start()
listOfRunningThreads.append(listeningThread(threadsSpawned, connectionSocket, addr))
listOfRunningThreads[ threadsSpawned ].start()
threadsSpawned += 1
print'etter thread'
acceptClient()