source: trigger/communication.py@ 52

Last change on this file since 52 was 52, checked in by rissim, 15 years ago
trigger software (VME) v1
File size: 787 bytes
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 buf = marshall(args)
13 value = socket.htonl(len(buf))
14 size = struct.pack("L",value)
15 channel.send(size)
16 channel.send(buf)
17
18def receive(channel):
19
20 size = struct.calcsize("L")
21 size = channel.recv(size)
22 try:
23 size = socket.ntohl(struct.unpack("L", size)[0])
24 except struct.error, e:
25 return ''
26
27 buf = ""
28
29 while len(buf) < size:
30 buf = channel.recv(size - len(buf))
31
32 return unmarshall(buf)[0]
Note: See TracBrowser for help on using the repository browser.