Socket服务器端程序:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
namespace SocketServer
{
class Program
{
static void Main(string[] args)
{
IPAddress ip = IPAddress.Parse("127.0.0.1");//服务器端IP地址
IPEndPoint iep = new IPEndPoint(ip, 5555);//服务端地址及端口
//1.建立套接字,以Tcp协议链接,字节流的方式进行数据传输
Socket MySocket = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
//设置Socket地址可重复使用
// MySocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
//2.绑定套接字
MySocket.Bind(iep);
//3.监听套接字
MySocket.Listen(10);
//4.等待客户端请求
Socket MyClient = MySocket.Accept();
//5.向客户端发送消息
MyClient