source: ResearchApps/Measurement/warpnet_framework/warpnet_server_azimuth.py

Last change on this file was 1519, checked in by sgupta, 14 years ago

WARPnet testing framework

File size: 1.3 KB
Line 
1# WARPnet Client<->Server Architecture
2# WARPnet Parameter Definitions
3#
4# Author: Siddharth Gupta
5
6from twisted.internet import reactor
7from twisted.internet.protocol import Protocol, ClientFactory
8from warpnet_common_params import *
9
10class EmulatorProtocol(Protocol):
11
12    def sendMessage(self, msg):
13        self.transport.write(msg)
14
15    def dataReceived(self, data):
16        self.factory.dataReceived(data)
17       
18    def connectionMade(self):
19        self.factory.protocolInst = self
20        print "Connected to Emulator"
21
22    def connectionLost(self, reason):
23        print "Disconnected from Emulator"
24
25class EmulatorFactory(ClientFactory):
26    protocol = EmulatorProtocol
27   
28    def __init__(self, master):
29        self.master = master
30   
31    def sendMessage(self, message):
32        self.protocolInst.sendMessage(message)
33       
34    def dataReceived(self, data):
35        self.master.dataReceived(data)
36   
37class processEmulatorMsg():
38   
39    def __init__(self, factory, controllerID, ipAddr):
40        self.emulator = EmulatorFactory(self)
41        self.factory = factory
42        self.cID = controllerID
43        reactor.connectTCP(ipAddr, 10102, self.emulator)
44   
45    def sendMessage(self, message):
46        self.emulator.sendMessage(message)
47   
48    def message(self, controllerID, data):
49        #print "Sending Message to Emulator"
50        self.sendMessage(data['msg'])
51
52    def dataReceived(self, data):
53        self.factory.sendData_cID(self.cID, SC_EMULATOR_MSG_FROM_BOX, {'msg': data})
54
55
Note: See TracBrowser for help on using the repository browser.