winform中socket实现即时通讯(仿qq聊天)

本文介绍如何在C# Winform应用中利用Socket技术实现即时通讯功能,模仿QQ聊天。提供了服务器端的代码示例,经过验证可正常运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

C# winform中使用socket实现即时通讯,仿照qq聊天,此为服务器端代码,亲测可行,代码如下

using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Threading;


namespace FormServer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        Socket socketsend;//负责发送信息的socket
        /// <summary>
        /// 点击发送按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_send_Click(object sender, EventArgs e)
        {
            string strsend = this.richTB_send.Text.Trim();
            if (strsend == "")
            {
                MessageBox.Show("输入内容不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                byte[] buffer = Encoding.UTF8.GetBytes(strsend);//将信息转化为字符类型,方式为utf-8
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值