{"id":39842,"date":"2025-05-26T09:01:36","date_gmt":"2025-05-26T01:01:36","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/39842.html"},"modified":"2025-05-26T09:01:36","modified_gmt":"2025-05-26T01:01:36","slug":"%e4%bd%bf%e7%94%a8-proto-actor-%e6%9e%84%e5%bb%ba-tcp-%e6%9c%8d%e5%8a%a1%e5%99%a8%ef%bc%9a%e6%8e%a2%e7%b4%a2-net-%e4%b8%ad%e7%9a%84-actor-%e6%a8%a1%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/39842.html","title":{"rendered":"\u4f7f\u7528 Proto.Actor \u6784\u5efa TCP \u670d\u52a1\u5668\uff1a\u63a2\u7d22 .NET \u4e2d\u7684 Actor \u6a21\u578b"},"content":{"rendered":"<h2>\u7b80\u4ecb<\/h2>\n<p>\u5728\u4e0a\u4e00\u7bc7\u6587\u7ae0 \u4e2d&#xff0c;\u6211\u6f14\u793a\u4e86 Proto.Actor&#xff08;\u9002\u7528\u4e8e .NET \u7684 Actor \u6a21\u578b\u6846\u67b6&#xff09;\u7684\u57fa\u7840\u7528\u6cd5\u3002\u672c\u6587\u5c06\u6784\u5efa\u4e00\u4e2a\u66f4\u590d\u6742\u7684\u793a\u4f8b&#xff1a;\u4f7f\u7528\u4e09\u4e2a Actor \u5b9e\u73b0 TCP \u670d\u52a1\u5668&#xff0c;\u5206\u522b\u5904\u7406\u8fde\u63a5\u3001\u5b57\u8282\u63a5\u6536\u548c\u6570\u636e\u5904\u7406\u3002<\/p>\n<h2>\u9879\u76ee\u6982\u8ff0<\/h2>\n<h4>\u6838\u5fc3 Actor<\/h4>\n<p>1. WaitForTcpConnectionActor<\/p>\n<ul>\n<li>\u00a0\u76d1\u542c\u65b0\u7684 TCP \u8fde\u63a5\u3002<\/li>\n<li>\u4e3a\u6bcf\u4e2a\u8fde\u63a5\u751f\u6210 ReceiveBytesActor \u5b9e\u4f8b\u3002<\/li>\n<\/ul>\n<p>2.\u00a0ReceiveBytesActor<\/p>\n<ul>\n<li>\u4ece\u5957\u63a5\u5b57\u63a5\u6536\u5b57\u8282\u6d41\u3002<\/li>\n<li>\u751f\u6210 ProcessActor \u5b9e\u4f8b\u4ee5\u53cd\u5e8f\u5217\u5316\u5e76\u8bb0\u5f55\u6570\u636e&#xff1b;\u82e5\u5931\u8d25\u6700\u591a\u91cd\u542f 3 \u6b21\u3002<\/li>\n<\/ul>\n<p>3.\u00a0ProcessActor<\/p>\n<ul>\n<li>\u5c06\u4f20\u5165\u5b57\u8282\u53cd\u5e8f\u5217\u5316\u4e3a Sample \u5bf9\u8c61\u3002<\/li>\n<li>\u5c06\u5bf9\u8c61\u5185\u5bb9\u8f93\u51fa\u5230\u63a7\u5236\u53f0\u3002<\/li>\n<\/ul>\n<h3>\u8981\u6c42<\/h3>\n<ul>\n<li>.NET 8 \u6216\u66f4\u9ad8\u7248\u672c<\/li>\n<li>NuGet \u5305 &#xff1a;\n<ul>\n<li>Proto.Actor<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>\u542f\u52a8 Actor \u7cfb\u7edf<\/h2>\n<p>\u914d\u7f6e Actor \u7cfb\u7edf\u4ee5\u751f\u6210 WaitForTcpConnectionActor&#xff0c;\u5e76\u5728\u6309\u4e0b Ctrl&#043;C \u65f6\u505c\u6b62\u5b83&#xff1a;<\/p>\n<p>using Proto;<br \/>\nusing TcpServer;<\/p>\n<p>var system &#061; new ActorSystem();<\/p>\n<p>var cancellationTokenSource &#061; new CancellationTokenSource();<br \/>\nConsole.CancelKeyPress &#043;&#061; (_, _) &#061;&gt;<br \/>\n{<br \/>\n    cancellationTokenSource.Cancel();<br \/>\n};<\/p>\n<p>system.Root.Spawn(Props.FromProducer(() &#061;&gt; new WaitForTcpConnectionActor(9091)));<\/p>\n<p>while (!cancellationTokenSource.IsCancellationRequested)<br \/>\n{<br \/>\n    await Task.Delay(1_000);<br \/>\n}<\/p>\n<p>await system.ShutdownAsync(); <\/p>\n<h2>\u7b49\u5f85 TCP \u8fde\u63a5\u7684 Actor<\/h2>\n<p>Actor \u6a21\u578b\u901a\u8fc7 Actor \u4e4b\u95f4\u4f20\u9012\u6d88\u606f\u5b9e\u73b0\u901a\u4fe1\u3002\u6211\u4eec\u5c06\u4f7f\u7528\u5185\u7f6e\u6d88\u606f&#xff08;\u5982 Started \u548c Terminated&#xff09;\u4ee5\u53ca\u81ea\u5b9a\u4e49\u6d88\u606f WaitForNextConnection\u3002<\/p>\n<p>\u5982\u4e0a\u4e00\u7bc7\u6587\u7ae0 \u6240\u793a&#xff0c;Actor \u7684\u5b9a\u4e49\u65b9\u5f0f\u5982\u4e0b&#xff1a;<\/p>\n<p>public class WaitForTcpConnectionActor(int port) : IActor<br \/>\n{<br \/>\n    public async Task ReceiveAsync(IContext context)<br \/>\n    {<br \/>\n    }<br \/>\n} <\/p>\n<h3>\u542f\u52a8 TCP \u76d1\u542c\u5668<\/h3>\n<p>\u7b2c\u4e00\u6b65\u662f\u542f\u52a8 TCP \u670d\u52a1\u5668\u3002\u4e3a\u6b64&#xff0c;\u6211\u4eec\u4f7f\u7528\u5185\u7f6e\u7684 Started \u6d88\u606f&#xff1a;<\/p>\n<p>public class WaitForTcpConnectionActor(int port) : IActor<br \/>\n{<br \/>\n    private TcpListener? _listener;<\/p>\n<p>    public async Task ReceiveAsync(IContext context)<br \/>\n    {<br \/>\n        if (context.Message is Started)<br \/>\n        {<br \/>\n            Console.WriteLine(&#034;\u6b63\u5728 9091 \u7aef\u53e3\u76d1\u542c&#034;);<br \/>\n            _listener &#061; TcpListener.Create(port);<br \/>\n            _listener.Start();<br \/>\n        }<br \/>\n    }<br \/>\n} <\/p>\n<p>\u968f\u540e&#xff0c;\u7b49\u5f85\u5ba2\u6237\u7aef\u8fde\u63a5\u3002\u4e3a\u6b64&#xff0c;\u6211\u4eec\u9700\u8981\u5411\u81ea\u8eab\u53d1\u9001\u4e00\u6761 WaitForNextConnection \u6d88\u606f&#xff1a;<\/p>\n<p>public class WaitForTcpConnectionActor(int port) : IActor<br \/>\n{<br \/>\n    private TcpListener? _listener;<br \/>\n    public async Task ReceiveAsync(IContext context)<br \/>\n    {<br \/>\n        if(context.Message is Started)<br \/>\n        {<br \/>\n            _listener &#061; TcpListener.Create(port);<br \/>\n            _listener.Start();<br \/>\n            context.Send(context.Self, new WaitForNextConnection());<br \/>\n        }<br \/>\n    }<br \/>\n} <\/p>\n<h3>\u7b49\u5f85 TCP \u8fde\u63a5<\/h3>\n<p>\u73b0\u5728\u6211\u4eec\u5df2\u5f00\u59cb\u76d1\u542c\u8fde\u63a5&#xff0c;\u4e0b\u4e00\u6b65\u662f\u63a5\u6536\u5b83\u4eec&#xff0c;\u5e76\u4e3a\u6bcf\u4e2a\u8fde\u63a5\u751f\u6210\u65b0\u7684 ReceiveBytesActor \u5b9e\u4f8b&#xff1a;<\/p>\n<p>public class WaitForTcpConnectionActor(int port) : IActor<br \/>\n{<br \/>\n    &#8230;<br \/>\n    public async Task ReceiveAsync(IContext context)<br \/>\n    {<br \/>\n        if(context.Message is Started)<br \/>\n        {<br \/>\n            &#8230;<br \/>\n        }<br \/>\n        else if(context.Message is WaitForNextConnection)<br \/>\n        {<br \/>\n            var socket &#061; await _listener!.AcceptSocketAsync(cancellationToken);<br \/>\n            var actor &#061; context.Spawn(Props.FromProducer(() &#061;&gt; new ReceiveBytesActor()))<br \/>\n                .WithChildSupervisorStrategy(new OneForOneStrategy(<br \/>\n            (_, exception) &#061;&gt;<br \/>\n            {<br \/>\n                Console.WriteLine(&#034;Error: {0}&#034;, exception);<br \/>\n                return SupervisorDirective.Restart;<br \/>\n            },<br \/>\n            3,<br \/>\n            TimeSpan.FromSeconds(1)));;<br \/>\n            context.Send(actor, new SocketAccepted(socket));<br \/>\n            context.Send(context.Self, new WaitForNextConnection());<br \/>\n        }<br \/>\n    }<br \/>\n} <\/p>\n<h4>Actor \u76d1\u7763\u673a\u5236<\/h4>\n<p>\u6211\u4eec\u901a\u8fc7 OneForOneStrategy \u914d\u7f6e\u5bf9 ReceiveBytesActor \u5b9e\u4f8b\u7684\u76d1\u7763\u7b56\u7565&#xff1a;<\/p>\n<ul>\n<li>\u82e5\u5b50 Actor \u53d1\u751f\u6545\u969c &#xff0c;\u5b83\u5c06\u5728 1 \u79d2\u5185\u6700\u591a\u91cd\u542f 3 \u6b21 \u3002<\/li>\n<li>\u6b64\u7b56\u7565\u786e\u4fdd\u4e34\u65f6\u6027\u9519\u8bef &#xff08;\u5982\u6d88\u606f\u683c\u5f0f\u9519\u8bef&#xff09;\u4e0d\u4f1a\u5bfc\u81f4\u6574\u4e2a\u7cfb\u7edf\u5d29\u6e83 \u3002<\/li>\n<\/ul>\n<h3 style=\"background-color:transparent\">\u901a\u77e5\u5b8c\u6210<\/h3>\n<p>\u5f53\u5904\u7406\u5b8c\u6210\u540e&#xff0c;\u5b50 Actor \u4f1a\u5411\u7236 Actor \u53d1\u9001 ProcessCompleted \u6d88\u606f\u3002\u8fd9\u63d0\u793a\u7236 Actor \u663e\u5f0f\u505c\u6b62\u5b50 Actor &#xff0c;\u786e\u4fdd\u8d44\u6e90\u6e05\u7406\u5e76\u907f\u514d\u5185\u5b58\u6cc4\u6f0f\u3002<\/p>\n<p>public class WaitForTcpConnectionActor(int port) : IActor<br \/>\n{<br \/>\n    &#8230;<br \/>\n    public async Task ReceiveAsync(IContext context)<br \/>\n    {<br \/>\n        if(context.Message is Started)<br \/>\n        {<br \/>\n            &#8230;<br \/>\n        }<br \/>\n        else if(context.Message is { Message: Terminated, Sender: not null }))<br \/>\n        {<br \/>\n            _listener?.Dispose();<br \/>\n        }<br \/>\n        else if(context.Message is ProcessCompleted)<br \/>\n        {<br \/>\n            await context.StopAsync(Sender);<br \/>\n        }<br \/>\n        else if(context.Message is WaitForNextConnection)<br \/>\n        {<br \/>\n            &#8230;<br \/>\n        }<br \/>\n    }<br \/>\n} <\/p>\n<h4>\u8d44\u6e90\u6e05\u7406<\/h4>\n<p>\u5f53\u8fde\u63a5\u5904\u7406\u5b8c\u6210\u540e&#xff1a;<\/p>\n<ul>\n<li>ProcessCompleted \u6d88\u606f \u901a\u77e5\u4efb\u52a1\u5b8c\u6210\u3002<\/li>\n<li>\u7236 Actor \u505c\u6b62\u5b50 Actor \u5e76\u901a\u8fc7\u7ec8\u6b62 Actor \u89e6\u53d1\u8d44\u6e90\u6e05\u7406\u3002<\/li>\n<\/ul>\n<h3>\u5b8c\u6574\u7684 WaitForTcpConnectionActor \u4ee3\u7801<\/h3>\n<p>using System.Net.Sockets;<br \/>\nusing Proto;<\/p>\n<p>namespace TcpServer;<\/p>\n<p>public class WaitForTcpConnectionActor(int port) : IActor<br \/>\n{<br \/>\n    private static readonly Props Props &#061; Props.FromProducer(() &#061;&gt; new ReceiveBytesActor())<br \/>\n        .WithChildSupervisorStrategy(new OneForOneStrategy(<br \/>\n            (_, exception) &#061;&gt;<br \/>\n            {<br \/>\n                Console.WriteLine(&#034;Error: {0}&#034;, exception);<br \/>\n                return SupervisorDirective.Restart;<br \/>\n            },<br \/>\n            3,<br \/>\n            TimeSpan.FromSeconds(1)));<\/p>\n<p>    private TcpListener? _listener;<\/p>\n<p>    public async Task ReceiveAsync(IContext context)<br \/>\n    {<br \/>\n        if (context is { Message: Terminated, Sender: not null })<br \/>\n        {<br \/>\n            Close();<br \/>\n        }<br \/>\n        else if (context.Message is Started)<br \/>\n        {<br \/>\n            Open();<br \/>\n            context.Send(context.Self, new WaitForNextConnection());<br \/>\n        }<br \/>\n        else if (context.Message is ProcessCompleted)<br \/>\n        {<br \/>\n            Console.WriteLine(&#034;stopping actor: {0}&#034;, context.Sender);<br \/>\n            await context.StopAsync(context.Sender!);<br \/>\n        }<br \/>\n        else if(context.Message is WaitForNextConnection)<br \/>\n        {<br \/>\n            var socket &#061; await AcceptTcpClientAsync(context.CancellationToken);<br \/>\n            Console.WriteLine(&#034;Accepted connection from {0}&#034;, socket.RemoteEndPoint);<br \/>\n            var actor &#061; context.Spawn(Props);<br \/>\n            context.Send(actor, new SocketAccepted(socket));<br \/>\n            context.Send(context.Self, new WaitForNextConnection());<br \/>\n        }<br \/>\n    }<\/p>\n<p>    private void Open()<br \/>\n    {<br \/>\n        Close();<br \/>\n        Console.WriteLine(&#034;Listening on port 9091&#034;);<br \/>\n        _listener &#061; TcpListener.Create(port);<br \/>\n        _listener.Start();<br \/>\n    }<\/p>\n<p>    private async Task&lt;Socket&gt; AcceptTcpClientAsync(CancellationToken cancellationToken)<br \/>\n    {<br \/>\n        Console.WriteLine(&#034;Waiting for connection&#8230;&#034;);<br \/>\n        return await _listener!.AcceptSocketAsync(cancellationToken);<br \/>\n    }<\/p>\n<p>    private void Close()<br \/>\n    {<br \/>\n        Console.WriteLine(&#034;Closing listener&#034;);<br \/>\n        _listener?.Dispose();<br \/>\n    }<br \/>\n} <\/p>\n<h3 style=\"background-color:transparent\">\u4f18\u96c5\u5173\u95ed<\/h3>\n<p>\u5f53 Actor \u7cfb\u7edf\u5173\u95ed\u65f6&#xff0c;\u5fc5\u987b\u6b63\u786e\u91ca\u653e TCP \u76d1\u542c\u5668 &#xff0c;\u4ee5\u907f\u514d\u8d44\u6e90\u6cc4\u6f0f&#xff1a;<\/p>\n<p>public class WaitForTcpConnectionActor(int port) : IActor<br \/>\n{<br \/>\n    &#8230;<br \/>\n    public async Task ReceiveAsync(IContext context)<br \/>\n    {<br \/>\n        if(context.Message is Started)<br \/>\n        {<br \/>\n            &#8230;<br \/>\n        }<br \/>\n        else if(context.Message is { Message: Terminated, Sender: not null }))<br \/>\n        {<br \/>\n            _listener?.Dispose();<br \/>\n        }<br \/>\n        else if(context.Message is ProcessCompleted)<br \/>\n        {<br \/>\n           &#8230;.<br \/>\n        }<br \/>\n        else if(context.Message is WaitForNextConnection)<br \/>\n        {<br \/>\n            &#8230;<br \/>\n        }<br \/>\n    }<br \/>\n} <\/p>\n<h2>\u63a5\u6536\u5b57\u8282<\/h2>\n<p>\u4e0b\u4e00\u6b65\u662f\u4ece\u5957\u63a5\u5b57\u63a5\u6536\u5b57\u8282\u6d41&#xff1a;<\/p>\n<h3>\u5904\u7406 SocketAccepted \u4e8b\u4ef6<\/h3>\n<p>\u5f53\u65b0\u8fde\u63a5\u88ab\u63a5\u53d7\u65f6&#xff0c;Actor \u4f1a\u5b58\u50a8\u5957\u63a5\u5b57\u5b9e\u4f8b\u5e76\u8bfb\u53d6\u53ef\u7528\u5b57\u8282&#xff1a;<\/p>\n<p>public class ReceiveBytesActor : IActor<br \/>\n{<br \/>\n    private Socket? _socket;<br \/>\n    private byte[]? _buffer;<br \/>\n    public async Task ReceiveAsync(IContext context)<br \/>\n    {<br \/>\n        if(context.Message is SocketAccepted socket)<br \/>\n        {<br \/>\n            _socket &#061; socket;<br \/>\n            _buffer &#061; new byte[_socket.Available];<br \/>\n            await _socket.ReceiveAsync(_buffer);<\/p>\n<p>            var props &#061; Props.FromProducer(() &#061;&gt; new ProcessActor());<br \/>\n            var actor &#061; context.SpawnNamed(props, &#034;json-serializer&#034;);<br \/>\n            context.Send(actor, new SocketReceived(_buffer!));<br \/>\n        }<br \/>\n    }<br \/>\n} <\/p>\n<h3>\u901a\u77e5\u5b8c\u6210<\/h3>\n<p>\u5904\u7406\u5b8c\u6210\u540e&#xff0c;\u5f53\u524d Actor \u505c\u6b62\u5b50\u7ea7 ProcessActor \u5e76 \u901a\u77e5\u5176\u7236\u7ea7\u91ca\u653e\u8d44\u6e90 &#xff1a;<\/p>\n<p>public class ReceiveBytesActor : IActor<br \/>\n{<br \/>\n    &#8230;<\/p>\n<p>    public async Task ReceiveAsync(IContext context)<br \/>\n    {<br \/>\n        if(context.Message is SocketAccepted socket)<br \/>\n        {<br \/>\n            &#8230;<br \/>\n        }<br \/>\n        else if(context.Message is ProcessCompleted)<br \/>\n        {<br \/>\n             await context.StopAsync(Sender);<br \/>\n            context.Send(context.Parent!, new ProcessCompleted());<br \/>\n        }<br \/>\n    }<br \/>\n} <\/p>\n<h3>\u4f18\u96c5\u5173\u95ed\u5957\u63a5\u5b57<\/h3>\n<p>\u5f53 Actor \u7ec8\u6b62\u65f6&#xff0c;\u91ca\u653e\u5957\u63a5\u5b57\u8d44\u6e90 \u5e76\u505c\u6b62\u6240\u6709\u5b50\u7ea7 Actor \u4ee5\u9632\u6b62\u8d44\u6e90\u6cc4\u6f0f&#xff1a;<\/p>\n<p>public class ReceiveBytesActor : IActor<br \/>\n{<br \/>\n    &#8230;<\/p>\n<p>    public async Task ReceiveAsync(IContext context)<br \/>\n    {<br \/>\n        if(context.Message is Terminated)<br \/>\n        {<br \/>\n            _buffer &#061; null;<br \/>\n            _socket?.Dispose();<br \/>\n            await context.Children.StopMany(context);<br \/>\n        }<br \/>\n        else if(context.Message is SocketAccepted socket)<br \/>\n        {<br \/>\n            &#8230;<br \/>\n        }<br \/>\n        else if(context.Message is ProcessCompleted)<br \/>\n        {<br \/>\n           &#8230;<br \/>\n        }<br \/>\n    }<br \/>\n} <\/p>\n<h3>\u91cd\u65b0\u53d1\u9001\u7f13\u51b2\u6570\u636e<\/h3>\n<p>\u82e5 ProcessActor \u53d1\u751f\u6545\u969c\u5e76\u91cd\u542f&#xff0c;ReceiveBytesActor \u4f1a\u91cd\u65b0\u53d1\u9001\u5176\u7f13\u51b2\u533a\u4e2d\u7684\u6570\u636e\u4ee5\u91cd\u65b0\u5904\u7406&#xff1a;<\/p>\n<p>public class ReceiveBytesActor : IActor<br \/>\n{<br \/>\n    &#8230;<\/p>\n<p>    public async Task ReceiveAsync(IContext context)<br \/>\n    {<br \/>\n        if(context.Message is Terminated)<br \/>\n        {<br \/>\n            &#8230;<br \/>\n        }<br \/>\n        else if(context.Message is SocketAccepted socket)<br \/>\n        {<br \/>\n            &#8230;<br \/>\n        }<br \/>\n        else if(context.Message is ProcessCompleted)<br \/>\n        {<br \/>\n           &#8230;<br \/>\n        }<br \/>\n        else if(context.Message is ResendBufferReceived)<br \/>\n        {<br \/>\n           context.Send(Sender, new ResendBufferReceived(_buffer!));<br \/>\n        }<br \/>\n    }<br \/>\n} <\/p>\n<h3>\u5b8c\u6574\u7684 ReceiveBytesActor\u00a0\u4ee3\u7801<\/h3>\n<p>using System.Net.Sockets;<br \/>\nusing Proto;<\/p>\n<p>namespace TcpServer;<\/p>\n<p>public class ReceiveBytesActor : IActor<br \/>\n{<br \/>\n    private Socket? _socket;<br \/>\n    private byte[]? _buffer;<\/p>\n<p>    public async Task ReceiveAsync(IContext context)<br \/>\n    {<br \/>\n        if (context.Message is Terminated)<br \/>\n        {<br \/>\n            Console.WriteLine(&#034;Terminating actor&#034;);<br \/>\n            _buffer &#061; null;<br \/>\n            _socket?.Dispose();<br \/>\n            await context.Children.StopMany(context);<br \/>\n        }<br \/>\n        else if (context.Message is ProcessCompleted)<br \/>\n        {<br \/>\n            Console.WriteLine(&#034;Process completed&#034;);<br \/>\n            await context.StopAsync(context.Sender!);<br \/>\n            context.Send(context.Parent!, new ProcessCompleted());<br \/>\n        }<br \/>\n        else if (context.Message is SocketAccepted socketAccepted)<br \/>\n        {<br \/>\n            await SocketAccepted(socketAccepted.Socket);<\/p>\n<p>            var props &#061; Props.FromProducer(() &#061;&gt; new ProcessActor());<br \/>\n            var actor &#061; context.SpawnNamed(props, &#034;json-serializer&#034;);<br \/>\n            context.Send(actor, new BufferReceived(_buffer!));<br \/>\n        }<br \/>\n        else if (context.Message is ResendBufferReceived)<br \/>\n        {<br \/>\n            context.Send(context.Sender!, new BufferReceived(_buffer!));<br \/>\n        }<br \/>\n    }<\/p>\n<p>    private async Task SocketAccepted(Socket socket)<br \/>\n    {<br \/>\n        if (_socket !&#061; null)<br \/>\n        {<br \/>\n            return;<br \/>\n        }<\/p>\n<p>        _socket &#061; socket;<br \/>\n        _buffer &#061; new byte[_socket.Available];<br \/>\n        await _socket.ReceiveAsync(_buffer);<br \/>\n    }<br \/>\n} <\/p>\n<h2>ProcessActor<\/h2>\n<p>\u6700\u7ec8\u7684 Actor \u8d1f\u8d23\u53cd\u5e8f\u5217\u5316\u6570\u636e\u5e76\u8bb0\u5f55\u65e5\u5fd7&#xff1a;<\/p>\n<h3>BufferReceived \u6d88\u606f<\/h3>\n<p>BufferReceived \u6d88\u606f\u5305\u542b\u4ece\u5957\u63a5\u5b57\u63a5\u6536\u7684\u539f\u59cb\u5b57\u8282\u6d41\u3002\u8be5 Actor \u5c06\u6570\u636e\u53cd\u5e8f\u5217\u5316\u4e3a Sample \u5bf9\u8c61\u5e76\u8f93\u51fa\u5230\u63a7\u5236\u53f0\u3002\u5904\u7406\u5b8c\u6210\u540e&#xff0c;\u901a\u8fc7 ProcessCompleted \u6d88\u606f\u901a\u77e5\u7236\u7ea7 Actor&#xff08;ReceiveBytesActor&#xff09;\u6e05\u7406\u8d44\u6e90&#xff1a;<\/p>\n<p>public class ProcessActor : IActor<br \/>\n{<br \/>\n    public Task ReceiveAsync(IContext context)<br \/>\n    {<br \/>\n        if (context.Message is BufferReceived socketReceived)<br \/>\n        {<br \/>\n            var json &#061; JsonSerializer.Deserialize&lt;Sample&gt;(socketReceived.Data)!;<br \/>\n            Console.WriteLine(&#034;Received sample with id: {0} and name: {1}&#034;, json.Id, json.Name);<br \/>\n            context.Send(context.Parent!, new ProcessCompleted(context.Self));<br \/>\n        }<br \/>\n        return Task.CompletedTask;<br \/>\n    }<br \/>\n} <\/p>\n<h3>\u91cd\u542f\u673a\u5236<\/h3>\n<p>\u5f53 Actor \u53d1\u751f\u6545\u969c\u5e76\u91cd\u542f\u65f6&#xff0c;Proto.Actor \u4f1a\u5411\u8be5 Actor \u53d1\u9001 Restarting \u6d88\u606f\u3002\u8fd9\u4f7f\u5f97\u91cd\u542f\u7684 Actor \u80fd\u591f\u901a\u77e5\u5176\u7236\u7ea7\u91cd\u65b0\u4f20\u8f93\u539f\u59cb\u6d88\u606f&#xff08;\u6216\u72b6\u6001&#xff09;&#xff0c;\u4ee5\u4fbf\u91cd\u542f\u540e\u7684 Actor \u53ef\u4ee5\u91cd\u65b0\u5904\u7406\u8fd9\u4e9b\u6570\u636e<\/p>\n<p>public class ProcessActor : IActor<br \/>\n{<br \/>\n    public Task ReceiveAsync(IContext context)<br \/>\n    {<br \/>\n        if (context.Message is Restarting)<br \/>\n        {<br \/>\n            context.Send(context.Parent!, new ResendBufferReceived());<br \/>\n        }<br \/>\n        else if (context.Message is BufferReceived socketReceived)<br \/>\n        {<br \/>\n            var json &#061; JsonSerializer.Deserialize&lt;Sample&gt;(socketReceived.Data)!;<br \/>\n            Console.WriteLine(&#034;Received sample with id: {0} and name: {1}&#034;, json.Id, json.Name);<br \/>\n            context.Send(context.Parent!, new ProcessCompleted(context.Self));<br \/>\n        }<br \/>\n        return Task.CompletedTask;<br \/>\n    }<br \/>\n} <\/p>\n<h3>\u5b8c\u6574\u7684 ProcessActor \u4ee3\u7801<\/h3>\n<p>&#xfeff;using System.Text.Json;<br \/>\nusing Proto;<\/p>\n<p>namespace TcpServer;<\/p>\n<p>public class ProcessActor : IActor<br \/>\n{<br \/>\n    public Task ReceiveAsync(IContext context)<br \/>\n    {<br \/>\n        if (context.Message is Restarting)<br \/>\n        {<br \/>\n            context.Send(context.Parent!, new ResendBufferReceived());<br \/>\n        }<br \/>\n        else if (context.Message is BufferReceived socketReceived)<br \/>\n        {<br \/>\n            var json &#061; JsonSerializer.Deserialize&lt;Sample&gt;(socketReceived.Data)!;<br \/>\n            Console.WriteLine(&#034;Received sample with id: {0} and name: {1}&#034;, json.Id, json.Name);<br \/>\n            context.Send(context.Parent!, new ProcessCompleted());<br \/>\n        }<br \/>\n        return Task.CompletedTask;<br \/>\n    }<br \/>\n} <\/p>\n<h2>TCP \u5ba2\u6237\u7aef<\/h2>\n<p>\u6700\u540e&#xff0c;\u6211\u4eec\u6765\u5b9e\u73b0\u4e00\u4e2a\u7b80\u5355\u7684 TCP \u5ba2\u6237\u7aef&#xff0c;\u5b83\u4f1a\u5c06\u7528\u6237\u8f93\u5165\u8f6c\u6362\u4e3a JSON \u683c\u5f0f\u5e76\u53d1\u9001\u5230\u670d\u52a1\u5668&#xff1a;<\/p>\n<p>using System.Net.Sockets;<br \/>\nusing System.Text.Json;<br \/>\nusing TcpServer.Client;<\/p>\n<p>var id &#061; 0;<br \/>\nwhile (true)<br \/>\n{<br \/>\n    Console.Write(&#034;Type a name (q to quit\/f to non json): &#034;);<br \/>\n    var name &#061; Console.ReadLine();<br \/>\n    if (string.IsNullOrWhiteSpace(name))<br \/>\n    {<br \/>\n        continue;<br \/>\n    }<\/p>\n<p>    if (name &#061;&#061; &#034;q&#034;)<br \/>\n    {<br \/>\n        break;<br \/>\n    }<\/p>\n<p>    try<br \/>\n    {<br \/>\n        var connection &#061; new TcpClient();<br \/>\n        await connection.ConnectAsync(&#034;localhost&#034;, 9091);<\/p>\n<p>        var stream &#061; connection.GetStream();<br \/>\n        if (name &#061;&#061; &#034;f&#034;)<br \/>\n        {<br \/>\n            await stream.WriteAsync(new[] { (byte)&#039;f&#039;  });<br \/>\n        }<br \/>\n        else<br \/>\n        {<br \/>\n            await JsonSerializer.SerializeAsync(stream, new Sample<br \/>\n            {<br \/>\n                Id &#061; id&#043;&#043;,<br \/>\n                Name &#061; name,<br \/>\n            });<br \/>\n        }<br \/>\n        connection.Close();<br \/>\n    }<br \/>\n    catch (Exception e)<br \/>\n    {<br \/>\n        Console.WriteLine(&#034;Error: {0}&#034;,e);<br \/>\n    }<br \/>\n} <\/p>\n<h2>\u7ed3\u8bba<\/h2>\n<p>Proto.Actor \u5e93\u662f\u6784\u5efa\u5bb9\u9519\u7cfb\u7edf\u7684\u5f3a\u5927\u5de5\u5177&#xff0c;\u5b83\u5c55\u793a\u4e86 Actor \u6a21\u578b\u5982\u4f55\u7b80\u5316\u5e76\u53d1\u5904\u7406\u3001\u8d44\u6e90\u7ba1\u7406\u548c\u9519\u8bef\u6062\u590d\u3002\u901a\u8fc7\u4f7f\u7528\u4e09\u4e2a Actor&#xff08;WaitForTcpConnectionActor\u3001ReceiveBytesActor \u548c ProcessActor&#xff09;\u5b9e\u73b0 TCP \u670d\u52a1\u5668&#xff0c;\u6211\u4eec\u63a2\u7d22\u4e86\u4ee5\u4e0b\u6838\u5fc3\u6982\u5ff5&#xff1a;<\/p>\n<p>\u6838\u5fc3\u5b9e\u8df5<\/p>\n<ul>\n<li>\u76d1\u7763\u7b56\u7565 &#xff1a;\u901a\u8fc7 OneForOneStrategy \u914d\u7f6e\u5b50 Actor \u5728\u5931\u8d25\u65f6\u6700\u591a\u91cd\u542f 3 \u6b21&#xff0c;\u786e\u4fdd\u4e34\u65f6\u6027\u9519\u8bef&#xff08;\u5982\u6d88\u606f\u89e3\u6790\u5931\u8d25&#xff09;\u4e0d\u4f1a\u5bfc\u81f4\u7cfb\u7edf\u5d29\u6e83\u3002<\/li>\n<li>\u751f\u547d\u5468\u671f\u7ba1\u7406 &#xff1a;\u901a\u8fc7 Started\u3001Terminated \u548c Restarting \u7b49\u6d88\u606f\u5b89\u5168\u5730\u7ba1\u7406 Actor \u72b6\u6001\u548c\u8d44\u6e90\u91ca\u653e\u3002<\/li>\n<li>\u6d88\u606f\u5f39\u6027 &#xff1a;\u901a\u8fc7 ResendSocketAccepted \u548c ProcessCompleted \u7b49\u673a\u5236\u91cd\u8bd5\u5931\u8d25\u64cd\u4f5c&#xff0c;\u4fdd\u969c\u6570\u636e\u5b8c\u6574\u6027\u3002<\/li>\n<\/ul>\n<h3>\u5b66\u4e60\u4e0e\u751f\u4ea7\u73af\u5883\u7684\u6743\u8861<\/h3>\n<p>\u672c\u793a\u4f8b\u4e3a\u6559\u5b66\u76ee\u7684\u7b80\u5316\u4e86\u590d\u6742\u573a\u666f\u3002\u4f8b\u5982&#xff1a;<\/p>\n<li>\n<p>_socket.Available \u7684\u5c40\u9650\u6027<\/p>\n<ul>\n<li>\u6f14\u793a\u7528\u9014 &#xff1a;\u76f4\u63a5\u4f7f\u7528 Available \u5c5e\u6027\u8bfb\u53d6\u6570\u636e\u957f\u5ea6\u5728\u6f14\u793a\u4e2d\u4fbf\u6377&#xff0c;\u4f46\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u4e0d\u53ef\u9760&#xff08;\u53ef\u80fd\u8bfb\u53d6\u5230\u4e0d\u5b8c\u6574\u6570\u636e&#xff09;\u3002<\/li>\n<li>\u751f\u4ea7\u5efa\u8bae &#xff1a;\u91c7\u7528\u52a8\u6001\u7f13\u51b2&#xff08;\u5982 MemoryStream&#xff09;\u5904\u7406\u53d8\u957f\u6570\u636e\u6d41&#xff0c;\u5e76\u7ed3\u5408\u6d88\u606f\u8fb9\u754c\u6807\u8bc6&#xff08;\u5982\u524d\u7f00\u957f\u5ea6\u5b57\u6bb5&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u9519\u8bef\u5904\u7406\u7684\u6539\u8fdb<\/p>\n<ul>\n<li>\u5f53\u524d\u5b9e\u73b0 &#xff1a;\u7f3a\u4e4f\u5bf9\u8fb9\u7f18\u60c5\u51b5&#xff08;\u5982\u7578\u5f62\u8f93\u5165&#xff09;\u7684\u5065\u58ee\u5f02\u5e38\u5904\u7406\u3002<\/li>\n<li>\u751f\u4ea7\u5efa\u8bae &#xff1a;\u5c06\u5957\u63a5\u5b57\u64cd\u4f5c\u5305\u88f9\u5728 try-catch \u5757\u4e2d&#xff0c;\u5e76\u7cfb\u7edf\u5316\u8bb0\u5f55\u9519\u8bef\u65e5\u5fd7&#xff08;\u5982\u901a\u8fc7 Serilog \u7b49\u5de5\u5177&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u8d44\u6e90\u6e05\u7406\u7684\u589e\u5f3a<\/p>\n<ul>\n<li>\u57fa\u7840\u4fdd\u969c &#xff1a;ProcessCompleted \u6d88\u606f\u786e\u4fdd\u5957\u63a5\u5b57\u548c Actor \u88ab\u6b63\u786e\u91ca\u653e\u3002<\/li>\n<li>\u751f\u4ea7\u4f18\u5316 &#xff1a;\u6dfb\u52a0\u8d85\u65f6\u673a\u5236\u6216\u5fc3\u8df3\u68c0\u6d4b&#xff0c;\u907f\u514d\u5b64\u513f\u8fde\u63a5&#xff08;\u5982\u5ba2\u6237\u7aef\u5f02\u5e38\u65ad\u5f00\u540e\u8d44\u6e90\u672a\u91ca\u653e&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<h2>\u5b8c\u6574\u4ee3\u7801<\/h2>\n<p>GitHub \u4ed3\u5e93<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb789\u6b21\uff0c\u70b9\u8d5e24\u6b21\uff0c\u6536\u85cf8\u6b21\u3002\u672c\u6587\u4ecb\u7ecd\u4e86\u5982\u4f55\u4f7f\u7528Proto.Actor\u6846\u67b6\u6784\u5efa\u4e00\u4e2a\u590d\u6742\u7684TCP\u670d\u52a1\u5668\uff0c\u901a\u8fc7\u4e09\u4e2aActor\u5206\u522b\u5904\u7406\u8fde\u63a5\u3001\u5b57\u8282\u63a5\u6536\u548c\u6570\u636e\u5904\u7406\u3002\u6838\u5fc3Actor\u5305\u62ecWaitForTcpConnectionActor\u3001ReceiveBytesActor\u548cProcessActor\uff0c\u5206\u522b\u8d1f\u8d23\u76d1\u542c\u8fde\u63a5\u3001\u63a5\u6536\u5b57\u8282\u6d41\u548c\u53cd\u5e8f\u5217\u5316\u6570\u636e\u3002\u6587\u7ae0\u8be6\u7ec6\u8bf4\u660e\u4e86\u5982\u4f55\u914d\u7f6eActor\u7cfb\u7edf\u3001\u5b9e\u73b0TCP\u76d1\u542c\u3001\u5904\u7406\u8fde\u63a5\u3001\u63a5\u6536\u5b57\u8282\u3001\u53cd\u5e8f\u5217\u5316\u6570\u636e\u4ee5\u53ca\u8d44\u6e90\u6e05\u7406\u3002\u6b64\u5916\uff0c\u8fd8\u63a2\u8ba8\u4e86Actor\u76d1\u7763\u673a\u5236\u3001\u6d88\u606f\u5f39\u6027\u3001\u751f\u547d\u5468\u671f\u7ba1\u7406\u7b49\u6838\u5fc3\u6982\u5ff5\uff0c\u5e76\u63d0\u4f9b\u4e86\u751f\u4ea7\u73af\u5883\u4e2d\u7684\u4f18\u5316\u5efa\u8bae\u3002\u901a\u8fc7\u8fd9\u4e2a\u793a\u4f8b\uff0c<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[895,3612,3613,55,3611,205],"topic":[],"class_list":["post-39842","post","type-post","status-publish","format-standard","hentry","category-server","tag-net","tag-actor-model","tag-actor-","tag-c","tag-proto-actor","tag-tcp-ip"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u4f7f\u7528 Proto.Actor \u6784\u5efa TCP \u670d\u52a1\u5668\uff1a\u63a2\u7d22 .NET \u4e2d\u7684 Actor \u6a21\u578b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/39842.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u4f7f\u7528 Proto.Actor \u6784\u5efa TCP \u670d\u52a1\u5668\uff1a\u63a2\u7d22 .NET \u4e2d\u7684 Actor \u6a21\u578b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb789\u6b21\uff0c\u70b9\u8d5e24\u6b21\uff0c\u6536\u85cf8\u6b21\u3002\u672c\u6587\u4ecb\u7ecd\u4e86\u5982\u4f55\u4f7f\u7528Proto.Actor\u6846\u67b6\u6784\u5efa\u4e00\u4e2a\u590d\u6742\u7684TCP\u670d\u52a1\u5668\uff0c\u901a\u8fc7\u4e09\u4e2aActor\u5206\u522b\u5904\u7406\u8fde\u63a5\u3001\u5b57\u8282\u63a5\u6536\u548c\u6570\u636e\u5904\u7406\u3002\u6838\u5fc3Actor\u5305\u62ecWaitForTcpConnectionActor\u3001ReceiveBytesActor\u548cProcessActor\uff0c\u5206\u522b\u8d1f\u8d23\u76d1\u542c\u8fde\u63a5\u3001\u63a5\u6536\u5b57\u8282\u6d41\u548c\u53cd\u5e8f\u5217\u5316\u6570\u636e\u3002\u6587\u7ae0\u8be6\u7ec6\u8bf4\u660e\u4e86\u5982\u4f55\u914d\u7f6eActor\u7cfb\u7edf\u3001\u5b9e\u73b0TCP\u76d1\u542c\u3001\u5904\u7406\u8fde\u63a5\u3001\u63a5\u6536\u5b57\u8282\u3001\u53cd\u5e8f\u5217\u5316\u6570\u636e\u4ee5\u53ca\u8d44\u6e90\u6e05\u7406\u3002\u6b64\u5916\uff0c\u8fd8\u63a2\u8ba8\u4e86Actor\u76d1\u7763\u673a\u5236\u3001\u6d88\u606f\u5f39\u6027\u3001\u751f\u547d\u5468\u671f\u7ba1\u7406\u7b49\u6838\u5fc3\u6982\u5ff5\uff0c\u5e76\u63d0\u4f9b\u4e86\u751f\u4ea7\u73af\u5883\u4e2d\u7684\u4f18\u5316\u5efa\u8bae\u3002\u901a\u8fc7\u8fd9\u4e2a\u793a\u4f8b\uff0c\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/39842.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-26T01:01:36+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/39842.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/39842.html\",\"name\":\"\u4f7f\u7528 Proto.Actor \u6784\u5efa TCP \u670d\u52a1\u5668\uff1a\u63a2\u7d22 .NET \u4e2d\u7684 Actor \u6a21\u578b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-05-26T01:01:36+00:00\",\"dateModified\":\"2025-05-26T01:01:36+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/39842.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/39842.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/39842.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u4f7f\u7528 Proto.Actor \u6784\u5efa TCP \u670d\u52a1\u5668\uff1a\u63a2\u7d22 .NET \u4e2d\u7684 Actor \u6a21\u578b\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u4f7f\u7528 Proto.Actor \u6784\u5efa TCP \u670d\u52a1\u5668\uff1a\u63a2\u7d22 .NET \u4e2d\u7684 Actor \u6a21\u578b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/39842.html","og_locale":"zh_CN","og_type":"article","og_title":"\u4f7f\u7528 Proto.Actor \u6784\u5efa TCP \u670d\u52a1\u5668\uff1a\u63a2\u7d22 .NET \u4e2d\u7684 Actor \u6a21\u578b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb789\u6b21\uff0c\u70b9\u8d5e24\u6b21\uff0c\u6536\u85cf8\u6b21\u3002\u672c\u6587\u4ecb\u7ecd\u4e86\u5982\u4f55\u4f7f\u7528Proto.Actor\u6846\u67b6\u6784\u5efa\u4e00\u4e2a\u590d\u6742\u7684TCP\u670d\u52a1\u5668\uff0c\u901a\u8fc7\u4e09\u4e2aActor\u5206\u522b\u5904\u7406\u8fde\u63a5\u3001\u5b57\u8282\u63a5\u6536\u548c\u6570\u636e\u5904\u7406\u3002\u6838\u5fc3Actor\u5305\u62ecWaitForTcpConnectionActor\u3001ReceiveBytesActor\u548cProcessActor\uff0c\u5206\u522b\u8d1f\u8d23\u76d1\u542c\u8fde\u63a5\u3001\u63a5\u6536\u5b57\u8282\u6d41\u548c\u53cd\u5e8f\u5217\u5316\u6570\u636e\u3002\u6587\u7ae0\u8be6\u7ec6\u8bf4\u660e\u4e86\u5982\u4f55\u914d\u7f6eActor\u7cfb\u7edf\u3001\u5b9e\u73b0TCP\u76d1\u542c\u3001\u5904\u7406\u8fde\u63a5\u3001\u63a5\u6536\u5b57\u8282\u3001\u53cd\u5e8f\u5217\u5316\u6570\u636e\u4ee5\u53ca\u8d44\u6e90\u6e05\u7406\u3002\u6b64\u5916\uff0c\u8fd8\u63a2\u8ba8\u4e86Actor\u76d1\u7763\u673a\u5236\u3001\u6d88\u606f\u5f39\u6027\u3001\u751f\u547d\u5468\u671f\u7ba1\u7406\u7b49\u6838\u5fc3\u6982\u5ff5\uff0c\u5e76\u63d0\u4f9b\u4e86\u751f\u4ea7\u73af\u5883\u4e2d\u7684\u4f18\u5316\u5efa\u8bae\u3002\u901a\u8fc7\u8fd9\u4e2a\u793a\u4f8b\uff0c","og_url":"https:\/\/www.wsisp.com\/helps\/39842.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-05-26T01:01:36+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"6 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/39842.html","url":"https:\/\/www.wsisp.com\/helps\/39842.html","name":"\u4f7f\u7528 Proto.Actor \u6784\u5efa TCP \u670d\u52a1\u5668\uff1a\u63a2\u7d22 .NET \u4e2d\u7684 Actor \u6a21\u578b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-05-26T01:01:36+00:00","dateModified":"2025-05-26T01:01:36+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/39842.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/39842.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/39842.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u4f7f\u7528 Proto.Actor \u6784\u5efa TCP \u670d\u52a1\u5668\uff1a\u63a2\u7d22 .NET \u4e2d\u7684 Actor \u6a21\u578b"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/39842","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=39842"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/39842\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=39842"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=39842"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=39842"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=39842"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}