public override void ReadResponse(NetworkPacket packet) { startPos = packet.ReadUShort(); segmentLen = packet.ReadUShort(); }
public override void ReadRequest(NetworkPacket packet) { timestamp = packet.ReadLong(); }
public override void WriteRequest(NetworkPacket packet, NetworkMessage message) { message.WriteRequest(packet); }
/** * Free a socket event back into the pool. * Reset all the initial properties to null. */ public void Free(NetworkPacket packet) { thread.PACKETPOOL.Free(packet); }
public virtual void OnError(object sender, NetworkPacket packet) { }
public virtual void WriteResponse(NetworkPacket packet, NetworkMessage message) { }
public virtual void WriteRequest(NetworkPacket packet) { }
public virtual NetworkMessage[] ReadHeaders(NetworkPacket packet) { return(null); }
public void Read(NetworkPacket packet) { username = packet.ReadString(); }
public void Write(NetworkPacket packet) { packet.Write((byte)1); packet.Write(sendRate); packet.Write(peerId); }
public void ReliableThread() { NetworkPacket packet = null; int queueCount = 0; long difftime; bool isAcknowledged; long curtime = NetworkTime.Milliseconds(); bool hasFailed = false; bool shouldResend = false; NetworkMessage message; while (true) { lock (RELIABLEQUEUE) { queueCount = RELIABLEQUEUE.Count; if( queueCount > 0) packet = RELIABLEQUEUE.Dequeue(); } if (queueCount == 0) { Thread.Sleep(NetworkConfig.ThreadReliableSleepTime); continue; } curtime = NetworkTime.Milliseconds(); hasFailed = false; shouldResend = false; //for (int i = 0; i < packet.messages.Count; i++) { message = packet.messages[0]; lock (ACKNOWLEDGED) { isAcknowledged = ACKNOWLEDGED.Remove(message.header.ackkey); } if (isAcknowledged) { packet.socket.Free(packet); continue; } difftime = curtime - message.header.sentTime; if (difftime > packet.retryDelay) { if (message.header.retryCount > NetworkConfig.SocketReliableRetryAttempts) { if (message.header.channelType == ChannelType.Server) { packet.socket.Failed(NetworkErrorType.ErrorConnectToServer, "Unable to connect to server.", packet); } else if (message.header.channelType == ChannelType.STUN) { packet.socket.Failed(NetworkErrorType.ErrorNoResponseSTUN, "Unable to connect to server.", packet); } failedReliableCount++; packet.socket.Failed(NetworkErrorType.ErrorReliableFailed, "Failed to deliver " + message.header.retryCount + " packets (" + failedReliableCount + ") times.", packet); hasFailed = true; packet.socket.Free(packet); continue; } shouldResend = true; Console.WriteLine("Resending " + message.header.sequence + ", attempt #" + message.header.retryCount); packet.socket.Send(packet); continue; } } if (hasFailed) { } else if (shouldResend) { } lock (RELIABLEQUEUE) { RELIABLEQUEUE.Enqueue(packet); } //Thread.Sleep(MIN_RELIABLE_SLEEP_TIME); } }
public override void ReadResponse(NetworkPacket packet) { responseTimestamp = packet.ReadLong(); }
public override void WriteResponse(NetworkPacket packet) { packet.Write(responseTimestamp); }
public void OnWriteHeader(object sender, NetworkMessage message) { NetworkPacket packet = (NetworkPacket)sender; packet.Write(message.header.id); }
public virtual void WriteResponse(NetworkPacket packet) { }
public virtual void WriteHeader(NetworkPacket packet, NetworkMessage message) { }
public virtual void ReadRequest(NetworkPacket packet) { }
public virtual void OnReceive(object sender, NetworkPacket packet) { }
public virtual void ReadResponse(NetworkPacket packet) { }
public virtual void WriteRequest(NetworkPacket packet, NetworkMessage message) { }
public virtual void StreamMessage(NetworkPacket packet) { }
public override void OnSend(object sender, NetworkPacket packet) { }
public override void ReadResponse(NetworkPacket packet) { methodId = (ushort)((uint)packet.ReadUShort() & 0x3FFF); //0x3F (0011 1111) sets left most 2 bits to 00 methodLength = packet.ReadUShort(); transactionID = packet.ReadBytes(16); header.ackkey = BitConverter.ToUInt32(transactionID, 0); method = (STUNMethod)methodId; //Console.WriteLine("STUN Response address: " + packet.remoteEndPoint.ToString()); //Console.WriteLine("STUN Response Method: " + Enum.GetName(typeof(STUNMethod), method)); //Console.WriteLine("STUN Response Length: " + methodLength); while (packet.bytePos < packet.byteLength) { STUNAddress address; STUNAttribute attrType = (STUNAttribute)packet.ReadUShort(); attributeTypes.Add(attrType); //Console.WriteLine("STUN Attr Type: " + Enum.GetName(typeof(STUNAttribute), attrType)); switch (attrType) { case STUNAttribute.MappedAddress: case STUNAttribute.SourceAddress: case STUNAttribute.ChangedAddress: address = ReadMappedAddress(packet); response.Add(attrType, address); break; case STUNAttribute.XorMappedAddress: case STUNAttribute.XorRelayedAddress: address = ReadXorMappedAddress(packet); response.Add(attrType, address); break; case STUNAttribute.ErrorCode: response.Add(attrType, ReadErrorCode(packet)); break; case STUNAttribute.UnknownAttribute: response.Add(attrType, ReadUnknownAttributes(packet)); break; case STUNAttribute.ServerName: response.Add(attrType, ReadString(packet)); break; case STUNAttribute.Realm: response.Add(attrType, ReadString(packet)); break; case STUNAttribute.Username: response.Add(attrType, ReadString(packet)); break; default: ushort attrLen = packet.ReadUShort(); byte[] bytes = packet.ReadBytes(attrLen); response.Add(attrType, bytes); while (((attrLen++) % 4) != 0) { packet.ReadByte(); } break; } } }
public override void WriteResponse(NetworkPacket packet, NetworkMessage message) { message.WriteResponse(packet); }
public void OnAllocateError(NetworkPacket packet, MessageSTUN message) { nonce = (byte[])message.Get(STUNAttribute.Nonce); ConnectTURN(null, false); }
public override void WriteResponse(NetworkPacket packet) { packet.Write(startPos); packet.Write(segmentLen); }
public void OnErrorConnectToServer(object sender, NetworkPacket packet) { }
public void OnErrorReliableFailed(object sender, NetworkPacket packet) { //Console.WriteLine("[ERROR] " + packet.lastErrorType.ToString() + ": " + packet.lastErrorMessage); }
public override void WriteRequest(NetworkPacket packet) { packet.Write(timestamp); }