- Home /
Question by
tohmjudson · Jan 14, 2014 at 04:07 AM ·
cloneudpmax
Optimization Help...Sending UDP Data from Clones to Max
HI all,
I have the following script (below), which is sending cloned planet prefab position data from Unity into Max via UDP. I am receiving all data fine, as long as I only have 3 or 4 clones. When I get to 9, everything bogs down hard. While all the data is getting there, it is behind by several seconds.
For the record: I need this to be on clones that will be generated by visitors to the exibition. I couldn't get the mu tools from VT to work with clones.
For testing, you can attach this to any object and receive in Max with a mxj net.udp.recv @port 7474
Can any of you guru's help me optimize this to lose the drag? Should I funnel or limit the packets?
Thank you so much in advance!
using UnityEngine;
using System.Net.Sockets;
using System.Net;
using System.Text;
using System.Collections;
public class UdpServer_Position : MonoBehaviour
{
public string hostName = "127.0.0.1";
public int port = 7474;
private UdpClient server;
private ASCIIEncoding byteEncoder = new ASCIIEncoding();
// Real-time data //
void Update ()
{
server = new UdpClient(hostName, port);
server.Connect( hostName, port );
SendFloat (gameObject.name + " " + "X", transform.position.x);
SendFloat (gameObject.name + " " + "Y", transform.position.y);
SendFloat (gameObject.name + " " + "Z", transform.position.z);
}
// Sends an Float value to Max //
public void SendFloat(string maxRouteArgument, float val)
{
string message = maxRouteArgument + " " + val;
byte[] messageBytes = byteEncoder.GetBytes( message );
SendBytes( messageBytes );
}
private void SendBytes( byte[] message )
{
try
{
server.Send( message, message.Length );
}
catch( SocketException e )
{
Debug.LogError( e );
}
}
// Close server on exit //
void OnApplicationQuit()
{
server.Close ();
}
}
Comment