public static Succeeded ( SocketError error ) : bool | ||
error | SocketError | |
return | bool |
internal void Update() { if (NetConfig.LatencySimulation) { for (int i = 0; i < NetConfig.MaxPacketReads; i++) { IPEndPoint source; int length; SocketError result = this.socket.TryReceive( out source, this.receiveBuffer, out length); if (NetSocket.Succeeded(result) == false) { return; } this.inQueue.Enqueue(source, this.receiveBuffer, length); } } else { this.inQueue.Clear(); } }
/// <summary> /// Polls the socket and receives all pending packet data. /// </summary> private void ReadPackets() { for (int i = 0; i < NetConfig.MaxPacketReads; i++) { IPEndPoint source; byte[] buffer; int length; SocketError result = this.receiver.TryReceive(out source, out buffer, out length); if (NetSocket.Succeeded(result) == false) { return; } NetPacketType type = NetEncoding.GetType(buffer); if (type == NetPacketType.Connect) { // We don't have a peer yet -- special case this.HandleConnectRequest(source, buffer, length); } else { NetPeer peer; if (this.peers.TryGetValue(source, out peer)) { switch (type) { case NetPacketType.Accept: this.HandleConnectAccept(peer, buffer, length); break; case NetPacketType.Kick: this.HandleKick(peer, buffer, length); break; case NetPacketType.Ping: this.HandlePing(peer, buffer, length); break; case NetPacketType.Pong: this.HandlePong(peer, buffer, length); break; case NetPacketType.Carrier: this.HandleCarrier(peer, buffer, length); break; case NetPacketType.Payload: this.HandlePayload(peer, buffer, length); break; } } } } }