Exemple #1
0
		public async void Send(Serializable.Context3D context)
		{
			if (!udpClient.Active)
			{
				Debug.Log("[UDP] Sending packet failed. UDP client not active.");
				return;
			}
			// Debug.Log("[UDP] Sent packet (" + context.RigidBodies.Count + ")");
			await udpClient.Send(context.ToByteArray());
			// Debug.Log("[UDP] Sent context.");
		}
Exemple #2
0
    //public async Error Send(Packet packet)
    public async Task <ILog> Send(Serializable.Context3D packet)
    {
        ArraySegment <byte> sendBuffer = new ArraySegment <byte>(packet.ToByteArray());

        //if (debug) Debug.Log(string.Format("WS - {0} {1}", "Sending packet", packet.Header.OpCode));
        using (CancellationTokenSource cts = new CancellationTokenSource())
        {
            try
            {
                await clientWebSocket.SendAsync(sendBuffer, WebSocketMessageType.Binary, true, cts.Token);

                return(null);
            }
            catch
            {
                return(new Error("[WS] Client failed to send packet"));
            }
        }
    }