C# socket详解
来源:百度知道 编辑:UC知道 时间:2024/05/15 09:09:12
可结合实例或是网上的材料,但请不要复制MSDN里的东西。我的目标是大概明白、会用就行。如果答案好的话,让我大有收获,我不会吝惜分数。
服务器端代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Net;
using System.Net.Sockets;
namespace ChatToolServer
{
public partial class Form1 : Form
{
//server-用于处理客户端连接请求的socket
Socket clientSocket = null;
delegate void del();
public Form1()
{
InitializeComponent();
}
//server-侦听方法
private void listen()
{
//获取服务器IP
string hostName = Dns.GetHostName();
IPAddress[] ip = Dns.GetHostAddresses(hostName);
IPAddress HostIp = ip[0];
//创建一个网络端点
IPEndPoint iep = new IPEndPoint(HostIp, 82);