如何在套接字连接时最好地发送附加数据?
客户:
socket.on('connect',function(){
//I'd like set some values and pass them up to the node server.
});
Run Code Online (Sandbox Code Playgroud)
Node.js服务器:
io.on('connection', function(client){
//I'd like to get the data here.
});
Run Code Online (Sandbox Code Playgroud)
例如,发送用户名或电子邮件地址等.
我正在使用node.js和socket.io构建一个小型原型.一切都运行良好,我面临的唯一问题是我的node.js连接将断开连接,我被迫刷新页面,以便连接并再次运行.
一旦断开事件被触发,有没有办法重新建立连接?
据我所知,这是一个常见问题.所以,我正在寻找解决这个问题的最佳实践方法:)
非常感谢,Dan
我想知道是否有办法使用JavaScript捕获iPhone的虚拟键盘的完成按钮事件?
基本上,我只是希望能够在用户点击完成后调用JS函数.
我无法触发客户端事件,请参阅代码/说明:
好的,所以我得到了这个工作(我认为)
客户端代码:
<script src="./Socket.IO/socket.io.js"></script>
<script>
io.setPath('./Socket.IO/');
var socket = new io.Socket('jayz.danstanhope.webfactional.com', { 'port': 80 });
socket.on('connect', function () {
alert('connect');
});
socket.on('message', function (msg) {
alert('message' + msg);
});
socket.on('close', function () {
alert('close');
});
socket.on('disconnect', function () {
alert('disconnect');
});
socket.connect();
</script>
Run Code Online (Sandbox Code Playgroud)
服务器端代码:
var sys = require("sys")
, fs = require("fs")
, path = require("path")
, http = require("http");
var io = require('/home/danstanhope/webapps/htdocs/Socket.IO-node');
var server = http.createServer(function (req, res) {
//your normal server code
res.writeHead(200, { 'Content-Type': 'text/html' …Run Code Online (Sandbox Code Playgroud)