WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rating: Thread Rating: 23 votes, 5.00 average. Display Modes
  #1  
Old 05-05-2007, 07:03 PM
pattie pattie is offline
Member
 
Join Date: Aug 2006
Posts: 32
Client Server Networking Problem

Hi guys:

I have been playing around with the client server example.
I have been experiencing a problem for a few days now:

I am using the server script and two clients to connect to the server.

Every time a client connects to the server, the server correctly receives the UPDATE event but the connected clients never receive it, therefore the client's update() function is never called and the client never sees the other connected clients. I do not understand why:
- the client to server communication works fine;
- the server to client communication does not work;
- the client to client communication does not work (viznet.client.sendAll).

I have disabled any possible firewall or antivirus installed on the machines.

Am I doing something wrong?

Thanks
Patrick
Reply With Quote
  #2  
Old 05-07-2007, 10:30 AM
Gladsomebeast Gladsomebeast is offline
Member
 
Join Date: Mar 2005
Location: Isla Vizta, CA
Posts: 397
Try pinging the server computer from the clients using the server's logical name. Vizard uses the computer's logical name to determan their IP address.
__________________
Paul Elliott
WorldViz LLC
Reply With Quote
  #3  
Old 05-07-2007, 11:48 AM
pattie pattie is offline
Member
 
Join Date: Aug 2006
Posts: 32
Client server Networking

Both clients can ping the server using either the IP address or the name
Reply With Quote
  #4  
Old 05-09-2007, 12:05 PM
pattie pattie is offline
Member
 
Join Date: Aug 2006
Posts: 32
Client Server networking problem

Hi guys:

I think you might want to take a look at the sendAll function. It looks like it does not send the events to the clients (server works fine).

Is it a bug in the client server code or did I forget something?

Patrick
Reply With Quote
  #5  
Old 05-09-2007, 12:52 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Are you using Vizard 2.5? Because the viznet module will only work with Vizard 3.0
Reply With Quote
  #6  
Old 05-10-2007, 01:41 PM
pattie pattie is offline
Member
 
Join Date: Aug 2006
Posts: 32
Cleint Server Networking problem

I am using the very last version on all machines
Reply With Quote
  #7  
Old 05-10-2007, 01:48 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
I tested the sendAll command and it worked fine here. Can you post the scripts you are using? Also, in the future, please post Vizard 3.0 related question in the Vizard 3.0 forum.
Reply With Quote
  #8  
Old 05-11-2007, 03:25 PM
pattie pattie is offline
Member
 
Join Date: Aug 2006
Posts: 32
Client Server Networking problem

Sorry about posting this thread in the wrong place.

Here is the code I am using:

SERVER SERVER SERVER SERVER:

import viz
import viznet
viz.go()
viz.clearcolor(.2,.2,.4)
view = viz.get(viz.MAIN_VIEWPOINT)
view.setPosition(70,45,-60)
view.lookat(0,0,10)
objectList = ['duck.wrl', 'logo.wrl', 'male.cfg', 'female.cfg' ]
maze = viz.add('tankmaze.wrl')
objects = {}
UPDATE = viznet.id('update')
CLIENT_DISCONNECTED = viznet.id('client_disconnected')
CHAT = viznet.id('chat')
viznet.server.start(port_in=14950, port_out = 14951)
def onStartClient(e):
print '** Client joined:', e.sender
viz.callback(viznet.CLIENT_CONNECT_EVENT, onStartClient)
def onStopClient(e):
print '** Client left:', e.sender
viznet.server.send(CLIENT_DISCONNECTED, client=e.sender)
objects[e.sender].remove() #Remove object from map
del objects[e.sender] #Delete user from array
viz.callback(viznet.CLIENT_DISCONNECT_EVENT, onStopClient)
def update(e):
try:
objects[e.sender].setPosition(e.pos)
objects[e.sender].rotate(e.ori)
except KeyError:
objects[e.sender] = viz.add(objectList[e.object],scale=
2,2,2],pos=e.pos,euler=e.ori)
objects[e.sender].tooltip = e.sender
viz.callback(UPDATE, update)

import viztip
tth = viztip.ToolTip()
tth.start()
tth.setDelay(0)

