Exemplo n.º 1
0
 /// <summary>
 /// The invoke receive.
 /// </summary>
 /// <param name="e">The e.</param>
 private void OnReceive(SocketReceiveEventArgs e)
 {
     if (Receive != null)
     {
         Receive(this, e);
     }
 }
Exemplo n.º 2
0
        private async Task HandleTCPReceive_RT(SocketReceiveEventArgs args)
        {
            switch (args.ReadPacket.OpCode)
            {
            case 0:
                string guid     = args.ReadPacket.ReadString();
                string roomId   = args.ReadPacket.ReadString();
                string clientId = args.ReadPacket.ReadString();
                if (tempUsersDick.TryGetValue(guid, out NetSocket netSocket))
                {
                    tempUsersDick.Remove(guid);
                    await AddClient(roomId, clientId, new NetSocket(netSocket.MainSocket, NetManager.BUFFER_LENGTH));

                    WritePacket wr = new WritePacket(NetManager.RT_PACKET_OPCODE1);
                    netSocket.Send(wr);
                }
                else
                {
                }
                break;

            default:
                break;
            }
            await Task.FromResult(true);
        }
Exemplo n.º 3
0
 private static void client_OnSocketReceive(object sender, SocketReceiveEventArgs e)
 {
     foreach (string content in e.Contents)
     {
         Console.WriteLine(content);
     }
 }
Exemplo n.º 4
0
        private void OnSocketReceive(object sender, SocketReceiveEventArgs e)
        {
            SockMgrReceiveEventArgs arg = new SockMgrReceiveEventArgs(this, e.Buffer);

            SockMgrReceiveEvent?.Invoke(this, arg);
            _responser.OnSockMgrReceive(this, arg);
        }
