예제 #1
0
 public override void ReadResponse(NetworkPacket packet)
 {
     startPos   = packet.ReadUShort();
     segmentLen = packet.ReadUShort();
 }
예제 #2
0
 public override void ReadRequest(NetworkPacket packet)
 {
     timestamp = packet.ReadLong();
 }
예제 #3
0
 public override void WriteRequest(NetworkPacket packet, NetworkMessage message)
 {
     message.WriteRequest(packet);
 }
예제 #4
0
 /**
  * Free a socket event back into the pool.
  * Reset all the initial properties to null.
  */
 public void Free(NetworkPacket packet)
 {
     thread.PACKETPOOL.Free(packet);
 }
예제 #5
0
 public virtual void OnError(object sender, NetworkPacket packet)
 {
 }
예제 #6
0
 public virtual void WriteResponse(NetworkPacket packet, NetworkMessage message)
 {
 }
예제 #7
0
 public virtual void WriteRequest(NetworkPacket packet)
 {
 }
예제 #8
0
 public virtual NetworkMessage[] ReadHeaders(NetworkPacket packet)
 {
     return(null);
 }
예제 #9
0
 public void Read(NetworkPacket packet)
 {
     username = packet.ReadString();
 }
예제 #10
0
 public void Write(NetworkPacket packet)
 {
     packet.Write((byte)1);
     packet.Write(sendRate);
     packet.Write(peerId);
 }
예제 #11
0
        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);
            }
        }
예제 #12
0
 public override void ReadResponse(NetworkPacket packet)
 {
     responseTimestamp = packet.ReadLong();
 }
예제 #13
0
 public override void WriteResponse(NetworkPacket packet)
 {
     packet.Write(responseTimestamp);
 }
예제 #14
0
        public void OnWriteHeader(object sender, NetworkMessage message)
        {
            NetworkPacket packet = (NetworkPacket)sender;

            packet.Write(message.header.id);
        }
예제 #15
0
 public virtual void WriteResponse(NetworkPacket packet)
 {
 }
예제 #16
0
 public virtual void WriteHeader(NetworkPacket packet, NetworkMessage message)
 {
 }
예제 #17
0
 public virtual void ReadRequest(NetworkPacket packet)
 {
 }
예제 #18
0
 public virtual void OnReceive(object sender, NetworkPacket packet)
 {
 }
예제 #19
0
 public virtual void ReadResponse(NetworkPacket packet)
 {
 }
예제 #20
0
 public virtual void WriteRequest(NetworkPacket packet, NetworkMessage message)
 {
 }
예제 #21
0
 public virtual void StreamMessage(NetworkPacket packet)
 {
 }
예제 #22
0
 public override void OnSend(object sender, NetworkPacket packet)
 {
 }
예제 #23
0
        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;
                }
            }
        }
예제 #24
0
 public override void WriteResponse(NetworkPacket packet, NetworkMessage message)
 {
     message.WriteResponse(packet);
 }
예제 #25
0
 public void OnAllocateError(NetworkPacket packet, MessageSTUN message)
 {
     nonce = (byte[])message.Get(STUNAttribute.Nonce);
     ConnectTURN(null, false);
 }
예제 #26
0
 public override void WriteResponse(NetworkPacket packet)
 {
     packet.Write(startPos);
     packet.Write(segmentLen);
 }
예제 #27
0
 public void OnErrorConnectToServer(object sender, NetworkPacket packet)
 {
 }
예제 #28
0
 public void OnErrorReliableFailed(object sender, NetworkPacket packet)
 {
     //Console.WriteLine("[ERROR] " + packet.lastErrorType.ToString() + ": " + packet.lastErrorMessage);
 }
예제 #29
0
 public override void WriteRequest(NetworkPacket packet)
 {
     packet.Write(timestamp);
 }