WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Client Server Networking Problem (https://forum.worldviz.com/showthread.php?t=5964)

mihirradia 02-26-2017 02:34 PM

Client Server Networking Problem
 
1 Attachment(s)
Hi,
I'm using the example of Client and Server networking script for my problem. When I run the Server script it runs with no errors. But when I run the Client scripts I get the following error. Could you tell me what is this error? And how can I solve it?

I would be grateful, if you could help me out as soon as possible.

Thanks,
Mihir

Jeff 02-27-2017 05:54 AM

Vizard serializes the arguments to a string and sends that to the remote computer. To serialize the data, Vizard uses the cPickle library that comes with Python. Perhaps you are trying to send an object that cPickle does not recognize.

It's difficult to tell without having a simple example that reproduces the error. For help with code on the forum it's always best to follow the posting Vizard code guidelines.

mihirradia 02-27-2017 09:12 AM

1 Attachment(s)
Hi Jeff,
Its really difficult for me to produce an example that replicates my error. I have attached my code with as short as possible. As I am using the vizconnect tool. I have also attached the vizconnect_desktop.py

my code is
Code:

import csv
import viz
import vizfx
import vizconnect
import vizact
import makingCSVFile
import zspace
import vizshape
import vizcam
import vizinfo
import viznet
import vizinput
from tools import collision_test

filePath = vizinput.fileOpen(filter=[('DAE Files','*.dae'),('OSG Files','*.ive;*.osgb;*.osg'),('VRML Files','*.wrl'),('All File','*.*')],directory='3DModels')
logoss1=None
Listchilderen=[]
GrabedObject=None
ModelsList=[]
ModelsList.append(logoss1)
DissasembeldPart=False
models=None
grabItems=None
class ExplosiveModel(viz.VizNode):
        """ creates a model with a given dae file and gets parts and moves them on specified axes """

        def __init__(self, rowData):
               
                self.isu = vizfx.addChild(filePath)
                logoss1 = self.isu
                Listchilderen = logoss1.getNodeNames()
                viz.VizNode.__init__(self, self.isu.id)
                self.scale = .035125 #this scale is determined by doc (dividing model size by .035, we get desired size)
                self.isu.setScale([self.scale]*30)
                self.current = 0 #index of current
                self.rowData = rowData[:]
                self.layerParents = []
                self.partDict = {}
                for tool in vizconnect.getToolsWithMode('Grabber'):
                        tool.getRaw().setCollisionTester(collision_test.Distance(node=tool.getRaw(), distanceThreshold=1000))

def initZSpace():
        import zspace

        viz.setMultiSample(8)
        viz.clearcolor(viz.SLATE)

        #initialize zSpace display
        display = zspace.init()

        #Scale up the zSpace display to avoid having to
        #scale down all the models to fit within the display viewport
        display.setScale(200)

        #save handle to wand tracker
        wandTracker = zspace.getWandTracker()
        wandTracker.setLedEnabled(True)


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


#___________________________________________________________________________________
#-----------------------------------------------------------------------------------       
def update(e):
        # need to edit this
        global grabbedObject
        global grabItems,models, filePath
        global ModelsList,logoss1,DissasembeldPart,Listchilderen, xmodel
        if e.client != viz.getComputerName():
                try:
                       
                       
                        if e.DisAssPart==True and DissasembeldPart==False:
                               
                               

                                for i in Listchilderen:
                                        if i.startswith("Inst"):
                                                xmodel=logoss1.getChild(i)
                                               
                                                ModelsList.append(xmodel)
                                                               
                                models = viz.cycle(ModelsList)
                                grabItems = set(models)
                                DissasembeldPart=True
                                e.GrabObj.setPosition(e.pos)
                                e.GrabObj.setEuler(e.ori)
                               
                        elif e.DisAssPart==False and DissasembeldPart==True:
                               
                                for i1 in ModelsList:
                                        i1.remove()
                                logoss1.remove()
                                logoss1 = viz.add(filePath)
                                logoss1.setPosition([0,0,0])
                                logoss1.setScale([0.1,0.1,0.1])
                                models = viz.cycle([logoss1])
                                grabItems = set(models)
                                DissasembeldPart=False
                                e.GrabObj.setPosition(e.pos)
                                e.GrabObj.setEuler(e.ori)
                               
               
                               
                        else:
                               
                                e.GrabObj.setPosition(e.pos)
                                e.GrabObj.setEuler(e.ori)
                               
                                               
                except KeyError:
                        print 'errooooooooor'
                #print '-------------update client'
viz.callback(UPDATE,update)
#___________________________________________________________________________________
#-----------------------------------------------------------------------------------
def client_disconnected(e):
        viz.callback(CLIENT_DISCONNECTED,client_disconnected)
#___________________________________________________________________________________
#-----------------------------------------------------------------------------------
def sendUpdate():
        global GrabedObject, DissasembeldPart
        if GrabedObject!=None:
                ori= GrabedObject.getEuler()
                pos = GrabedObject.getPosition()
                GrabObj=GrabedObject
                DisAssPart=DissasembeldPart
       
                viznet.client.sendAll(UPDATE,client=viz.getComputerName(),pos=pos,ori=ori,GrabObj=GrabObj,DisAssPart=DisAssPart )
       
vizact.ontimer(.001,sendUpdate)
#___________________________________________________________________________________
#-----------------------------------------------------------------------------------
def onStopServer(e):
 
    viz.quit()
viz.callback(viznet.SERVER_DISCONNECT_EVENT,onStopServer)

#___________________________________________________________________________________
#-----------------------------------------------------------------------------------

#alternatively, you could use the desktop                             
vizconnect.go('vizconnect_desktop.py') #desktop vizconnect setup

rowData = []
#read csv data for part numbers per step
with open('names.csv', 'rb') as csvfile:
        reader = csv.reader(csvfile)
        for row in reader:
                rowData.append([row[0], row[1], row[2].split()])
print rowData

#Set the animation speed and mode
SPEED = 1200
MODE = viz.SPEED
ROTATE_MODE = viz.PIVOT_ROTATE

def AnimateView(pos):
        global GrabedObject
        action = vizact.goto(pos,SPEED,MODE,pivot=vizconnect.getViewpointDict(),rotate_mode=ROTATE_MODE)
        GrabedObject = vizconnect.getTransport().getRaw()
        vizconnect.getTransport().getNode3d().runAction(action)
       
model = ExplosiveModel(rowData)
model.setScale([0.02]*3)

viz.clearcolor(viz.GRAY) #change background color if desired

#Start off by moving to the first location
AnimateView([0,2,-15])


mihirradia 02-27-2017 10:34 AM

It's urgent. Please help me out as soon as possible.

Jeff 02-28-2017 12:09 AM

It looks like the transport object can't be sent using the network command and causes the cPickle error. Try sending the position and orientation of the transport every frame to all clients. On the receiving end, set the position and orientation of the transport:

Code:

transport.setPosition(pos)
transport.setEuler(euler)


mihirradia 02-28-2017 09:32 AM

Hi Jeff,
I'm sorry I'm new to this Vizard. What changes should I make in my update function in my Client? Do you want me to change the e.GrabObject.setPosition(pos) to transport.setPosition(pos) correct on the client script? What changes do I need to make in the server script?
I'm sorry for such silly question, but I new to programming as well. I am really sorry for the inconvenience caused

Jeff 03-01-2017 12:46 AM

Sorry, it's difficult to help because I don't really understand the code or what you are trying to do. Troubleshooting custom code is beyond the scope of what we can help with on the forum.

I'm not sure this is going to make things work the way you want but to avoid the error remove the transport object, which is called 'GrabObj' in the line below:

Code:

viznet.client.sendAll(UPDATE,client=viz.getComputerName(),pos=pos,ori=ori,GrabObj=GrabObj,DisAssPart=DisAssPart )
It seems like you are already sending the position and orientation of the transport and there is only one transport used in the script. So in your function that receives the network data, get a handle to that transport and then call set position and orientation on it.

Maybe there's an easier way of setting this up. Can you explain generally how your application is supposed to work? We can't necessarily provide code but may have suggestions.

mihirradia 03-01-2017 04:07 PM

Hi Jeff,
I have a CAD model that is uploaded in the system. After that I am using the orientation and flying transports from the vizconnect tool to rotate the object in the virtual environment. Now, all I wanted is to do networking between two systems. For example, If I rotate the model in upward direction using transports in the client system, the information should get updated in the server system. I'm able to connect the systems the server displays the message of the client joined and left. But the client is not able to update the information and it is showing me the cPickle error.

Jeff 03-02-2017 04:37 AM

Does the example server/client scripts posted here work for you?

mihirradia 03-06-2017 12:15 PM

1 Attachment(s)
Hi Jeff,
The sample scripts are working. I did what you told me to do to remove the transport object i.e "GrabObj" after doing that I am getting the below error.

Jeff 03-06-2017 11:23 PM

Since you are no longer sending the GrabObj object, you can't receive it in the update function. You could try getting a handle to the transport in your script using the following:

Code:

transport = vizconnect.getTransport().getRaw()
Then set its position and orientation to the values you receive in the update function.

I can't guarantee that this will help or not. As I mentioned before, to get help with code on the forum it needs to follow the guidelines for posting code. For more in depth assistance, you might contact sales@worldviz.com and they can provide options for custom development and priority support.


All times are GMT -7. The time now is 12:01 PM.

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