控制台程序2个
1.TCPServer的控制台应用程序,作为服务端
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;//
using System.Net.Sockets;
namespace TcpServer
{
class Program
{
static void Main(string[] args)
{
TcpListener server = null;
Console.Write("请输入监听的端口号:");
string strPort = Console.ReadLine();
try
{
int port = Convert.ToInt32(strPort);
IPEndPoint listenPort = new IPEndPoint(IPAddress.Any, port);
server = new TcpListener(listenPort);//初始化TcpListener的新实例
server.Start();//开始监听客户端的请求
Byte[] bytes = new Byte[256];//缓存读入的数据
String data = null;
while (true)//循环监听
{
Console.Write("服

本文提供了一个C#控制台程序示例,包括服务器端(TCPServer)和客户端(TcpClients),详细展示了如何使用TcpListener和TcpClient进行双向通信。通过输入服务器IP地址和端口号,客户端可以连接到服务器并进行消息收发。服务器端监听指定端口,接收到客户端消息后回显并等待新的连接。
最低0.47元/天 解锁文章
6535

被折叠的 条评论
为什么被折叠?



