Esempio n. 1
0
 public void Write(ByteBuffer buf)
 {
     buf.WriteByte(Id);
     buf.WriteShort(Length);
     buf.AddBytes(Data);
     buf.WriteByte(Percent);
 }
Esempio n. 2
0
        //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        public static void SendRegularRequest(RequestTypes requestType, ByteBuffer requestBuffer, RequestParseCallback requestParseCallback, RequestViewCallback requestViewCallback)
        {
            if (requestType == RequestTypes.ReconnectToServer)
            {
                Init();
                requestViewCallback?.Invoke(RequestStates.Completed);
                return;
            }

            if ((DateTime.Now - lastPingTime).TotalMilliseconds > Settings.pingValueLifeTime * 3)
                Init();

            if ((connectState != ConnectStates.AuthPassed) && (userToken == null) && (login == null))
                return;

            sendPacketBuffer.Reset((int)HeaderOffsets.SecondEnd);

            sendPacketBuffer.Add((byte)ClientPacketTypes.Request);
            sendPacketBuffer.Add((byte)requestType);

            if (requestBuffer != null)
                sendPacketBuffer.AddBytes(requestBuffer, 0);

            SendRequestToServer(requestParseCallback, requestViewCallback);

            if (WaitForPacket(ClientPacketTypes.RequestAnswer, waitPacketTimeout) == false)
            {
                Console.WriteLine("socket.Connected: " + socket.Connected);
                socket.Disconnect(false);
                ConnectToServer();
            }

            Update();
        }
Esempio n. 3
0
 private void SocketOnDataReceived(DataReceivedArgs args)
 {
     lock (_handleLock) {
         _receiveBuffer.AddBytes(args.Data);
         _lastActive = DateTime.UtcNow;
         Handle();
     }
 }
Esempio n. 4
0
        /// <summary>
        /// This is called whenever data is received from the client
        /// </summary>
        /// <param name="args"></param>
        private void SocketOnDataReceived(DataReceivedArgs args)
        {
            if (!_canReceive)
            {
                return;
            }

            lock (_fk) {
                Interlocked.Add(ref Server.ReceivedIncrement, args.Data.Length);
                _receiveBuffer.AddBytes(args.Data); // -- Add the bytes into our receive buffer..
                _lastActive = DateTime.UtcNow;
            }
        }
Esempio n. 5
0
 private void BaseSocketOnDataReceived(DataReceivedArgs args)
 {
     lock (_receiveBuffer) {
         _receiveBuffer.AddBytes(args.Data);
     }
 }