예제 #1
0
 private void btnStart_Click(object sender, EventArgs e)
 {
     btnStart.Enabled = false;
     _Client          = new AsyncClient(txtIP.Text, Convert.ToInt32(txtPort.Text));
     try
     {
         _Client.Connected     += new EventHandler <AsyncClientEventArgs>(Client_OnConnected);
         _Client.DataReceived  += new EventHandler <AsyncClientEventArgs>(Client_OnDataReceived);
         _Client.DataSended    += new EventHandler <AsyncClientEventArgs>(Client_OnDataSended);
         _Client.Closing       += new EventHandler <AsyncClientEventArgs>(Client_OnClosing);
         _Client.Closed        += new EventHandler <AsyncClientEventArgs>(Client_OnClosed);
         _Client.Exception     += new EventHandler <AsyncClientEventArgs>(Client_OnException);
         _Client.ConnectTimeout = 3000;
         _Client.Connect();
     }
     catch (Exception ex)
     {
         WriteLog("無法連接至伺服器!!!");
         if (ex.GetType().Equals(typeof(System.Net.Sockets.SocketException)))
         {
             System.Net.Sockets.SocketException se = (System.Net.Sockets.SocketException)ex;
             WriteLog("{0} - {1}", se.SocketErrorCode, se.Message);
         }
         btnStart.Enabled = true;
     }
 }
예제 #2
0
 public MainWindowViewModel()
 {
     _parser     = new ParserApsTensileV1();
     asyncClient = new AsyncClient(hostName, portNumber);
     asyncClient.MessageReceived += AsyncClient_MessageReceived;
     asyncClient.Connect();
 }
예제 #3
0
 private void InitNet()
 {
     try
     {
         InitAsyncTimer();
         ip   = ConfigHelper.GetInstace().IP;
         port = ConfigHelper.GetInstace().Port;
         if (this.asyncClient != null)
         {
             this.asyncClient.Dispose();
             this.asyncClient.onConnected  -= new AsyncClient.Connected(client_onConnected);
             this.asyncClient.onDisConnect -= new AsyncClient.DisConnect(client_onDisConnect);
             this.asyncClient.onDataByteIn -= new AsyncClient.DataByteIn(client_onDataByteIn);
         }
         asyncClient              = new AsyncClient();
         asyncClient.onConnected += new AsyncClient.Connected(client_onConnected);
         asyncClient.Connect(ip, port);
         asyncClient.onDataByteIn += new AsyncClient.DataByteIn(client_onDataByteIn);
         asyncClient.onDisConnect += new AsyncClient.DisConnect(client_onDisConnect);
     }
     catch (Exception ex)
     {
         Console.WriteLine("cannot connect to server:" + ex.Message);
     }
 }
