发布时间:2019-09-10 08:45:23编辑:auto阅读(2178)
from socketIO_client import SocketIO
hosts = 'http://websocke.server.com'
port = 3000
# 收到message消息处理过程
def on_message(*args):
# print "recv:", args
# print "geted:", type(args[0])
if type(args[0]) is types.DictType:
rp = args[0]
print "recv:", rp
sk = SocketIO(hosts,port=port)
sk = SocketIO(hosts,port=port,params={'token': 'ksdjfkjdf'}) #create connection with params
# add lisenter for message response
sk.on('message', on_message)
data = {
"sn": 0,
"ver": 2}
# send data to message
sk.emit('message', data, on_message)
sk.sendf(data, on_message) # default send data to message
#send data to login
sk.emit('login', data, on_message)
sk.wait_for_callbacks(seconds=1)
import logging
logging.getLogger('requests').setLevel(logging.WARNING)
logging.basicConfig(level=logging.DEBUG)
var server = require('http').createServer();
var io = require('socket.io')(server);
io.on('connection', function(client){
console.log('connected');
//when get data on message
client.on('message', function(obj){
console.log("get message and return to client...");
io.emit('message', {'a':'messagetest'});
console.log("login backed...");
});
// when get data on login
client.on('login', function(obj){
console.log("get login data and return to client...");
io.emit('login', {'a':'logintest'});
console.log("login backed...");
});
client.on('event', function(data){});
client.on('disconnect', function(){
console.log('client disconnected');
});
});
console.log("server started on port 3000");
server.listen(3000);
上一篇: python 监控键盘输入
下一篇: windows下python proto
47851
46411
37294
34741
29323
25979
24927
19959
19551
18040
5800°
6422°
5937°
5967°
7074°
5921°
5952°
6447°
6409°
7789°