def updateChat(msg):
text.message('\n'.join(text.getMessage().split('\n ')[1:])+'\n'+msg)

text = viz.addText('\n\n\n\n', viz.SCREEN) # send 4 carriage returns to screen
text.alignment(viz.TEXT_LEFT_BOTTOM)
text.fontSize(25)
text.translate(0.05,0.08)

input = viz.addText('>_', viz.SCREEN) # Add Chat prompt
input.alignment(viz.TEXT_LEFT_BOTTOM)
input.fontSize(25)
input.translate(0.032,0.05)
input.visible(0) #Only visible when in type mode

def onChat(e):
updateChat(e.client+': '+e.chat)
viz.callback(CHAT,onChat)

talking = False
def onKeyDown(key):
global talking
if key == 'y' and not talking: # Start talking mode
talking = True
input.message('> _')
input.visible(1)
elif key == viz.KEY_ESCAPE and talking: # Exit talking mode
talking = False
input.visible(0)
return True
elif talking and key == viz.KEY_RETURN: # Send message
talking = False
viznet.server.send(CHAT,client='SERVER',chat=input .getMessage()[2:-1])
input.visible(0)
# Update display with our message
updateChat('SERVER'+': '+input.getMessage()[2:-1])
elif talking and key == viz.KEY_BACKSPACE: # Delete a character
if len(input.getMessage()) > 3:
input.message(input.getMessage()[:-2]+'_')
elif len(key) > 1: # Handle special keys
return False
elif talking and 32 <= ord(key) <= 126: # Input message
input.message(input.getMessage()[:-1]+key+'_')
viz.callback(viz.KEYDOWN_EVENT,onKeyDown,priority=-6)

CLIENT CLIENT CLIENT CLIENT

import viz
import viznet
import vizinfo
viz.go()
viz.clearcolor(.2,.2,.4)
maze = viz.add('tankmaze.wrl')
objects = {}
SEND_UPDATE_TIMER = 1
UPDATE = viznet.id('update')
CLIENT_DISCONNECTED = viznet.id('client_disconnected')
CHAT = viznet.id('chat')
SERVER_NAME=viz.input('Enter Server Name')
while not viznet.client.connect(SERVER_NAME,port_in=14951,po rt_out=14950):
if viz.ask('Could not connect to ' + SERVER_NAME + ' would you like to try another?'):
SERVER_NAME=viz.input('Enter Server Name')
else:
viz.quit()
break

objectList = ['duck.wrl','logo.wrl','male.cfg','female.cfg']
obj_choice=viz.choose('Connected. Select your character',objectList)

def mytimer(num):
if num == SEND_UPDATE_TIMER:
ori= viz.get(viz.HEAD_ORI)
pos = viz.get(viz.HEAD_POS)
viznet.client.sendAll(UPDATE,client=viz.getCompute rName
(),object=obj_choice,pos=pos,ori=ori)
viz.callback(viz.TIMER_EVENT, mytimer)
viz.starttimer(SEND_UPDATE_TIMER, .05, -1)

def update(e):
if e.client != viz.getComputerName():
try:
objects[e.client].setPosition(e.pos)
objects[e.client].rotate(e.ori)
except KeyError:
objects[e.client] = viz.add(objectList[e.object],scale=[2,2,2],pos=e.pos,euler=e.ori)
objects[e.client].tooltip = e.client
viz.callback(UPDATE,update)

def client_disconnected(e):
objects[e.client].remove()
del objects[e.client]
viz.callback(CLIENT_DISCONNECTED,client_disconnect ed)

def onStopServer(e):
print 'Disconnected from server'
viz.quit()
viz.callback(viznet.SERVER_DISCONNECT_EVENT,onStop Server)

import viztip
tth = viztip.ToolTip()
tth.start()
tth.setDelay(0)

def updateChat(msg):
text.message('\n'.join(text.getMessage().split('\n ')[1:])+'\n'+msg)

text = viz.addText('\n\n\n\n',viz.SCREEN)
text.alignment(viz.TEXT_LEFT_BOTTOM)
text.fontSize(25)
text.translate(.05,.08)

input = viz.addText('> _',viz.SCREEN)
input.fontSize(25)
input.translate(.032,.05)
input.visible(0)

def onChat(e):
updateChat(e.client+': '+e.chat)
viz.callback(CHAT,onChat)

