locked
C# WebSockets server in Windows Runtime?

    Question

  • I need a way to communicate large amounts of data between the JS in a WebView and the C# in my main application and after some research I have concluded that using the WebSockets standard will probably be my best option. My problem is that I cannot find out how to implement a C# WebSockets server in C# for Windows Runtime (Windows 8.1 and Windows Phone 8.1). I can find a lot of libraries for Desktop that enable this but I cannot find a single library compatible with RT or a single tutorial of how to implement it on RT. I know that it should theoretically be possible though because Cordova supports Windows 8 (which uses the RT library) and Windows Phone 8 (which is Silveright though). I do though not want to use Cordova for this because it would really be overkill (it's a full scale web server...) slowing my application down, making it larger and complicating the source. I also believe Cordova is C++ and this will remove AnyCPU compiling... Any ideas what I can do?

    PS. This application will ultimately have a Desktop, Mac, Linux, iOS an Android version too so I would prefer if this solution use as standard C# as possible but if not possible it should be easy to make other implementations for the other platforms.

    Thursday, July 24, 2014 10:53 AM

Answers

  • The Windows Runtime WebSocket implementation is pretty much designed for clients. There isn't a WebSocketListener.

    See Connecting with WebSockets and WebSocket sample

    If you use the StreamSocketListener you can listen for incoming connections and look for the HTTP requests. I believe an MVP posted a sample demonstrating this, but my search fu is weak today and I can't find it. The sample may have been specifically to provide an image.

    Note that Windows Store apps are blocked from network loopback to the local system outside of their app container. Your scenario of connecting back to the same app stays within the app container and so can work.

    --Rob

    Thursday, July 24, 2014 8:19 PM
    Owner
  • The primary advantage of the websocket over streamsocket/datagramsocket is that a websocket is designed to get through proxies.  If that's not as important, then you can use a plain streamsocket.

    Network Developer Experience Team (Microsoft)

    Monday, July 28, 2014 7:36 PM

All replies

  • The Windows Runtime WebSocket implementation is pretty much designed for clients. There isn't a WebSocketListener.

    See Connecting with WebSockets and WebSocket sample

    If you use the StreamSocketListener you can listen for incoming connections and look for the HTTP requests. I believe an MVP posted a sample demonstrating this, but my search fu is weak today and I can't find it. The sample may have been specifically to provide an image.

    Note that Windows Store apps are blocked from network loopback to the local system outside of their app container. Your scenario of connecting back to the same app stays within the app container and so can work.

    --Rob

    Thursday, July 24, 2014 8:19 PM
    Owner
  • The primary advantage of the websocket over streamsocket/datagramsocket is that a websocket is designed to get through proxies.  If that's not as important, then you can use a plain streamsocket.

    Network Developer Experience Team (Microsoft)

    Monday, July 28, 2014 7:36 PM
  • The primary advantage of the websocket over streamsocket/datagramsocket is that a websocket is designed to get through proxies.  If that's not as important, then you can use a plain streamsocket.

    Network Developer Experience Team (Microsoft)

    I see, but is there any way to communicate with JS through a simple streamsocket?
    Sunday, August 03, 2014 6:05 AM