<s> """<STR_LIT>""" <EOL> import sys <EOL> import wx <EOL> from twisted . internet import wxreactor <EOL> wxreactor . install ( ) <EOL> from twisted . internet . protocol import Protocol , DatagramProtocol , Factory <EOL> from twisted . internet import reactor <EOL> from twisted . python import log <EOL> class M2UDP ( DatagramProtocol ) : <EOL> """<STR_LIT>""" <EOL> def datagramReceived ( self , data , host_port ) : <EOL> """<STR_LIT>""" <EOL> host , port = host_port <EOL> log . msg ( "<STR_LIT>" % ( data , host , port ) ) <EOL> c = data . strip ( ) <EOL> if len ( c ) > <NUM_LIT:0> : <EOL> mlab = self . mlab <EOL> engine = self . engine <EOL> scene = self . scene <EOL> camera = scene . camera <EOL> try : <EOL> exec ( c , locals ( ) , globals ( ) ) <EOL> except : <EOL> log . err ( ) <EOL> scene . render ( ) <EOL> class M2TCP ( Protocol ) : <EOL> """<STR_LIT>""" <EOL> maxConnect = <NUM_LIT:1> <EOL> def connectionMade ( self ) : <EOL> log . msg ( '<STR_LIT>' ) <EOL> self . factory . numConnect += <NUM_LIT:1> <EOL> if self . factory . numConnect > self . maxConnect : <EOL> self . transport . write ( "<STR_LIT>" ) <EOL> self . transport . loseConnection ( ) <EOL> def connectionLost ( self , reason ) : <EOL> log . msg ( '<STR_LIT>' ) <EOL> self . factory . numConnect -= <NUM_LIT:1> <EOL> def dataReceived ( self , data ) : <EOL> """<STR_LIT>""" <EOL> c = data . strip ( ) <EOL> log . msg ( '<STR_LIT>' , c ) <EOL> if len ( c ) > <NUM_LIT:0> : <EOL> mlab = self . factory . mlab <EOL> engine = self . factory . engine <EOL> scene = self . factory . scene <EOL> camera = scene . camera <EOL> try : <EOL> exec ( c , locals ( ) , globals ( ) ) <EOL> except : <EOL> log . err ( ) <EOL> scene . render ( ) <EOL> def serve_udp ( engine = None , port = <NUM_LIT> , logto = sys . stdout ) : <EOL> """<STR_LIT>""" <EOL> from mayavi import mlab <EOL> e = engine or mlab . get_engine ( ) <EOL> proto = M2UDP ( ) <EOL> proto . engine = e <EOL> proto . scene = e . current_scene . scene <EOL> proto . mlab = mlab <EOL> if logto is not None : <EOL> log . startLogging ( logto ) <EOL> log . msg ( '<STR_LIT>' , port ) <EOL> log . msg ( '<STR_LIT>' , e ) <EOL> reactor . registerWxApp ( wx . GetApp ( ) ) <EOL> reactor . listenUDP ( port , proto ) <EOL> reactor . run ( ) <EOL> def serve_tcp ( engine = None , port = <NUM_LIT> , logto = sys . stdout , max_connect = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> from mayavi import mlab <EOL> e = engine or mlab . get_engine ( ) <EOL> factory = Factory ( ) <EOL> factory . protocol = M2TCP <EOL> factory . maxConnect = max_connect <EOL> factory . numConnect = <NUM_LIT:0> <EOL> factory . engine = e <EOL> factory . scene = e . current_scene . scene <EOL> factory . mlab = mlab <EOL> if logto is not None : <EOL> log . startLogging ( logto ) <EOL> log . msg ( '<STR_LIT>' , port ) <EOL> log . msg ( '<STR_LIT>' , e ) <EOL> reactor . registerWxApp ( wx . GetApp ( ) ) <EOL> reactor . listenTCP ( port , factory ) <EOL> reactor . run ( ) <EOL> def test_tcp ( ) : <EOL> """<STR_LIT>""" <EOL> from mayavi import mlab <EOL> mlab . test_plot3d ( ) <EOL> serve_tcp ( ) <EOL> def test_udp ( ) : <EOL> """<STR_LIT>""" <EOL> from mayavi import mlab <EOL> mlab . test_plot3d ( ) <EOL> serve_udp ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> test_tcp ( ) </s>
