locked
Windows store apps - saving streamsocket connections RRS feed

  • General discussion

  • My app lets users connect to each other to share messages and such using streamsockets.

    The app has a streamSocket Listener that, when the `onConnectionReceived` is called, it returns the socket that is connecting and sending  a request to the app.

    The app will have MANY sockets connecting to it, each socket will be carrying different requests the app must carry out.

     My questions are: 

    1. What is the best practice for saving these Socket connections so i can reuse them later and write to them?

    2. How can  i have my app handle each connections request separately and at the same time?(maybe have them each running on a different thread?) Meaning, i dont want my app writing a response to the wrong streamsocket that sent the request.
    Sunday, December 8, 2013 5:16 AM

All replies

  • 1. What is the best practice for saving these Socket connections so i can reuse them later and write to them?

    You really cannot 'save' them.  You want to open a socket when needed and close it when you do not.

    2. How can  i have my app handle each connections request separately and at the same time?

    You would need to track each request by the socket that you are using.  If it is the same socket for all requests you need to create a protocol so you can keep track of it (maybe a unique header for each request).  The easiest way is the first... create a separate socket for each 'conversation' and dispose of it when the conversation is done.  You still may want a unique identifier for the conversation in case the connection is lost (you switch to a different app) so you can re-establish the conversation.


    Jeff Sanders (MSFT)

    @jsandersrocks - Windows Store Developer Solutions @WSDevSol
    Getting Started With Windows Azure Mobile Services development? Click here
    Getting Started With Windows Phone or Store app development? Click here
    My Team Blog: Windows Store & Phone Developer Solutions
    My Blog: Http Client Protocol Issues (and other fun stuff I support)

    Monday, December 9, 2013 3:14 PM
    Moderator