talking = False
def onKeyDown(key):
global talking
if key == 'y' and not talking:
talking = True
input.message('> _')
input.visible(1)
elif key == viz.KEY_ESCAPE and talking:
talking = False
input.visible(0)
return True
elif talking and key == viz.KEY_RETURN:
talking = False
viznet.client.sendAll(CHAT,client=viz.getComputerN ame(),chat=input.getMessage()[2:-1])
input.visible(0)
elif talking and key == viz.KEY_BACKSPACE:
if len(input.getMessage()) > 3:
input.message(input.getMessage()[:-2]+'_')
elif len(key) > 1:
return False
elif talking and 32 <= ord(key) <= 126:
input.message(input.getMessage()[:-1]+key+'_')
viz.callback(viz.KEYDOWN_EVENT,onKeyDown,priority=-6)
Reply With Quote
  #9  
Old 05-11-2007, 03:50 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

Can you repost the code using the special code tags?
HTML Code:
[code]insert code here[/code]
This will preserve the indentation in the code.
Reply With Quote
  #10  
Old 05-11-2007, 04:03 PM
pattie pattie is offline
Member
 
Join Date: Aug 2006
Posts: 32
Client Server Networking problem

No need for the chat management code, I experimented without it.

SERVER SERVER SERVER SERVER
Code:
import viz
import viznet
viz.go()
viz.clearcolor(.2,.2,.4)
view = viz.get(viz.MAIN_VIEWPOINT)
view.setPosition(70,45,-60)
view.lookat(0,0,10)

objectList = ['duck.wrl', 'logo.wrl', 'male.cfg', 'female.cfg' ] 
maze = viz.add('tankmaze.wrl')
objects = {}

UPDATE = viznet.id('update')
CLIENT_DISCONNECTED = viznet.id('client_disconnected')
CHAT = viznet.id('chat')
viznet.server.start(port_in=14950, port_out = 14951)
def onStartClient(e):
	print '** Client joined:', e.sender
viz.callback(viznet.CLIENT_CONNECT_EVENT, onStartClient)
def onStopClient(e):
	print '** Client left:', e.sender
	viznet.server.send(CLIENT_DISCONNECTED, client=e.sender)
	objects[e.sender].remove() #Remove object from map
	del objects[e.sender] #Delete user from array
viz.callback(viznet.CLIENT_DISCONNECT_EVENT, onStopClient)

def update(e):
	try:
		objects[e.sender].setPosition(e.pos)
		objects[e.sender].rotate(e.ori)
	except KeyError:
		objects[e.sender] = viz.add(objectList[e.object],scale=[2,2,2],pos=e.pos,euler=e.ori)
		objects[e.sender].tooltip = e.sender
viz.callback(UPDATE, update)

import viztip
tth = viztip.ToolTip()
tth.start()
tth.setDelay(0)
CLIENT CLIENT CLIENT CLIENT
Code:
import viz
import viznet
import vizinfo
viz.go()
viz.clearcolor(.2,.2,.4)
maze = viz.add('tankmaze.wrl')
objects = {}
SEND_UPDATE_TIMER = 1
UPDATE = viznet.id('update')
CLIENT_DISCONNECTED = viznet.id('client_disconnected')
CHAT = viznet.id('chat')
SERVER_NAME=viz.input('Enter Server Name')
while not viznet.client.connect(SERVER_NAME,port_in=14951,port_out=14950):
    if viz.ask('Could not connect to ' + SERVER_NAME + ' would you like to try another?'):
        SERVER_NAME=viz.input('Enter Server Name')
    else:
        viz.quit()
        break

objectList = ['duck.wrl','logo.wrl','male.cfg','female.cfg']
obj_choice=viz.choose('Connected. Select your character',objectList)

def mytimer(num): 
    if num == SEND_UPDATE_TIMER:
        ori= viz.get(viz.HEAD_ORI)
        pos = viz.get(viz.HEAD_POS)
        viznet.client.sendAll(UPDATE,client=viz.getComputerName(),object=obj_choice,pos=pos,ori=ori)
viz.callback(viz.TIMER_EVENT, mytimer)
viz.starttimer(SEND_UPDATE_TIMER, .05, -1)

