c# - TCP / IP客户端-服务器,c#中的词法分析器
问题描述
我正在编写一个 TCP / IP 客户端服务器,分析一个词法分析器来检查 Pascal 的程序。请
告诉我如何重新制作程序以便使用池线程处理来自客户端的查询?
客户端。代码如下所示:
using System;
using System.Net.Sockets;
using System.Text;
namespace Client
{
class Program
{
static Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
static void Main(string[] args)
{
socket.Connect("127.0.0.1", 904);
string message = "proc1('2',2);";//Console.ReadLine();
byte[] buffer = Encoding.UTF8.GetBytes(message);
socket.Send(buffer);
Console.ReadLine();
}
}
}
服务器。代码如下所示:
using System;
using System.Net.Sockets;
using System.Text;
using System.Net;
using System.Text.RegularExpressions;
namespace Server
{
class Program
{
static Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
static void Main(string[] args)
{
socket.Bind(new IPEndPoint(IPAddress.Any,904));
socket.Listen(10);
Socket client = socket.Accept();
Console.WriteLine("Connected");
byte[] buffer = new byte[256];
client.Receive(buffer);
string s = Encoding.UTF8.GetString(buffer);
Regex regex = new Regex(@"^[_a-zA-Z]\w*\((?:(?:'[\d\w_]+'|""[\d\w_]*""|[\d\w_]+),?)*\);");
MatchCollection matches = regex.Matches(s);
if (matches.Count > 0)
{
foreach (Match match in matches)
Console.WriteLine("true: {0}",match.Value);
}
else
{
Console.WriteLine("false");
}
Console.ReadLine();
}
}
}
解决方案
推荐阅读
- java - 反序列化 Jackson 抽象类和多个具体类
- sml - 使用中缀运算符连接列表中的所有元素
- react-native - React Native 中未生成短动态链接
- terraform - 子模块不继承提供者
- sabre - 讨价还价者 Max
- c# - 如何在 Blazor 中创建 div 元素
- mysql - 在 1 个查询中组合 2 个逻辑 SQL 语句
- python - Python温度转换器输出为无
- ios - Branch.io 延迟的深层链接在服务器上存储多长时间?
- react-native - React Native Modal Date Picker - 为什么我得到一个额外的窗口?