locked
Windows Phone Tcp Srver, multiple connections RRS feed

Answers

  • The post you're mentioning isn't for WinRT.
    You should be able to listen for incoming connections and hold on to a list of connected sockets when the connectionreceived event fires.  You can then communicate across all of these sockets separately.

    You can see this if you run the StreamSocket sample. You can run multiple clients to connect to the same server.  This should be the relevant code:

    private async void OnConnection(StreamSocketListener sender,            StreamSocketListenerConnectionReceivedEventArgs args)
    {
      DataReader reader = new DataReader args.Socket.InputStream);
         
    Notice that args.Socket is what you want to store and then you can respond appropriate to each separate socket according to it's sent data.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Marked as answer by mwindham Tuesday, June 3, 2014 3:09 PM
    Tuesday, June 3, 2014 1:11 PM

All replies

  • The post you're mentioning isn't for WinRT.
    You should be able to listen for incoming connections and hold on to a list of connected sockets when the connectionreceived event fires.  You can then communicate across all of these sockets separately.

    You can see this if you run the StreamSocket sample. You can run multiple clients to connect to the same server.  This should be the relevant code:

    private async void OnConnection(StreamSocketListener sender,            StreamSocketListenerConnectionReceivedEventArgs args)
    {
      DataReader reader = new DataReader args.Socket.InputStream);
         
    Notice that args.Socket is what you want to store and then you can respond appropriate to each separate socket according to it's sent data.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Marked as answer by mwindham Tuesday, June 3, 2014 3:09 PM
    Tuesday, June 3, 2014 1:11 PM
  • Thanks!
    Tuesday, June 3, 2014 3:08 PM