简体   繁体   English

带Android的WebSockets:URL在哪里?

[英]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. 我目前正在开发适用于Android的聊天应用程序,并且我了解它需要一个中间服务器作为客户端之间的联系点。 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. 我也知道XMPP是一个经过验证的解决方案,但是我主要是C#开发人员,并且想花时间在WebSockets上,因为从我的读物来看,我认为它既快速轻巧 ,尽管需要握手某种形式。

So right now I've downloaded WebSocket4Net (which is a fork from SuperWebSocket ?). 因此,现在我已经下载了WebSocket4Net (这是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. 我能够使用各种本地URL创建WebSocket对象,并且我了解Autobahn是适用于Android的可行WebSockets客户端库。 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). 但是,我不明白的是,我如何让我的Android客户端连接到Web服务器(没有LAN连接,而是通过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. 现在,我认为一个可能的解决方案是公开一个WCF端点,该端点然后可以与WebSocket很好地配合使用,但是这又会增加往返时间,从而首先破坏了WebSockets实现的目的……(轻量级- ness!),我也可以只使用WCF服务作为联系点。

My question then is: what's the URL that my Android client will interact with? 然后我的问题是:Android客户端将与之交互的URL是什么?

Matt, 马特,

  1. Create ac# console application with WebSocket4Net listening on a specific port (say 8000). 使用WebSocket4Net在特定端口(例如8000)上侦听来创建ac#控制台应用程序。

  2. Then deploy this application on a server with a static IP or a domain name (say example.com) assigned to it. 然后将此应用程序部署到为其分配了静态IP或域名(例如example.com)的服务器上。

  3. Now in android app you connect to this ip or domain address using Autobahn. 现在,在android应用中,您可以使用Autobahn连接到该IP或域地址。 ie the url will be ws://example.com:8000 即网址将为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. 不好的是,WebSocket4Net 不是SuperWebSocket的分支,而是WebSocket客户端,因此它与我所寻找的完全不同。 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 . 无论如何,感谢@VinZ的回答,我期待着这个问题的解决方案: Alchemy Websockets:无法在Azure上托管服务器

It's really troubling because my Websocket server works locally but not on Azure! 这真的很麻烦,因为我的Websocket服务器在本地工作,但不能在Azure上工作!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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