Hi, Iam trying to make a multiplayer game using webgl.
Sending a message from player to server works, but not the other way around.
I have this in Update function
int recConnectionId;
int recChannelId;
byte[] recBuffer = new byte[1024];
int bufferSize = 1024;
int dataSize;
byte error;
NetworkEventType recNetworkEvent = NetworkTransport.ReceiveFromHost(
socketId, out recConnectionId, out recChannelId, recBuffer,
bufferSize, out dataSize, out error);
switch (recNetworkEvent)
{
case NetworkEventType.DataEvent:
MemoryStream str = new MemoryStream(recBuffer);
BinaryFormatter formatter = new BinaryFormatter();
//the line below causes a loop of exceptions in console
string msg = formatter.Deserialize(str) as string;
Debug.Log("from server: " + msg.ToString());
break;
}
The switch has other cases but they are mostly empty.
The mentioned line causes a loop of “SerializationException: Unexpected binary element: 0” in console and the message itself is never written.
This exact same code works when I run it in unity editor but not when I build the app and run it in browser.
What am I doing wrong?
Thank you.