📄 mytcpserver.cs
字号:
using System;
using System.Net.Sockets;
using System.Text;
namespace HelloWorld
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class MyTcpServer
{
private const int portNum = 9999;
public static int Main(String[] args)
{
bool done = false;
TcpListener listener = new TcpListener(portNum);
listener.Start();
while (!done)
{
Console.Write("Waiting for connection...");
TcpClient client = listener.AcceptTcpClient();
Console.WriteLine("Connection accepted.");
NetworkStream ns = client.GetStream();
string WelcomeString="Hello The World!";
byte[] byteTime = Encoding.ASCII.GetBytes(WelcomeString);
try
{
ns.Write(byteTime, 0, byteTime.Length);
ns.Close();
client.Close();
done=true;
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
listener.Stop();
Console.ReadLine();
return 0;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -