Beispiel #1
0
        private async Task HandleReceiveAsync()
        {
            while (true)
            {
                var(receiveCount, receiveText) = await connection.ReceiveMessageAsync();

                if (receiveCount == 0)
                {
                    if (connection.Connected)
                    {
                        ChattingListTextBox.Text += "receive 0 but connected. \n";
                    }
                    else
                    {
                        ChattingListTextBox.Text += "receive 0 and disconnected. \n";
                    }
                    break;
                }

                ChattingListTextBox.Text += receiveText + "\n";

                var obj = JObject.Parse(receiveText);
                if (!obj.ContainsKey("Type"))
                {
                    continue;
                }

                HandlePacketAsync(obj);
            }
        }
Beispiel #2
0
        private async Task HandleReceiveAsync()
        {
            while (true)
            {
                var(receiveCount, receiveText) = await connection.ReceiveMessageAsync();

                if (receiveCount == 0)
                {
                    if (connection.Connected)
                    {
                    }
                    else
                    {
                    }
                    break;
                }



                var obj = JObject.Parse(receiveText);
                if (!obj.ContainsKey("Type"))
                {
                    continue;
                }

                HandlePacketAsync(obj);
            }
        }
        private async void HandleConnection(SocketEx client)
        {
            IServerApi api = new ServerApi(_lobby, client);

            try
            {
                while (true)
                {
                    var(receiveCount, receiveText) = await client.ReceiveMessageAsync();

                    if (receiveCount == 0)
                    {
                        Console.WriteLine("receive 0.");

                        await api.ConnectionClosed();

                        return;
                    }

                    var obj = JObject.Parse(receiveText);
                    if (!obj.ContainsKey("Type"))
                    {
                        //await client.SendMessageAsync(new SC_System
                        //{
                        //    Data = "올바르지 않은 패킷입니다.",
                        //});
                    }

                    await api.HandlePacketAsync(obj);
                }
            }
            catch (SocketException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
        }
Beispiel #4
0
        private async void HandleConnection(SocketEx client)
        {
            try
            {
                while (true)
                {
                    var(receiveCount, receiveText) = await client.ReceiveMessageAsync();

                    if (receiveCount == 0)
                    {
                        Console.WriteLine("receive 0.");

                        await _chattingServer.DisconnectAsync(client);

                        return;
                    }

                    var obj = JObject.Parse(receiveText);
                    if (!obj.ContainsKey("Type"))
                    {
                        await client.SendMessageAsync(new SC_System
                        {
                            Data = "올바르지 않은 패킷입니다.",
                        });
                    }

                    await _chattingServer.HandlePacketAsync(client, obj);
                }
            }
            catch (SocketException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch
            {
            }
        }