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(obj