WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Generic UDP or TCP/IP function (https://forum.worldviz.com/showthread.php?t=1126)

Steve_HT 06-22-2007 04:58 PM

Generic UDP or TCP/IP function
 
Does Vizard have in place in a generic TCP/IP protocol as part of the networking package, or is it presently configured only for the Vizard Networking communications?

If there is not such a protocol, how difficult would it be to create? I'd like to port data from a set of XServes across either TCP/IP or UDP to drive the hand and other objects in my environment.

farshizzo 06-22-2007 05:04 PM

Hi,

The networking feature built-in to Vizard uses UDP, but the data is "pickled" before it is sent. This makes it difficult to communicate with non-Python programs, which I assume is what you are doing. If you want to receive raw data over a socket then you can use the Python socket library. Here is some sample code:
Code:

import viz
viz.go()

import socket

#The maximum amount of data to receive at a time
MAX_DATA_SIZE = 1024

#The port to send/receive data on
PORT = 4999

#Get the name of this computer
COMPUTER_NAME = socket.gethostname()

#Get the IP address of this computer
COMPUTER_IP_ADDRESS = socket.gethostbyname('localhost')

#Create a socket to send data over
OutSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
OutSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

#Create a socket to receive data from
InSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
InSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
InSocket.bind(('', PORT))
InSocket.setblocking(0)

def SendData(data):
        OutSocket.sendto(data,(COMPUTER_IP_ADDRESS,PORT))
       
def ReceiveData():
        try:
                return InSocket.recv(MAX_DATA_SIZE)
        except socket.error:
                #Insert error handling code here
                pass

vizact.onkeydown(' ',SendData,'hello there')

def CheckSocket():
        #Try to receive data from socket
        data = ReceiveData()
        if data:
                print 'Received Message:',data
vizact.ontimer(0,CheckSocket)



All times are GMT -7. The time now is 05:14 AM.

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