Unity3D - Websockets and C#

No replies
digitalroar
digitalroar's picture
Offline
Joined: 2011/09/06

We have a light weight receive function in our client code, we use json for our messaging bus. Unity3d crashes whenever an attempt to receive on the established socket, anyone know how to test a web socket connection to verify that it has data/is readable? :
public Hashtable RecvMsg()
{
lock(locker)
{
string recvMsg;
recvMsg = webSocket.Recv();

Hashtable message = new Hashtable();
message = JsonMapper.ToObject(recvMsg);

Hashtable result = new Hashtable();

if(message["messageStatus"].ToString() == "True")
{
result = JsonMapper.ToObject(message["messageResult"].ToString());
return result;
}
else
{
Debug.Log(message["messageError"].ToString());
return null;
}
}

/*
lock(locker) {
string msg = webSocket.Recv();
if(msg != null)
{
//string msg = opSec.DecryptText(iMsg, iKey, iIV);
Hashtable data = new Hashtable();
data = JsonMapper.ToObject(msg);
queue.Enqueue(data);
print("msg received");
}
}
*/
}

__________________

"You work that you may keep pace with the earth and the soul of the earth. For to be idle is to become a stranger unto the seasons, and to step out of life's procession, that marches in majesty and proud submission towards the infinite."

-Kahlil Gibran  excerpt from The Prophet.