简体   繁体   中英

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. Thus, we assign a handler to the event ConnectionReceived which is invoked whenever a connection is received.

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. Thus, the process happens in the Run method of the background task in this case. So does this mean, that we don't need to assign a ConnectionReceived event handler anymore when SocketActivityTrigger is used?

Why do we need the event StreamSocketListener.ConnectionReceived when we use SocketActivityTrigger?

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM