[英]Why do we need the event StreamSocketListener.ConnectionReceived when we use SocketActivityTrigger?
StreamSocketListener is used in UWP Apps to make the App act like a Server, ie listen on a network port and respond when it receives a connection on that port. StreamSocketListener 用于 UWP 应用程序中,使应用程序像服务器一样运行,即侦听网络端口并在接收到该端口上的连接时做出响应。 Thus, we assign a handler to the event ConnectionReceived which is invoked whenever a connection is received.
因此,我们为 ConnectionReceived 事件分配一个处理程序,每当接收到连接时就会调用该事件。
And as explained here , when we want to make this possible when the app is suspended as well, we configure a background task that is triggered using a SocketActivityTrigger whenever a connection is received.正如这里所解释的,当我们希望在应用程序暂停时也实现这一点时,我们配置了一个后台任务,每当接收到连接时使用 SocketActivityTrigger 触发。 Thus, the process happens in the Run method of the background task in this case.
因此,在这种情况下,该过程发生在后台任务的 Run 方法中。 So does this mean, that we don't need to assign a ConnectionReceived event handler anymore when SocketActivityTrigger is used?
那么这是否意味着,当使用 SocketActivityTrigger 时,我们不再需要分配 ConnectionReceived 事件处理程序?
Why do we need the event StreamSocketListener.ConnectionReceived when we use SocketActivityTrigger?
为什么我们在使用 SocketActivityTrigger 时需要事件 StreamSocketListener.ConnectionReceived?
There's a difference between the two.两者是有区别的。 The StreamSocketListener acts like a Server, when your app connects to the listener, the
StreamSocketListener.ConnectionReceived
event will be triggered. StreamSocketListener 就像一个服务器,当您的应用程序连接到侦听器时,将触发
StreamSocketListener.ConnectionReceived
事件。 You can get the connected socket in it and send data to it.您可以在其中获取连接的套接字并向其发送数据。
But about SocketActivityTrigger, when your app receives data on a socket, a keep alive timer expired or the socket was closed, the Run method will be triggered.但是关于 SocketActivityTrigger,当您的应用程序在套接字上接收数据、保持活动计时器到期或套接字已关闭时,将触发 Run 方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.