예제 #1
0
        private void ClientClose(object sender, NetEventArgs e)
        {
            string info;

            if (e.Client.TypeOfExit == Session.ExitType.ExceptionExit)
            {
                info = string.Format("A Client Session:{0} Exception Closed.",
                                     e.Client.ID);
            }
            else
            {
                info = string.Format("A Client Session:{0} Normal Closed.",
                                     e.Client.ID);
            }
            UpdateUItoolStripButton(toolStripButtonStart, "Start Connect", Color.Red, Client.Properties.Resources.Red);
            UpdateUIToolStripTextBox(PortNo, true);
            UpdateUIToolStripTextBox(IPNo, true);
            UpdateUITextBox(SendData, true);
            UpdateUIButton(buttonSend, false);
            tc.Close();
            tc.Dispose();
            //Console.WriteLine(info);
            //Console.Write(">");
            rtbe1.SetText(info, true);
            //throw new NotImplementedException();
        }
예제 #2
0
        private void toolStripButtonStart_Click(object sender, EventArgs e)
        {
            try
            {
                switch (toolStripButtonStart.Text)
                {
                case "Start Connect":
                    toolStripButtonStart.BackColor             = Color.Blue;
                    toolStripButtonStart.ImageTransparentColor = Color.Blue;
                    toolStripButtonStart.BackgroundImage       = Client.Properties.Resources.Blue;
                    toolStripButtonStart.Image = Client.Properties.Resources.Blue;
                    toolStripButtonStart.Text  = "DisConnect";
                    PortNo.Enabled             = false;
                    IPNo.Enabled = false;
                    tc           = new TcpCli(new Coder(Coder.EncodingMothord.UTF8));
                    //tc = new TcpCli(new Coder(Coder.EncodingMothord.HexString));
                    //tc.Resovlver = new DatagramResolver(Convert.ToChar(4).ToString());//EOT (end of transmission)
                    tc.ReceivedDatagram   += new NetEvent(RecvData);
                    tc.DisConnectedServer += new NetEvent(ClientClose);
                    tc.ConnectedServer    += new NetEvent(ClientConn);
                    tc.ExceptionMessage   += new NetEvent(ClienError);
                    tc.Connect(IPNo.Text, Convert.ToUInt16(PortNo.Text));
                    tc.HeadLength      = true;
                    buttonSend.Enabled = true;
                    SendData.Enabled   = true;
                    rtbe1.SetText(String.Format("Connect to [{0}]({1})", IPNo.Text, PortNo.Text), true);
                    break;

                case "DisConnect":
                    toolStripButtonStart.BackColor             = Color.Red;
                    toolStripButtonStart.ImageTransparentColor = Color.Red;
                    toolStripButtonStart.BackgroundImage       = Client.Properties.Resources.Red;
                    toolStripButtonStart.Image = Client.Properties.Resources.Red;
                    toolStripButtonStart.Text  = "Start Connect";
                    PortNo.Enabled             = true;
                    IPNo.Enabled       = true;
                    buttonSend.Enabled = false;
                    SendData.Enabled   = false;
                    tc.Close();
                    tc.Dispose();
                    rtbe1.SetText(String.Format("DisConnect to [{0}]({1})", IPNo.Text, PortNo.Text), true);
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                toolStripStatusLabel1.Text                 = ex.Message.ToString();
                toolStripButtonStart.BackColor             = Color.Red;
                toolStripButtonStart.ImageTransparentColor = Color.Red;
                toolStripButtonStart.BackgroundImage       = Client.Properties.Resources.Red;
                toolStripButtonStart.Image                 = Client.Properties.Resources.Red;
                toolStripButtonStart.Text = "Start Connect";
                PortNo.Enabled            = true;
                IPNo.Enabled       = true;
                buttonSend.Enabled = false;
                SendData.Enabled   = false;
                tc.Close();
                tc.Dispose();
                rtbe1.SetText(String.Format("DisConnect to [{0}]({1})", IPNo.Text, PortNo.Text), true);
            }
        }