using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace SocketServer
{
class Program
{
static Socket ServerSocket;
static Socket MyClient;
static void Main(string[] args)
{
IPAddress ip = IPAddress.Parse("127.0.0.1");//服务器端IP地址
IPEndPoint iep = new IPEndPoint(ip, 5555);//服务端地址及端口
//1.建立套接字,以Tcp协议链接,字节流的方式进行数据传输
ServerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
//设置Socket地址可重复使用
ServerSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
//2.绑定套接字
ServerSocket.Bind(iep);
//3.监听套接字
ServerSocket.Listen(10);
//4.等待客户端请
C#笔记,socket通信代码
最新推荐文章于 2021-11-30 09:57:42 发布