简体   繁体   中英

WebSockets with Android: where's the URL?

I'm currently working on a chat app for Android, and I understand that it needs an intermediary server as a point of contact between clients. I also get that XMPP is a tried and tested solution but however I'm primarily a C# developer and would like to invest my time in WebSockets, because from what I've read I believe it's both fast and lightweight , though it needs a handshake of some sort.

So right now I've downloaded WebSocket4Net (which is a fork from SuperWebSocket ?). I'm able to create a WebSocket object with a local URL of sorts, and I understand that Autobahn is a viable WebSockets client library for Android. What I don't understand however, is how I'm going to get my Android client to connect to the web server (without a LAN connection, but rather over the Internet).

Right now I think that a possible solution would be to expose a WCF endpoint which then plays well with the WebSocket , but then again that would add to the roundtrip time, defeating the purpose of WebSockets implementation in the first place... (lightweighted-ness!) I might as well just make do with simply WCF services as that point of contact.

My question then is: what's the URL that my Android client will interact with?

Matt,

  1. Create ac# console application with WebSocket4Net listening on a specific port (say 8000).

  2. Then deploy this application on a server with a static IP or a domain name (say example.com) assigned to it.

  3. Now in android app you connect to this ip or domain address using Autobahn. ie the url will be ws://example.com:8000

I hope this is what you were looking for.

My bad, WebSocket4Net is not a fork of SuperWebSocket but instead a WebSocket client so it was totally different from what I was looking for. Thanks for the answer anyway @VinZ, I'm looking forward to getting a solution on this question: Alchemy Websockets: Can't host server on Azure .

It's really troubling because my Websocket server works locally but not on Azure!

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