Example #1
0
        private void MessageHandler(object o, TCPServerClientMessageEventArgs args)
        {
            try
            {
                this.Invoke(new Action(() => this.Message.Text = args.Message));
                switch (args.MessageType)
                {
                case TCPServerClientMessages.Connected:
                    this.Invoke(new Action(() => this.ButtonsPattern(false, false, true, true, false, false, false)));
                    break;

                case TCPServerClientMessages.Disconnected:
                    this.Invoke(new Action(() =>
                    {
                        this.ButtonsPattern(false, true, false, false, false, false, false);
                        this.textBoxFriendsOnline.Text = "0";
                    }));
                    if (this.Client != null && this.Client.BaseSocket != null)
                    {
                        this.Client.Dispose();
                    }
                    break;

                default: break;
                }
            }catch (Exception ex) { }
        }
Example #2
0
        private void WatchDog(TCPServerClientMessages state)
        {
            if (state == TCPServerClientMessages.Undefined)
            {
                return;
            }
            string message = String.Empty;

            if (state == TCPServerClientMessages.Initialized)
            {
                message = "Initialized";
            }
            else if (state == TCPServerClientMessages.Connected)
            {
                message = "Connected to " + this.EndPoint.Address.ToString() + " : " + this.EndPoint.Port.ToString();
            }
            else if (state == TCPServerClientMessages.Disconnected)
            {
                message = "Disconnected";
            }
            else if (state == TCPServerClientMessages.AddressFail)
            {
                message = "Ip address fail";
            }
            else if (state == TCPServerClientMessages.ConnectFail)
            {
                message = "Connect fail";
            }
            else if (state == TCPServerClientMessages.Disconnected)
            {
                message = "Disconnected";
            }
            else if (state == TCPServerClientMessages.DisconnectFail)
            {
                message = "Disconnect fail";
            }
            else if (state == TCPServerClientMessages.ReceiveFail)
            {
                message = "Receive fail";
            }
            else if (state == TCPServerClientMessages.SendFail)
            {
                message = "Send fail";
            }
            else if (state == TCPServerClientMessages.NoHandler)
            {
                message = "No server handler assigned";
            }
            else if (state == TCPServerClientMessages.ParseFail)
            {
                message = "Data parsing fail";
            }
            string fullMessage = DateTime.Now.ToUniversalTime() + " : " + message;

            this.MessageLog.Add(fullMessage);
            TCPServerClientMessageEventArgs argument = new TCPServerClientMessageEventArgs(state, fullMessage);

            if (this.ClientMessageEvent != null)
            {
                this.ClientMessageEvent(this, argument);
            }
        }