请给我一个,我怎么能连接这些简单的例子:
- TCP侦听服务器localhost上的端口33333
和
- 一个Javascript客户端浏览器上工作
我搜索的JS插座,所有环节的WebSockets或socket.io。他们是非常有益的,如果服务器具有相同的框架创建。
可以请你帮忙吗? {S0的}
编辑:
客户端:
这在JS的客户端代码甚至没有连接到服务器。<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="http://cdn.socket.io/stable/socket.io.js"></script>
<script type="text/javascript">
// Create SocketIO instance, connect
var socket = new io.Socket('localhost',{
port: 33333
});
socket.connect();
// Add a connect listener
socket.on('connect',function() {
console.log('Client has connected to the server!');
});
// Add a connect listener
socket.on('message',function(data) {
console.log('Received a message from the server!',data);
});
// Add a disconnect listener
socket.on('disconnect',function() {
console.log('The client has disconnected!');
});
// Sends a message to the server via sockets
function sendMessageToServer(message) {
socket.send(message);
}
</script>
<body>
</body>
</html>
提及:C#客户端与服务器的工作。