void SendPositions() { byte[] position = ToByteArray(JsonMessageBuilder.FormatPositionsMessage(worldManager.GetVRPlayer(), worldManager.GetMobs(), ipcManagerPrefab.GetIPCManager().ReceiveEventsForType(Communication.EventType.KillMob))); byte error; NetworkTransport.Send(wsClient.GetHostId(), wsClient.GetConnectionId(), wsClient.GetChannelId(), position, position.Length, out error); }
void Update() { if (!clientInitialised) { return; } int recHostId; int connectionId; int channelId; int dataSize; byte[] buffer = new byte[1024]; byte error; NetworkEventType networkEvent = NetworkEventType.DataEvent; do { networkEvent = NetworkTransport.Receive(out recHostId, out connectionId, out channelId, buffer, 1024, out dataSize, out error); switch (networkEvent) { case NetworkEventType.Nothing: break; case NetworkEventType.ConnectEvent: if (recHostId == clientSocket) { Debug.Log("Client connected to " + connectionId.ToString() + "!"); byte[] gameWorld = ToByteArray(JsonMessageBuilder.FormatWorldStatusMessage(worldManager.GetGameWorld())); NetworkTransport.Send(recHostId, connectionId, channelId, gameWorld, gameWorld.Length, out error); wsClient = new WebsocketClient(recHostId, connectionId, channelId); } break; case NetworkEventType.DataEvent: string data = FromByteArray(buffer); Debug.Log(data); if (recHostId == clientSocket) { commandResolver.ResolveMessage(data); } break; case NetworkEventType.DisconnectEvent: if (recHostId == clientSocket) { Debug.Log("Client has disconnected"); wsClient = null; } break; } } while (networkEvent != NetworkEventType.Nothing); }