📄 program.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
namespace TCPClient
{
class Program
{
static void Main(string[] args)
{
try
{
TcpClient tcpc = new TcpClient("127.0.0.1", 10000);
NetworkStream ns = tcpc.GetStream();
while (true)
{
string input = Console.ReadLine();
byte[] data = Encoding.ASCII.GetBytes(input);
ns.Write(data, 0, data.Length);
byte[] inbyte = new byte[1024];
int recv = ns.Read(inbyte, 0, inbyte.Length);
Console.WriteLine(Encoding.ASCII.GetString(inbyte, 0, recv) + " from" + tcpc.Client.RemoteEndPoint.ToString());
}
ns.Close();
tcpc.Close();
}
catch (Exception e)
{
Console.WriteLine("先开服务端!");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -