public static Get ( int size ) : |
||
size | int | |
return |
public void SendData(ConnectionId userId, byte[] data, int offset, int length, bool reliable) { //if(Network.isServer && method == DeliveryMode.Unreliable && userId != UserIdAll) //{ // throw new InvalidOperationException("Unity only allows to send to all clients at once from server."); //} //if(Network.isClient && method == DeliveryMode.Unreliable && (_KnownPlayers.ContainsKey(userId) == false ||_KnownPlayers[userId].player != Network.connections[0])) //{ // throw new InvalidOperationException("Can only send to server"); //} if (reliable) { NetworkPlayer pl = this.mKnownPlayers[userId].ConnectedUser; NetworkView nv = GetComponent <NetworkView>(); nv.RPC("DeliverMessage", pl, data); } else { Queue <ByteArrayBuffer> userOut; bool found = mOutgoingUnreliableMessages.TryGetValue(userId, out userOut); if (found == false) { userOut = new Queue <ByteArrayBuffer>(); mOutgoingUnreliableMessages.Add(userId, userOut); } ByteArrayBuffer msg = ByteArrayBuffer.Get(length); msg.CopyFrom(data, offset, length); userOut.Enqueue(msg); } }
public void SingleEndpoint_OnSerialize(BitStream stream, NetworkPlayer senderOrReceiver) { //doesnt work. server sends messages automatically to all others if (stream.isReading) { char countin = (char)0; stream.Serialize(ref countin); int count = (int)countin; //Debug.Log(count + " packages sent"); for (int k = 0; k < count; k++) { int length = 0; short lengthin = 0; stream.Serialize(ref lengthin); length = ((int)(ushort)lengthin); //just making sure it converts the - values back into high positive values ByteArrayBuffer msg = ByteArrayBuffer.Get(length); for (int i = 0; i < length; i++) { char c = 'v'; stream.Serialize(ref c); msg.array[i] = (byte)c; msg.positionWrite++; } NetworkEvent ev = new NetworkEvent(NetEventType.UnreliableMessageReceived, NetworkPlayerToConnectionId(senderOrReceiver), msg); mEvents.Enqueue(ev); } } else { Queue <ByteArrayBuffer> userOut; ConnectionId userid; userid = NetworkPlayerToConnectionId(senderOrReceiver); // NetworkPlayerToInt(senderOrReceiver); bool found = mOutgoingUnreliableMessages.TryGetValue(userid, out userOut); if (found && userOut.Count > 0) { char count = (char)0; if (userOut.Count > 255) { Debug.LogWarning("Too many messages at once"); count = (char)255; } else { count = (char)userOut.Count; } stream.Serialize(ref count); for (int i = 0; userOut.Count > 0 && i < 256; i++) { ByteArrayBuffer msg = userOut.Dequeue(); short length = (short)msg.positionWrite; stream.Serialize(ref length); for (int k = 0; k < length; k++) { char c = (char)msg.array[k]; stream.Serialize(ref c); } msg.Dispose(); } //Debug.Log(count + " messages sent to " + userid); } } }