我正在尝试使用socket.io构建一个phonegap聊天应用程序,现在我了解它如何使用快速框架(http://socket.io/get-started/chat/),但有没有人知道如何使用phonegap构建相同的东西?< / p>
答案 0 :(得分:2)
If you build your client side content in Phonegap, you can simply use socket.io as a cross-browser WebSocket, as described in the socket.io documentation. This means that you will not be serving anything like you would normally do in a framework or in socket.io. Instead you set up your Node.js server as described in the linked example. So the only communications you do with the server are the pieces of information you need to share between clients.
Doing this you can build all your logic with the basic socket.io building blocks of emits, rooms, and callbacks, without having to worry about how you are going to serve up the content.
I hope that helps.
答案 1 :(得分:2)
Socket.io可以应用于PhoneGap。 例如,您有一个Node.js Socket.io应用程序,其中包含index.js(您的服务器代码)和index.html(您的客户端代码),并假设您已将您的应用程序上传到互联网,并且网址类似于{{ 3}}
要将您的Socket.io应用转换为PhoneGap应用,您不需要index.js(您的服务器代码)。你只需要你的index.html,你需要修改index.html中的src路径和Socket.io连接字符串,就像这样;
首先,将<script src="/socket.io/socket.io.js"></script>
更改为
<script src="https://www.your-web-site.com/socket.io/socket.io.js"></script>
其次,将var socket = io();
更改为
var socket = io.connect("https://www.your-web-site.com");
之后,您可以将这个新的index.html代码转换为PhoneGap应用。