Hi,
I am trying to build a simple car simulator for Ubuntu 14.04 that will take in inputs through UDP. If I use C# as the scripting language to call the UDP APIs, will the simulator able to be run in Ubuntu 14.04? If not, may I know how should I go about it to achieve it?
Thanks.
Sure, I don’t see why not.
Thanks for the prompt respond. In fact, these few days I have been trying to work on the networking end on unity. Although there was no error in the connection creation, I was not able to send a packet out as it stated that there is a Wrong Connection fault. May I know what is it that is causing this error?
I have modified the roll a ball tutorial (the script under PlayerController.cs) to do my testing.
The modified code was attached for reference.
Thanks.
public struct data_t
{
public double x;
public double y;
public byte[] Serialise()
{
byte[] arr;
MemoryStream ms = new MemoryStream();
arr = System.BitConverter.GetBytes(this.x);
ms.Write(arr, 0, arr.Length);
arr = System.BitConverter.GetBytes(this.y);
ms.Write(arr,0,arr.Length);
arr = ms.ToArray();
return arr;
}
}
public class PlayerController : MonoBehaviour {
public float speed;
public Text countText;
public Text winText;
public Text statusText;
private Rigidbody rb;
private int count;
private int reliableChannelId;
private int hostId;
private int connectionId;
private ConnectionConfig connectionConfig;
private HostTopology topology;
// Use this for initialization
void Start ()
{
rb = GetComponent<Rigidbody> ();
count = 0;
SetCountText ();
winText.text = "";
// Initializing the Transport Layer with no arguments (default settings)
NetworkTransport.Init();
// Configuring
connectionConfig = new ConnectionConfig();
reliableChannelId = connectionConfig.AddChannel (QosType.Unreliable);
// Topology
topology = new HostTopology (connectionConfig, 10);
// Host creation
hostId = NetworkTransport.AddHost(topology, 10000);
// Connection id creation
byte error;
connectionId = NetworkTransport.Connect(hostId, "127.0.0.1", 10000, 0, out error);
switch ((NetworkError)error)
{
case NetworkError.Ok:
statusText.text = "Connection Ok!!";
// statusText.text = connectionId.ToString();
break;
default:
statusText.text = "Error!!";
break;
}
}
// Update is called once per frame (before rendering a frame)
// This is also where most of our game code will go
void Update ()
{
data_t pose;
pose.x = 10.0;
pose.y = 20.0;
byte err = 0;
byte[] buffer = pose.Serialise();
NetworkTransport.Send (hostId, connectionId, reliableChannelId, buffer, buffer.Length, out err);
switch ((NetworkError)err)
{
case NetworkError.Ok:
statusText.text = "Ok!!";
break;
case NetworkError.WrongHost:
statusText.text = "Wrong host!!";
break;
case NetworkError.WrongConnection:
statusText.text = "Wrong connection!!";
break;
default:
statusText.text = "Error!!";
break;
}
// statusText.text = buffer.Length.ToString();
}
}