예제 #4
0
 private void InitClient()
 {
     try
     {
         InitAsyncTimer();
         string zoneIP   = ConfigHelper.GetInstace().ZoneIP;
         int    zonePort = ConfigHelper.GetInstace().ZonePort;
         if (this.asyncClient != null)
         {
             this.asyncClient.Dispose();
             this.asyncClient.onConnected  -= new AsyncClient.Connected(client_onConnected);
             this.asyncClient.onDisConnect -= new AsyncClient.DisConnect(client_onDisConnect);
             this.asyncClient.onDataByteIn -= new AsyncClient.DataByteIn(client_onDataByteIn);
         }
         asyncClient              = new AsyncClient();
         asyncClient.onConnected += new AsyncClient.Connected(client_onConnected);
         asyncClient.Connect(zoneIP, zonePort);
         asyncClient.onDataByteIn += new AsyncClient.DataByteIn(client_onDataByteIn);
         asyncClient.onDisConnect += new AsyncClient.DisConnect(client_onDisConnect);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
예제 #5
0
 private void frmMain_Load(object sender, EventArgs e)
 {
     Client = new AsyncClient();
     Client.Connect(Global.Default.varXml.Connection.ServerIP, Global.Default.varXml.Connection.Port);
     Client.Connected       += Client_Connected;
     Client.Disconnected    += Client_Disconnected;
     Client.MessageReceived += Client_MessageReceived;
 }
예제 #6
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            loginBtn.IsEnabled = false;
            Alarmus.AutorizationMessage msg = new Alarmus.AutorizationMessage(Alarmus.ClientType.CLIENT_USER, loginBox.Text, passwordBox.Password);

            AsyncClient.Connect(addressBox.Text, 8888); //TODO: Заменить адрес из текст бокса на параметр
            clientThread = new Thread(() => AsyncAutorization(msg));
            clientThread.Start();
        }
예제 #7
0
 /// <summary>初始化連線類別並連線至遠端</summary>
 /// <param name="ipHost"></param>
 private void InitinalConnection(IPEndPoint ipHost)
 {
     _Client               = new AsyncClient(ipHost);
     _Client.Connected    += new EventHandler <AsyncClientEventArgs>(Remote_OnConnected);
     _Client.Closed       += new EventHandler <AsyncClientEventArgs>(Remote_OnClosed);
     _Client.DataSended   += new EventHandler <AsyncClientEventArgs>(Remote_OnDataSended);
     _Client.DataReceived += new EventHandler <AsyncClientEventArgs>(Remote_OnDataReceived);
     _Client.SendFail     += new EventHandler <AsyncClientEventArgs>(Remote_OnSendedFail);
     _Client.Connect();
 }
 public static bool Init(int port)
 {
     Client = new AsyncClient(null);
     if (Client.Connect("127.0.0.1", port))
     {
         Client.OnRecevice += new OnReceviceHanlder(Recevice);
         Client.BeginRecevice();
         return(true);
     }
     return(false);
 }
예제 #9
0
 private void btnCreateSingle_Click(object sender, EventArgs e)
 {
     // if(IsConnected())
     if (m_Client != null && m_Client.IsConnected())
     {
         return;
     }
     m_ReceivedBuffer.Clear();
     m_Client = new AsyncClient(tbLocalIP.Text, Convert.ToInt32(tbLocalport.Text), tbIPAddress.Text, 20160);
     m_Client.HandleReceivedBuffers += OnReceivedBuffers;
     m_Client.Connect();
 }
예제 #10
0
파일: ChatForm.cs 프로젝트: Hona/Drocsid
        private async void StartClientButton_Click(object sender, EventArgs e)
        {
            // If no IP is specified then connect to the local host
            var address = IpAddressTextBox.Text == ""
                ? Helper.LocalIpAddress
                : IPAddress.Parse(IpAddressTextBox.Text);

            Client = new AsyncClient(_logger);
            await Client.Connect(address);

            Client.MessageReceived += ProcessMessage;
            await Client.ReadData();
        }
예제 #11
0
        static void Main(string[] args)
        {
            _parser = new ParserApsTensileV1();
            //MessageHandler messageHandler = new MessageHandler();
            AsyncClient asyncClient = new AsyncClient(hostName, portNumber, new MessageHandler());

            asyncClient.MessageReceived += AsyncClient_MessageReceived;
            asyncClient.Connect();
            if (asyncClient.IsConnected)
            {
                asyncClient.Send("first data from program\r");
            }
            Console.ReadLine();
        }
예제 #12
0
        /// <summary>
        /// 创建连接
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void mumCreateLink_Click(object sender, EventArgs e)
        {
            // if(IsConnected())
            if (m_Client != null && m_Client.IsConnected())
            {
                return;
            }
            ConfigForm cfg = new ConfigForm();

            if (DialogResult.OK == cfg.ShowDialog())
            {
                m_SerialNo = cfg.SerialNo;//序列号传入
                m_ReceivedBuffer.Clear();
                m_Client = new AsyncClient(cfg.IP, cfg.Port);
                m_Client.HandleReceivedBuffers += OnReceivedBuffers;
                m_Client.Connect();
            }
        }
예제 #13
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            m_ThreadPool.Clear();
            int    iCount   = Convert.ToInt32(tbCount.Text);
            int    basePort = 30000;
            string szIp     = "";

            for (int iLoop = 0; iLoop < iCount; iLoop++)
            {
                szIp = string.Format("127.0.0.{0}", iLoop + 1);
                AsyncClient client = new AsyncClient(szIp, basePort++, tbIPAddress.Text, Convert.ToInt32(tbPort.Text));
                m_ClientList.Add(client);
                m_ReceivedBufferList.Add(new List <byte>());
                client.HandleReceivedBuffersEx += OnReceivedBuffersEx;
                client.Connect();
                Thread th = new Thread(new ParameterizedThreadStart(ProcSendCommand));
                m_ThreadPool.Add(th);
                th.Start(client);
            }
        }
예제 #14
0
 private void InitSocket(string ip, int port)
 {
     try
     {
         InitAsyncTimer();
         if (this.asyncClient != null)
         {
             this.asyncClient.Dispose();
             this.asyncClient.onConnected  -= new AsyncClient.Connected(client_onConnected);
             this.asyncClient.onDisConnect -= new AsyncClient.DisConnect(client_onDisConnect);
             this.asyncClient.onDataByteIn -= new AsyncClient.DataByteIn(client_onDataByteIn);
         }
         asyncClient              = new AsyncClient();
         asyncClient.onConnected += new AsyncClient.Connected(client_onConnected);
         asyncClient.Connect(ip, port);
         asyncClient.onDataByteIn += new AsyncClient.DataByteIn(client_onDataByteIn);
         asyncClient.onDisConnect += new AsyncClient.DisConnect(client_onDisConnect);
     }
     catch (Exception ex)
     {
     }
 }