def update(e):
    if e.client != viz.getComputerName():
        try:
            objects[e.client].setPosition(e.pos)
            objects[e.client].rotate(e.ori)
        except KeyError:
            objects[e.client] = viz.add(objectList[e.object],scale=[2,2,2],pos=e.pos,euler=e.ori)
            objects[e.client].tooltip = e.client
viz.callback(UPDATE,update)

#The client_disconnected function performs some simple cleanup when another client disconnects, 
#and the onStopServer function closes the client.
def client_disconnected(e):
    objects[e.client].remove()
    del objects[e.client]
viz.callback(CLIENT_DISCONNECTED,client_disconnected)

def onStopServer(e):
    print 'Disconnected from server'
    viz.quit()
viz.callback(viznet.SERVER_DISCONNECT_EVENT,onStopServer)

import viztip
tth = viztip.ToolTip()
tth.start()
tth.setDelay(0)
Reply With Quote
  #11  
Old 05-11-2007, 04:25 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

I just tested your script here, running one server with two clients and it worked fine. You said that server to client communication does not work. Have you tried a simple viznet example that does not use sendAll, to make sure that this is not a problem with your network setup?

I've included a very basic viznet example. In this example, whenever a client presses the spacebar their background color should change. Also, the server will print out a message every time a client connects/disconnects. If this does not work then there might be a problem with your network setup.

SERVER SERVER SERVER SERVER
Code:
import viz
viz.go()

import viznet

#Create custom event IDs
CLIENT_KEYDOWN = viznet.id('ClientKeyDown')
SET_CLEAR_COLOR = viznet.id('SetClearColor')

#Start server
viznet.server.start()

colors = [viz.RED,viz.BLUE,viz.BLACK,viz.ORANGE,viz.YELLOW,viz.GREEN,viz.GRAY]
curColor = 0

#When client connects, send them current color
def onStartClient(e):
	viznet.server.sendClient(e.sender,SET_CLEAR_COLOR,color=colors[curColor])
	print '** Client joined:',e.sender
viz.callback(viznet.CLIENT_CONNECT_EVENT,onStartClient)

#Print out when client leaves
def onStopClient(e):
	print '** Client left:',e.sender
viz.callback(viznet.CLIENT_DISCONNECT_EVENT,onStopClient)

#When client presses space key, change color and notify all clients
def onKeydownClient(e):
	global curColor
	if e.keydown == ' ':
		curColor = (curColor + 1) % len(colors)
		viznet.server.send(SET_CLEAR_COLOR,color=colors[curColor])
viz.callback(CLIENT_KEYDOWN,onKeydownClient)
CLIENT CLIENT CLIENT CLIENT
Code:
import viz
viz.go()

import viznet

#Create custom event IDs
CLIENT_KEYDOWN = viznet.id('ClientKeyDown')
SET_CLEAR_COLOR = viznet.id('SetClearColor')

#Connect to server
viznet.client.connect(viz.input('Enter Server Name'))

#Send message to server when space key is pressed
vizact.onkeydown(' ',viznet.client.send,CLIENT_KEYDOWN,keydown=' ')

#Change color on server event
def onClearColorClient(e):
	viz.clearcolor(e.color)
viz.callback(SET_CLEAR_COLOR,onClearColorClient)

#Print out message if disconnected from server
def onStopClient(e):
	print '** Disconnected from server'
viz.callback(viznet.SERVER_DISCONNECT_EVENT,onStopClient)
Reply With Quote
  #12  
Old 05-11-2007, 05:06 PM
pattie pattie is offline
Member
 
Join Date: Aug 2006
Posts: 32
Client Server Networking problem

If it works on your side, then it definitively is something with my network config.
I'll keep on playing around.

Thanks
Patrick
Reply With Quote
  #13  
Old 07-04-2013, 10:11 AM
iva iva is offline
Member
 
Join Date: Mar 2013
Posts: 10
Okay, this is a 6 years old post, but I have had the same problem already twice, so next time when I google for the solution, I will find this post. I don't know if this would solve OP's problem, but I had the same situation, communication worked from client to server, but server to client never worked. It turns out, if I use server's machine name instead of server's IP address, miraculously everything started to work.
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 09:41 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Copyright 2002-2018 WorldViz LLC