![]() |
|
|
|
#1
|
|||
|
|||
|
continued
No luck with an answer yet, so I look for a work-around myself. Extend the communication protocol with a connection-test and connect-confirm network events
Code:
import viz
import viznet
CONN_TEST = viznet.id("connTest")
CONN_CONF = viznet.id("connConf")
myName = viz.net.getName()
Code:
if myName == 'HEAD1':
doClient()
else:
doServer()
viz.go()
Code:
def srvrConnectTest(e):
viznet.server.sendClient(e.client, CONN_CONF, server=myName)
print 'connect confirmation sent'
def doServer():
viznet.server.start()
viz.callback(CONN_TEST, srvrConnectTest)
Code:
import threading
_TIMEOUT = 3.0
_myServer = None
_confirmEvent = threading.Event()
def clntConnectConfirm(e):
_myServer = e.server
print 'received confirmation from', e.server
_confirmEvent.set()
def doClient():
_lookfor = 'MASTER'
if not viznet.client.connect(_lookfor):
print _lookfor, 'does not run'
else:
viz.callback(CONN_CONF, clntConnectConfirm)
print 'asking for connection confirmation...'
viznet.client.send(CONN_TEST, client=myName)
_confirmEvent.clear()
_confirmEvent.wait(_TIMEOUT)
print 'the server's name is', _myServer
Code:
asking for connection confirmation... the server's name is None received confirmation from MASTER Thanks, Best Regards, Walter
__________________
21 is only half the truth. |
|
#2
|
|||
|
|||
|
Hi,
A couple things to note:
I'd recommend looking into the Python Twisted library. It supports much more advanced networking features. However, you can perform a blocking handshake by manually updating the network events in a while loop. Here is a minimal example: Server code: Code:
import viz
import viznet
viz.go()
HANDSHAKE = viznet.id('ConnectHandshake')
viznet.server.start()
# Perform handshake with clients
def onStartClient(e):
viznet.server.sendClient(e.sender,HANDSHAKE)
viz.callback(viznet.CLIENT_CONNECT_EVENT,onStartClient)
Code:
import viz
import viznet
import vizact
viz.go()
SERVER = 'MASTER'
HANDSHAKE = viznet.id('ConnectHandshake')
def ConnectServer(server,timeout=2.0):
d = viz.Data(connected=False)
if viznet.client.connect(server):
def _handshake(e):
d.connected = True
cb = vizact.addCallback(HANDSHAKE,_handshake)
expire = viz.tick() + timeout
while not d.connected and viz.tick() < expire:
viz.waitTime(0.1)
viz.update(viz.UPDATE_NETWORK)
cb.remove()
return d.connected
if ConnectServer(SERVER):
print 'Connected'
else:
print 'Not Connected'
|
![]() |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Connection problems from MotionBuilder to PPT | nachac | Precision Position Tracker (PPT) | 2 | 07-27-2010 08:29 AM |
| problems nagivating around | ruby21 | Vizard | 2 | 05-18-2010 03:22 PM |
| Problems loading WRL file | DrunkenBrit | Vizard | 2 | 01-29-2009 12:58 AM |
| Problems Importing VRML Files | oscar | Vizard | 4 | 10-13-2004 05:42 PM |
| Problems with lighting in 2.0 | murm | Vizard | 6 | 04-21-2004 09:59 AM |