source: trigger/communication.py@ 77

Last change on this file since 77 was 77, checked in by rissim, 15 years ago
trigger: gui added, interface modified
File size: 1.0 KB
Line 
1###############################################################################
2# The communication module (communication.py)
3###############################################################################
4import cPickle
5import socket
6import struct
7
8marshall = cPickle.dumps
9unmarshall = cPickle.loads
10
11def send(channel, args):
12 #print "will send: ", args
13 args+="\n"
14 buf = args #marshall(args)
15 #value = socket.htonl(len(buf))
16 value = str(len(buf))
17 #size = struct.pack("i",value)
18 print "length: ",len(buf)
19 #print "SIZE: ",repr(size)
20 #channel.send(value)
21 buf+="\0"
22 channel.send(buf)
23 #print 'sending: ',buf
24 #print 'sent'
25def receive(channel):
26
27 size = struct.calcsize("L")
28 size = channel.recv(size)
29 print "rec size: ",size
30 try:
31 size = socket.ntohl(struct.unpack("i", size)[0])
32 #print "unpacked: ",size
33 except struct.error, e:
34 return ''
35
36 buf = ""
37
38 while len(buf) < size:
39 buf = channel.recv(size - len(buf))
40
41 return unmarshall(buf)[0]
Note: See TracBrowser for help on using the repository browser.