/// <summary> /// 关闭 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { TCPClientManager manager = new TCPClientManager(_client_id); manager.DisConnect(); Close(); }
// Use this for initialization void Start() { Debug.Log(SystemInfomation.IPAddress); tcpServer = new TCPServerManager(8001); tcpClient = new TCPClientManager("192.168.1.5", 8001); tcpClient.ListenerMessageEvent += ListenerMessageEvent; currentcontext = SynchronizationContext.Current; }
/// <summary> /// 窗体加载 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void frmTCPClient_Load(object sender, EventArgs e) { Text = "TCPClient " + _client_id; //注册事件 TCPClientManager manager = new TCPClientManager(_client_id); //访问客户端 manager.TCPMessageReceived += new TCPMessageReceivedEventHandler(manager_TCPMessageReceived); manager.TCPClientDisConnected4Pulse += new TCPClientDisConnected4PulseEventHandler(manager_TCPClientDisConnected4Pulse); manager.TCPClientDisConnected += new TCPClientDisConnectedEventHandler(manager_TCPClientDisConnected); }
protected override void ConfigClient() { try { base.ConfigClient(); mgr = new TCPClientManager <T>(); mgr.InitializeManager(_productType, Config.WcfConfigModel.BaseAddress, Config.WcfConfigModel.Port); mgr.MsgReceiveEvent += Mgr_MsgReceiveEvent; } catch (Exception ex) { throw new Exception("配置联网信息失败"); } }
protected override ClientConnection ConnectClient(String clientName, String connectionString, String authToken) { //client manager wtih default connection localhost var clientMgr = new TCPClientManager(OnClientConnect); if (_cmSourceName != null) { clientMgr.Tracing = Chetch.Utilities.Config.TraceSourceManager.GetInstance(_cmSourceName); } clientMgr.AddServer("default", connectionString == null ? TCPServer.LocalCS(TCPMessagingServer.CONNECTION_REQUEST_PORT) : connectionString); var client = clientMgr.Connect(clientName, 10000, authToken); return(client); }
/// <summary> /// 创建客户端 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { if (TCPClientManager.ClientExist(textBox3.Text)) { MessageBox.Show("客户端已存在!"); return; } TCPClientManager manager = new TCPClientManager(textBox3.Text); //创建客户端 manager.Connect(textBox1.Text, int.Parse(textBox2.Text)); frmTCPClient frmtcpclient = new frmTCPClient(textBox3.Text); frmtcpclient.Show(); }
/// <summary> /// 发送图片 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button3_Click(object sender, EventArgs e) { using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.Filter = "图片文件|*.jpg;*jpeg"; if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { textBox3.Text = ofd.FileName; Image image = Image.FromFile(textBox3.Text); using (MemoryStream ms = new MemoryStream()) { image.Save(ms, ImageFormat.Jpeg); TCPClientManager manager = new TCPClientManager(_client_id); manager.SendAsync(Msg.Zmsg2, ms.ToArray(), null); //异步发送图片 } } } }
/// <summary> /// 发送文本 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button2_Click(object sender, EventArgs e) { TCPClientManager manager = new TCPClientManager(_client_id); manager.Send(Msg.Zmsg1, Encoding.Unicode.GetBytes(textBox2.Text)); //同步发送文本 }