Hi,
I am working on a project for data communication between hololens and PC. The hololens as client, sending camera pose and virtual objects pose, PC as server receiving the data and sending back with adding updates. The connection I create is based on low level scripting with using Networkclient and Networkserver class. It works fine for most of the time, But sometimes the connection will be interrupted by the Unknown Message id with a large number, I am confused about this. I code specific connection id in the beginning and have no idea about this id come from. Does anyone know about my problem?
Thanks!
structure:
hololens–client
Sending : camera pose, virtual contents pose (to same port, but with different ids )
Receiving. update virtual contents pose
PC --server
Sending: update virtual contents pose(with another id )
Receiving: camera pose, virtual contents pose
are you using the relay server? back when i was using the relay server, the connection would abruptly terminate in a weird way if i was using too much bandwidth.
Hi, Soooorry for my late response! I am not sure I am using relay server or not. Here the follow is my partial code for describing the problem.
Client:
// initialization
public static NetworkClient client;
public string Serverip = "192.168.1.100";
public int Serverport = 2345;
//Message type
public class MyMsgType
{
public static short Camerapose = MsgType.Highest + 100;
public static short Cubepose = MsgType.Highest + 200;
public static short backpose = MsgType.Highest + 300;
};
// Message base
public class Positionmsg : MessageBase
{
public Matrix4x4 transformmatrix;
public double deltatime;
public bool flag;
public int timeindex;
}
public class Cameramsg : MessageBase
{
public Vector3 cameraP;
public Quaternion cameraQ;
}
public class Estimatormsg : MessageBase
{
public Vector3 position;
public Quaternion rotation;
public int timeindex_back;
}
// Setup client function
void Setupclient()
{
client = new NetworkClient();
client.RegisterHandler(MsgType.Connect, OnConnected);
client.RegisterHandler(MyMsgType.backpose, Onreceiving); // receiving the message from Server
client.RegisterHandler(MsgType.Error, OnError);
client.Connect(Serverip, Serverport);
}
void OnConnected(NetworkMessage netMsg)
{
Debug.Log("Connected to server");
isAtstartup = false;
}
void Onreceiving(NetworkMessage netmsg)
{
Estimatormsg Message = netmsg.ReadMessage<Estimatormsg>();
p = Message.position;
Q = Message.rotation;
}
void OnError(NetworkMessage netMsg)
{
var errorMsg = netMsg.ReadMessage<ErrorMessage>();
Debug.Log("Error:" + errorMsg.errorCode);
}
// two sending functions, call in the update function under the different objects.
public static void Sending(Matrix4x4 result, double delta, int time_index)
{
Positionmsg msg = new Positionmsg();
msg.transformmatrix = result;
msg.deltatime = delta;
msg.flag = true;
msg.timeindex = time_index;
client.Send(MyMsgType.Cubepose, msg);
//TimeDetectdone = DateTime.Now;
}
public static void CameraSending(Vector3 p, Quaternion q)
{
Cameramsg msg = new Cameramsg();
msg.cameraP = p;
msg.cameraQ = q;
client.Send(MyMsgType.Camerapose, msg);
}
Server:
// Same initialization as the client
private int Serverport = 2345;
// message type
public class MyMsgType
{
public static short Camerapose = MsgType.Highest + 100;
public static short Cubepose = MsgType.Highest + 200;
public static short backpose = MsgType.Highest + 300;
};
//message base
public class Positionmsg : MessageBase
{
public Matrix4x4 transformmatrix;
public double deltatime;
public bool flag;
public int timeindex;
}
public class Cameramsg : MessageBase
{
public Vector3 cameraP;
public Quaternion cameraQ;
}
public class Estimatormsg : MessageBase
{
public Vector3 position;
public Quaternion rotation;
public int timeindex_back;
}
//set up server
void SetupServer()
{
NetworkServer.Reset();
if (NetworkServer.Listen(Serverport))
{
NetworkServer.RegisterHandler(MyMsgType.Camerapose, OnreceivingCamera);
NetworkServer.RegisterHandler(MyMsgType.Cubepose, Onreceiving);
}
}
//two receiving function
void Onreceiving(NetworkMessage netmsg)
{
Positionmsg Message = netmsg.ReadMessage<Positionmsg>();
Transmatrix = Message.transformmatrix;
deltaTime = Message.deltatime;
msgback.position = transform.position;
msgback.rotation = transform.rotation;
msgback.timeindex_back = Message.timeindex;
//Server sending back message to client
NetworkServer.SendToAll(MyMsgType.backpose,msgback);
Markerfind = false;
}
void OnreceivingCamera(NetworkMessage netmsg)
{
Cameramsg Message = netmsg.ReadMessage<Cameramsg>();
receiveP = Message.cameraP;
receiveQ = Message.cameraQ;
Camera.main.transform.position = receiveP;
Camera.main.transform.rotation = receiveQ;
}
Then when I start running the program, In the PC part will sometime be interrupt by this message.
" Unknow message id 65536, …" and the number of id is not identical, but all of them are large and unknown number, such like that. I could click the 'pause ’ button to continue running and later it maybe will stop again, seems like random, not fixed.