-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
53 lines (45 loc) · 1.52 KB
/
Copy pathserver.py
File metadata and controls
53 lines (45 loc) · 1.52 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
import socket
import select
import os
import sys
import client
from PyQt4 import QtCore
import gobject
gobject.threads_init()
import gst
#communication: server code. This class holds a client object which is set to None, when we have a connection established to the rover
#the client holds the socket. This socket is only used for recieving data from the server. The socket meant for sending data is present
#in main.py
class customServer(QtCore.QThread):
def __init__(self, port, bufferLength):
QtCore.QThread.__init__(self)
self.signal = QtCore.SIGNAL("server")
self.messageNum = 0
self.client = client.client()
self.connections = []
self.port = port
self.bufferLength = bufferLength
hostname = "0.0.0.0"
self.serv = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.serv.bind((hostname, int(port)))
self.connections.append(self.serv)
def run(self):
try:
while True:
#print "inside the server---------------------"
readsock, writesock, errsock = select.select(self.connections, [], [])
for sock in readsock:
self.receive()
except Exception, e:
print e
#method moved to main code
def send(self, data, host, port):
self.client = client.client()
self.client.connect(host, port)
self.client.send(data)
def receive(self):
chunk, addr = self.serv.recvfrom(self.bufferLength)
someString = str(chunk)
#print 'Message received : ' + someString
self.emit(self.signal, someString)
sys.stdout.flush()