Exemplo n.º 5
0
 static void server_OnSocketReceive(object sender, SocketReceiveEventArgs e)
 {
     foreach (string content in e.Contents)
     {
         Console.WriteLine(content);
         e.DataSender.Send(content.Length.ToString());
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// The <see cref="E:ExitGames.Net.Sockets.ISocketReceiver.Receive"/> callback.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The event args.</param>
 private void OnReceive(object sender, SocketReceiveEventArgs e)
 {
     try
     {
         DateTime receiveTime = DateTime.UtcNow;
         if (log.IsDebugEnabled)
         {
             log.DebugFormat("Received data from {0}.", new object[] { e.RemoteEndPoint });
         }
         if ((OnCounterDataReceived != null) || Channel.HasSubscriptions)
         {
             using (MemoryStream input = new MemoryStream(e.Buffer, e.Offset, e.BytesReceived))
             {
                 BinaryReader binaryReader = new BinaryReader(input);
                 binaryReader.PeekChar();
                 long     dateData   = binaryReader.ReadInt64();
                 DateTime senderTime = DateTime.FromBinary(dateData);
                 int      count      = binaryReader.ReadInt32();
                 string   senderId   = binaryReader.ReadString();
                 CounterSampleCollection[] counterSamples = new CounterSampleCollection[count];
                 for (int i = 0; i < count; i++)
                 {
                     counterSamples[i] = CounterSampleCollection.Deserialize(binaryReader);
                 }
                 CounterSamplesPackage counterSamle = new CounterSamplesPackage(e.RemoteEndPoint, senderId, senderTime, receiveTime, counterSamples);
                 if (OnCounterDataReceived != null)
                 {
                     OnCounterDataReceived(this, counterSamle);
                 }
                 Channel.Publish(counterSamle);
             }
         }
     }
     catch (ThreadAbortException)
     {
         throw;
     }
     catch (OutOfMemoryException)
     {
         throw;
     }
     catch (Exception exception)
     {
         if (log.IsErrorEnabled)
         {
             log.Error("Error during receive.", exception);
         }
     }
 }
Exemplo n.º 7
0
        void client_OnDataReceived(object sender, SocketReceiveEventArgs <object, object, object> args)
        {
            if (args.Packet is NicoResponse)
            {
                Console.WriteLine(((NicoResponse)args.Packet).Content);

                /*
                 *      NicoAlertResponse response =(NicoResponse)args.Packet;
                 *      Console.WriteLine("==================================");
                 *      Console.WriteLine("  Live\t\t" + response.LiveId);
                 *      Console.WriteLine("  User\t\t" + response.LiveOwnerUserId);
                 *      Console.WriteLine("  Comunity\t" + response.ComunityId);
                 *      Console.WriteLine("==================================");
                 *      Console.WriteLine();*/
            }
        }
Exemplo n.º 8
0
        private void SocketServerReceivedData(object sender, SocketReceiveEventArgs e)
        {
            try
            {
                _receivedBytes       = e.ReceivedData.Length;
                _receivedTotalBytes += _receivedBytes;
                RefreshStatusStrip();

                var dataMessage = radioReceivedDataHex.Checked ? e.ReceivedData.ToByteString() : Encoding.GetEncoding(txtReceivedDataEncoding.Text).GetString(e.ReceivedData);
                var logMessage  = String.Format("The server received {0} bytes", _receivedBytes);
                WriteToTextBox(txtReceivedData, dataMessage);
                WriteToTextBox(txtStatusLog, logMessage);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 9
0
        private void OnAfterReceive(object sender, SocketReceiveEventArgs e)
        {
            var lastIndex = 0;

            //получаем первую команду из буфера приемника
            var command = _protocol.FromBuffer(e.Buffer, lastIndex, e.Length, out lastIndex);

            while (command != null)
            {
                DoCommandProcess(command);

                //продолжаем считывать все команды, пока они не закончаться
                command = _protocol.FromBuffer(e.Buffer, lastIndex, e.Length, out lastIndex);
            }

            //отправляем индекс, на котором остановились
            e.FinishIndex = lastIndex;
        }
Exemplo n.º 10
0
        static void ClientReceive(object sender, SocketReceiveEventArgs e)
        {
            Console.WriteLine("Received request");
            const string request = "[color] ";
            var          client  = sender as ClientSocket;
            var          s       = e.Text;

            if (s.StartsWith(request))
            {
                s = s.Replace(request, "").Trim();
                s = RunExternal("color.py", s);
                Console.WriteLine(s);
                client.Send(s);
            }
            else
            {
                client.Send("[error] invalid request");
            }
        }
Exemplo n.º 11
0
        private static void HandleTCPReceive(SocketReceiveEventArgs args)
        {
            switch (args.ReadPacket.OpCode)
            {
            case 0:
                string guid = args.ReadPacket.ReadString();
                Console.WriteLine("Received : {0}", guid);
                WritePacket wr = new WritePacket(0);
                wr.AddString(guid);
                wr.AddString(matchId);
                wr.AddString(Id);
                tcpSocket.Send(wr);
                break;

            case 1:
                Console.WriteLine("You Can Play Now");
                break;

            default:
                break;
            }
        }
Exemplo n.º 12
0
        private void SocketClientReceivedData(object sender, SocketReceiveEventArgs e)
        {
            try
            {
                var receivedBytes = e.ReceivedData.Length;
                var socketClient  = _socketServer.FindClient(e.RemotePoint);
                if (_connectedClients.ContainsKey(socketClient))
                {
                    _connectedClients[socketClient].ReceivedBytes       = receivedBytes;
                    _connectedClients[socketClient].ReceivedTotalBytes += receivedBytes;
                }

                var dataMessage = radioReceivedDataHex.Checked ? e.ReceivedData.ToByteString() : Encoding.GetEncoding(txtReceivedDataEncoding.Text).GetString(e.ReceivedData);
                var logMessage  = String.Format("The server received data from the client {0}:{1}, Length: {2} bytes", e.RemotePoint.Address, e.RemotePoint.Port, receivedBytes);
                WriteToTextBox(txtReceivedData, dataMessage);
                WriteToTextBox(txtStatusLog, logMessage);
                RefreshStatusStrip();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 13
0
 private static void server_OnSocketReceive(SocketReceiveEventArgs e)
 {
     server.Broadcast(string.Format("客户端{0}:{1}", e.Sender.EndPoint, e.Content));
 }
Exemplo n.º 14
0
 private void Manager_OnMessage(object sender, SocketReceiveEventArgs e)
 {
     OnMessageReceived(e.FromClient, e.Message);
 }
Exemplo n.º 15
0
 /// <summary>
 /// The socket receiver_ receive.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The e.</param>
 private void SocketReceiver_OnReceive(object sender, SocketReceiveEventArgs e)
 {
     OnReceive(e);
 }
Exemplo n.º 16
0
 private static void client_OnSocketReceive(SocketReceiveEventArgs e)
 {
     Console.WriteLine(e.Content);
 }
Exemplo n.º 17
0
 private async Task HandleReceive(SocketReceiveEventArgs args)
 {
     await Task.FromResult(true);
 }