private void cmdConnetc_Click(object sender, EventArgs e) { try { channel = Beetle.TcpServer.CreateClient<Messages.HeadSizePackage>(txtIPAddress.Text, 9450,OnReceive); channel.ChannelDisposed += OnDisposed; channel.ChannelError += OnError; channel.BeginReceive(); cmdRegister.Enabled = true; } catch (Exception e_) { MessageBox.Show(e_.Message); } }
private void cmdConnect_Click(object sender, EventArgs e) { try { mChannel = Beetle.TcpServer.CreateClient<Beetle.Protobuf.Package>( txtIPAddress.Text, 9321, OnReveive); mChannel.ChannelDisposed += OnDisposed; cmdRegister.Enabled = !(cmdConnect.Enabled = false); mChannel.BeginReceive(); } catch (Exception e_) { MessageBox.Show(e_.Message); } }
private void cmdConnetc_Click(object sender, EventArgs e) { try { channel = Beetle.TcpServer.CreateClient <EncryptPackage>(txtIPAddress.Text, 8088, OnReceive); channel.ChannelDisposed += OnDisposed; channel.ChannelError += OnError; channel.BeginReceive(); cmdRegister.Enabled = true; } catch (Exception e_) { MessageBox.Show(e_.Message); } }
private void cmdConnect_Click(object sender, EventArgs e) { try { mChannel = Beetle.TcpServer.CreateClient <Beetle.Protobuf.Package>( txtIPAddress.Text, 9321, OnReveive); mChannel.ChannelDisposed += OnDisposed; cmdRegister.Enabled = !(cmdConnect.Enabled = false); mChannel.BeginReceive(); } catch (Exception e_) { MessageBox.Show(e_.Message); } }
// 连接方法主动发连接事件 public bool do_Connect(string ip, int port) { if (_Connected) { return(true); } IP = ip; Port = port; try { m_channel = Beetle.TcpServer.CreateClient(ip, port); // 连接到指定IP的端口服务 System.Threading.Thread.Sleep(100); m_channel.ChannelDisposed += _evt_Disposed; // 连接断开事件 m_channel.DataReceive = _evt_DataReceived; // 绑定数据流接收事件 m_channel.ChannelError += (o, err) => // 组件错误 { Console.WriteLine(err.Exception.Message); }; m_channel.BeginReceive(); // 开始接收数据 _Connected = m_channel.Socket.Connected; // ; if (_Connected) { IP = ip; Port = port; if (hasEvent) { OnConnect(_Connected, string.Format("{0}:{1}", IP, Port)); } } return(_Connected);// m_channel.Socket.Connected; } catch (System.Net.Sockets.SocketException ex_) { ErrorCode = -101; // MessageBox.Show("-101: 请确认[" + ip + ":" + port.ToString() + "]服务器已打开. "); Console.WriteLine(ex_.Message); // 由于目标计算机积极拒绝,无法连接 } catch (Exception e_) { ErrorCode = -100; MessageBox.Show("-100:" + e_.Message); //Console.WriteLine(e_.Message); } return(false); }
private void cmdConnect_Click(object sender, EventArgs e) { try { //连接到指定IP的端口服务 channel = Beetle.TcpServer.CreateClient(txtIPAddress.Text, 9321); //绑定数据流接收事件 channel.DataReceive = OnReceive; //连接断开事件 channel.ChannelDisposed += OnDisposed; channel.ChannelError += (o, err) => { System.Console.WriteLine(err.Exception.Message); }; //开始接收数据 channel.BeginReceive(); cmdSend.Enabled = true; cmdConnect.Enabled = false; } catch (Exception e_) { MessageBox.Show(e_.Message); } }
private void cmdConnect_Click(object sender, EventArgs e) { try { //连接到指定IP的端口服务 channel = Beetle.TcpServer.CreateClient(txtIPAddress.Text, 9321); //绑定数据流接收事件 channel.DataReceive = OnReceive; //连接断开事件 channel.ChannelDisposed += OnDisposed; channel.ChannelError += (o, err) => { System.Console.WriteLine(err.Exception.Message); }; //开始接收数据 channel.BeginReceive(); cmdSend.Enabled = true; cmdConnect.Enabled = false; } catch (Exception e_) { MessageBox.Show(e_.Message); } }