简体   繁体   English

Android中的Socket.io和Node.js示例

[英]Socket.io and node.js example in android

I am new to socket programming i have to use socket.io and node.js to connect with my server host in android so can anyone please just describe me the programming example of how to connect to server in android. 我是套接字编程的新手,我必须使用socket.io和node.js与android中的服务器主机进行连接,所以任何人都可以向我描述如何在android中连接服务器的编程示例。 And if possible please give some help regarding node.js and socket.io. 如果可能,请提供有关node.js和socket.io的帮助。 As i have searched everywhere on google but not able to find out the proper example. 由于我在Google上到处搜索,但找不到合适的示例。

Thanks 谢谢

You can just have your web service be REST base. 您只需将Web服务作为REST基础即可。

Your Android application can just talk to your web server via REST and receive data json or xml whatever you fancy. 您的Android应用程序可以通过REST与您的Web服务器进行通信,并可以根据需要接收数据json或xml。

So with node.js you should set up routes. 因此,使用node.js您应该设置路由。

An example would of a route would be 路线的一个例子是

www.example.com/users via GET post would return a list of users either in JSON/XML 通过GET张贴的www.example.com/users将以JSON / XML返回用户列表

For your android application you need a library, I believe there's a built in one already, to make request for certain routes such as www.example.com/users via GET method and write the logic to expect JSON or XML and parse that. 对于您的android应用程序,您需要一个库,我相信已经有了一个内置库,可以通过GET方法请求某些路由(例如www.example.com/users),并编写逻辑以期望JSON或XML并对其进行解析。

I just googled this: 我只是用谷歌搜索:

Android: https://github.com/koush/ion Android: https//github.com/koush/ion

As for node.js you just have to build route... 至于node.js,您只需要构建路由...

I think is would be better: 我认为这样会更好:

websocket api to replace rest api? websocket api替换其余api?

It actually invalidate my answers sorry, REST and websocket api are different. 抱歉,REST和websocket api不同,它实际上使我的答案无效。

I have no clue what problem exactly you have. 我不知道你到底有什么问题。 But you should break your problems down to small part. 但是您应该将问题分解为一小部分。 And google and search for answer for each smaller part which would make your life easier to google. 和谷歌搜索每个较小的部分的答案,这将使您的生活更容易谷歌。

Get your webservice up first so that your android software can consume stuff, build a prototype and then build a prototype of android app that consume data from that webservice. 首先启动您的Web服务,以便您的android软件可以使用东西,构建原型,然后构建使用该web服务中的数据的android应用原型。

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

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