c#实现简单的即时通讯(2)----客户端
来源:互联网 发布:windows找不到文件c 编辑:程序博客网 时间:2024/05/17 02:56
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Net;using System.Net.Sockets;using System.Text;using System.Threading;using System.Threading.Tasks;using System.Windows.Forms;namespace MyClient{ public partial class From1 : Form { public From1() { InitializeComponent(); TextBox.CheckForIllegalCrossThreadCalls = false; } Socket socketClient = null; Thread threadClient = null; private void ButtonConnect_Click(object sender, EventArgs e) { socketClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPAddress ipaddress = IPAddress.Parse(TextBoxIP.Text.Trim()); IPEndPoint endpoint = new IPEndPoint(ipaddress, int.Parse(TextBoxPort.Text.Trim())); socketClient.Connect(endpoint); threadClient = new Thread(RecMsg); threadClient.IsBackground = true; threadClient.Start(); } private void RecMsg() { while (true) { byte[] arrRecMsg = new byte[1024 * 1024]; int length = socketClient.Receive(arrRecMsg); string strRecMsg = Encoding.UTF8.GetString(arrRecMsg, 0, length); TextBoxRecord.AppendText(DateTime.Now.ToString() + "\r\n" + strRecMsg + "\r\n"); } } private void ClientSendMsg(string sendMsg) { byte[] arrClientSendMsg = Encoding.UTF8.GetBytes(sendMsg); socketClient.Send(arrClientSendMsg); TextBoxRecord.AppendText(DateTime.Now.ToString() + "\r\n" + sendMsg + "\r\n"); } private void ButtonSendMessage_Click(object sender, EventArgs e) { ClientSendMsg(TextBoxMessage.Text.Trim()); } private void TextBoxMessage_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { ClientSendMsg(TextBoxMessage.Text.Trim()); } } }}
阅读全文
0 0
- c#实现简单的即时通讯(2)----客户端
- c#实现简单的即时通讯(1)----服务端
- C#实现的简单ftp客户端
- C#局域网下的简单即时通讯案例
- 【转载】即时通讯实现其实挺简单的
- Android即时通讯工具的简单实现
- c# 实现局域网即时通讯
- 基于XMPP协议的即时通讯工具的客户端实现原理
- 基于XMPP协议的即时通讯工具的客户端实现原理
- 使用socket实现服务器客户端即时通讯的小例子
- 即时通讯里android客户端心跳机制的分析和实现
- c#实现的一个简单的FTP客户端
- 简单的企业即时通讯
- C# Winform Socket 即时通讯 (客户端+服务端)
- 基于环信的仿QQ即时通讯的简单实现
- C#服务器客户端通信简单实现
- python学习系列(八) --- socket实现简单的即时通讯
- ios实现一个简单的XMPP即时通讯程序
- java Map与Object互转
- MySQL存储引擎详解
- Android设备拍照详解
- 管理员登录与退出(自动登录)
- Swift基础之Literal的简单使用
- c#实现简单的即时通讯(2)----客户端
- Access denied for user ''@'localhost' (using password: YES)错误
- 浅谈JS DDoS攻击原理与防御
- gitLab搭建
- TP的中文验证实现
- 抓取html页面中的json数据
- TabLayout的TabItem自定义
- Centos7 安装Qt
- Python 3从入门到精通2-打印语句