WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 05-16-2011, 04:49 AM
moneim230 moneim230 is offline
Member
 
Join Date: Oct 2009
Posts: 18
Multi User Environment

i want to create a multi user environment between several users that allows them to chat and watch the same environment together.
i tried this code from vizard reference but it did not work!
Server:
Code:
import viz
import viznet
viz.go()
viz.clearcolor(.2,.2,.4)

viz.MainView.setPosition(70,45,-60)
viz.MainView.lookat(0,0,10)

objectList = ['duck.wrl','logo.wrl','vcc_male.cfg','vcc_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) # Alert other clients
    objects[e.sender].remove() # Remove object from our 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].setEuler(e.ori)
    except KeyError: # If key doesn't exist add the user's object
        objects[e.sender] = viz.add(objectList[e.object],scale=[2,2,2],pos=e.pos,euler=e.ori)
        objects[e.sender].tooltip = e.sender # Sets the tool tip for this object
viz.callback(UPDATE,update)

# Tool Tip
import viztip
tth = viztip.ToolTip()
tth.start()
tth.setDelay(0)

# Chat Stuff
def updateChat(msg): # Function to update the chat display
    text.message('\n'.join(text.getMessage().split('\n')[1:])+'\n'+msg)

text = viz.addText('\n\n\n\n',viz.SCREEN) # Add to screen
text.alignment(viz.TEXT_LEFT_BOTTOM)
text.fontSize(25)
text.setPosition(.05,.08)

input = viz.addText('> _',viz.SCREEN) # Add to screen
input.fontSize(25);
input.setPosition(.032,.05)
input.visible(0) # We only want visible when in type mode

def onChat(e): # Update the message display
    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:
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','vcc_female.cfg']
obj_choice=viz.choose('Connected. Select your character',objectList)

def update(e):
    if e.client != viz.getComputerName():
        try:
            objects[e.client].setPosition(e.pos)
            objects[e.client].setEuler(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_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)

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.setPosition(.05,.08)

input = viz.addText('> _',viz.SCREEN)
input.fontSize(25)
input.setPosition(.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.getComputerName(),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)
any suggestions?
Reply With Quote
  #2  
Old 05-16-2011, 01:55 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
Are the machines able to ping each other? Have you tried disabling any firewalls and virus scanners to see if that makes a difference?
Reply With Quote
  #3  
Old 05-16-2011, 03:56 PM
moneim230 moneim230 is offline
Member
 
Join Date: Oct 2009
Posts: 18
Quote:
Originally Posted by Jeff View Post
Are the machines able to ping each other? Have you tried disabling any firewalls and virus scanners to see if that makes a difference?
yes they ping each other and the firewalls are disabled.
i run the server code first then when i run the client code and write the server name it says "connected" and i select the character but the server does not see the client character navigating.
i also tried 2 clients connected to a server but they don't see each other and the server can't see them
Reply With Quote
  #4  
Old 05-16-2011, 04:31 PM
moneim230 moneim230 is offline
Member
 
Join Date: Oct 2009
Posts: 18
Quote:
Originally Posted by Jeff View Post
Are the machines able to ping each other? Have you tried disabling any firewalls and virus scanners to see if that makes a difference?
chatting works too
the problem is that the characters don't appear
Reply With Quote
  #5  
Old 05-17-2011, 04:10 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
Sorry about that, there was missing code in the documentation. If you add the following to the client script does it work for you?
Code:
def sendUpdate(): 
    ori= viz.MainView.getEuler()
    pos = viz.MainView.getPosition()
    viznet.client.sendAll(UPDATE,client=viz.getComputerName(),object=obj_choice,pos=pos,ori=ori)
vizact.ontimer(.05,sendUpdate)
Reply With Quote
  #6  
Old 05-17-2011, 05:56 PM
moneim230 moneim230 is offline
Member
 
Join Date: Oct 2009
Posts: 18
Thumbs up

Quote:
Originally Posted by Jeff View Post
Sorry about that, there was missing code in the documentation. If you add the following to the client script does it work for you?
Code:
def sendUpdate(): 
    ori= viz.MainView.getEuler()
    pos = viz.MainView.getPosition()
    viznet.client.sendAll(UPDATE,client=viz.getComputerName(),object=obj_choice,pos=pos,ori=ori)
vizact.ontimer(.05,sendUpdate)
thx Jeff it works now.
i hope vizard 4.0 documentation will get updated with this missing code.
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
orthographic projection in a head-tracked cave environment michaelrepucci Vizard 5 12-14-2011 10:29 AM
Controlling User Input ohad Vizard 1 03-15-2010 05:16 PM
Navigating an avatar using mouse position(2D) in 3D environment james007 Vizard 1 10-16-2009 11:29 AM
Getting a mirror to work in any environment Frank Verberne Vizard 5 03-27-2008 08:21 AM
environment maps, scenes, and you! vadrian Vizard 1 01-12-2005 04:04 PM


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


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