ZiT*_*TAL 2 mobile webkit node.js socket.io
我正在使用这个node.js代码:
var server = require("socket.io").listen(6666);
server.sockets.on("connection", function(message)
{
message.on("newMessage", function(data)
{
server.sockets.emit("sendEvent", data);
});
});
Run Code Online (Sandbox Code Playgroud)
这个HTML代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Online chat</title>
<style>
body
{
color: #333;
background: #333;
font-family: "Helvetica", Arial;
font-size: 14px;
text-align: center;
}
.container
{
background: #ccc;
border-radius: 1em;
box-shadow: 0px 5px 5px rgba(0,0,0,0.5);
text-shadow: 5px 5px 5px rgba(0,0,0,0.5);
margin: 1em auto;
padding: 1em;
width: 90%;
}
input
{
display: block;
font-size: 12px;
margin: 1em auto;
padding: 0.5em;
width: 95%;
}
span
{
display: block;
font-size: 12px;
margin: 1em auto;
padding: 0.5em;
width: 95%;
text-align: left;
}
</style>
<script src="/resources/js/socket.io.js"></script>
<script type="text/javascript">
<!--
var websocket = io.connect("http://localhost:6666");
window.onload = function()
{
websocket.on("sendEvent", function(data)
{
var chat = document.getElementById('zchat');
var span = document.createElement('span');
var txt = document.createTextNode(data);
span.appendChild(txt);
if(chat.hasChildNodes())
chat.insertBefore(span, chat.firstChild);
else
chat.appendChild(span);
});
var form = document.getElementById('zform');
var message = document.getElementById('zmessage');
form.onsubmit = function(e)
{
websocket.emit("newMessage", message.value);
return false;
};
};
//-->
</script>
</head>
<body>
<div class="container">
<form id="zform">
<label>Message: </label>
<input type="text" name="zmessage" id="zmessage" placeholder="Please insert message" required />
<input type="submit" />
</form>
</div>
<div id="zchat" class="container">
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
适用于普通浏览器,但我可以使用基于webkit的三星bada的"dolfin"浏览器进行探测,并且无法正常工作,有人可以使用其他移动浏览器进行探测吗?谢谢 :)
server.js
//...
var server = require("socket.io").listen(6969);
//...
Run Code Online (Sandbox Code Playgroud)
的index.html
//...
var websocket = io.connect("http://192.168.100.103:6969");
//...
Run Code Online (Sandbox Code Playgroud)
我认为SATAN的端口是邪恶的,jajajaja并且永远不要使用localhost,永远是PC的公共IP
归档时间: |
|
查看次数: |
2868 次 |
最近记录: |