예제 #15
0
        static void Main(string[] args)
        {
            AsyncClient client = new AsyncClient(1024, 1024 * 4, new Loger());

            client.OnReceived   += ReceiveCommond;
            client.OnConnected  += Connected;
            client.OnDisConnect += DisConnected;
            client.Connect(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8088));
            Console.ReadLine();
            short i = 0;

            while (i < 5)
            {
                Task.Delay(1).Wait();
                i++;
                var data = Encoding.UTF8.GetBytes("测试数据" + i);
                Session.SendAsync(new SendCommond()
                {
                    CommondId = i, Buffer = data
                });
            }
            Console.ReadLine();
        }
예제 #16
0
 private void OnConnectButtonClick(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(txtIP.Text))
     {
         asyncClient.SetConnectionForClient(txtIP.Text);
         if (exceptionThrown)
         {
             exceptionThrown = !exceptionThrown;
             return;
         }
         asyncClient.Connect();
         SetControlsForConnection();
         exceptionThrown = false;
     }
     else
     {
         if (string.IsNullOrEmpty(txtIP.Text))
         {
             MessageBox.Show(this, Resources.Warning_EmptyIpAddress, Resources.Warning_Title_EmptyIpAddress,
                             MessageBoxButtons.OK, MessageBoxIcon.Warning);
             return;
         }
     }
 }
예제 #17
0
 private void ReConnect()
 {
     asyncClient.Dispose();
     asyncClient.Connect(_ip, _port);
 }
예제 #18
0
 private void ReConnect()
 {
     asyncClient.Dispose();
     asyncClient.Connect(ConfigHelper.GetInstace().ZoneIP, ConfigHelper.GetInstace().ZonePort);
 }
예제 #19
0
        private void ConnectButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (!connected)
                {
                    connected         = true;
                    ChatTextBox.Text += "Trying to Connect...\n";

                    if (ServerPortBox.Value == 8891)
                    {
                        client        = new AsyncClient(ServerIpBox.Text, 8891, true);
                        connectedPort = 8891;
                        Thread listener = new Thread(delegate() { while (client.Client.Connected)
                                                                  {
                                                                      SetChatBox(client.RecieveEncryptedWithRsa());
                                                                  }
                                                     })
                        {
                            IsBackground = true
                        };
                        client.Connect();
                        listener.Start();
                    }
                    else if (ServerPortBox.Value == 8889)
                    {
                        client        = new AsyncClient(ServerIpBox.Text, 8889);
                        connectedPort = 8889;
                        Thread listener = new Thread(delegate() { while (client.Client.Connected)
                                                                  {
                                                                      SetChatBox(client.Recieve());
                                                                  }
                                                     })
                        {
                            IsBackground = true
                        };
                        client.Connect();
                        listener.Start();
                    }
                    else if (ServerPortBox.Value == 8890)
                    {
                        client        = new AsyncClient(ServerIpBox.Text, 8890);
                        connectedPort = 8890;
                        Thread listener = new Thread(delegate() { while (client.Client.Connected)
                                                                  {
                                                                      SetChatBox(client.RecieveEncrypted());
                                                                  }
                                                     })
                        {
                            IsBackground = true
                        };
                        client.Connect();
                        listener.Start();
                    }
                    else if (ServerPortBox.Value == 88901)
                    {
                        client        = new AsyncClient(ServerIpBox.Text, 8890);
                        connectedPort = 88901;
                        Thread listener = new Thread(delegate() { while (client.Client.Connected)
                                                                  {
                                                                      SetChatBox(client.RecieveDeepEncrypted());
                                                                  }
                                                     })
                        {
                            IsBackground = true
                        };
                        client.Connect();
                        listener.Start();
                    }
                    ChatTextBox.Text += "Connected to: " + ServerIpBox.Text + "\n";
                    this.SelectNextControl((Control)sender, true, true, true, true);
                }
                else
                {
                    ChatTextBox.Text += "Already Connected.\n";
                }
            }
            catch
            {
                ChatTextBox.Text += "Connection Failed.\n";
            }
        }
예제 #20
0
파일: Program.cs 프로젝트: liwl/sunsocket
 static void Main(string[] args)
 {
     AsyncClient client = new AsyncClient(1024, 1024 * 4, new Loger());
     client.OnReceived+= ReceiveCommond;
     client.OnConnected += Connected;
     client.Connect(new IPEndPoint(IPAddress.Parse("127.0.0.1"),9989));
     Console.ReadLine();
     short i =0;
     while (i<5)
     {
         Task.Delay(1).Wait();
         i++;
         var data = Encoding.UTF8.GetBytes("测试数据"+i);
         Session.SendAsync(new SendCommond() { CommondId = i, Buffer = data });
     }
     Console.ReadLine();
 }
예제 #21
0
 /// <summary>
 /// Establishes a connection to the Factory Orchestrator Service.
 /// Throws an exception if it cannot connect.
 /// </summary>
 /// <param name="ignoreVersionMismatch">If true, ignore a Client-Service version mismatch.</param>
 public void Connect(bool ignoreVersionMismatch = false)
 {
     AsyncClient.Connect(ignoreVersionMismatch).Wait();
     OnConnected?.Invoke();
 }