class1.cs
来自「原代码详细说明是关于c++方面的希望可以帮助大家使用」· CS 代码 · 共 23 行
CS
23 行
using System;
using System.Net;
using System.Net.Sockets;
class Server
{
static void Main(string[] args)
{
IPAddress ip=IPAddress.Parse("127.0.0.1");
IPEndPoint iep=new IPEndPoint(ip,5555);
Socket mySocket=new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
mySocket.Bind(iep);
mySocket.Listen(10);
Socket myClient=mySocket.Accept();
myClient.Send(System.Text.Encoding.Unicode.GetBytes("连接成功"));
byte []buf=new byte[1024];
int k=myClient.Receive(buf);
System.Console.WriteLine(System.Text.Encoding.Unicode.GetString(buf,0,k));
myClient.Send(System.Text.Encoding.Unicode.GetBytes("客户你好"));
myClient.Shutdown(SocketShutdown.Both);
myClient.Close();
mySocket.Close();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?