Skip to content

websocket APIs 简单封装,还赠送一个nodejs搭建websocket服务实例

Notifications You must be signed in to change notification settings

jaywcjlove/websocket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 

Repository files navigation

websocket

GitHub issues GitHub forks GitHub stars

下载

bower install websocket
npm install websocketjs

connect 连接websocket

ws.connect(url, callback, close, error)

ws.connect('ws://127.0.0.1:8080',function(handlers,evn){
//连接成功!
},function(handlers,evn){
//关闭触发!
    if(handlers.closeType === "kick"){
        console.log('这个是踢下线!的关闭!')
    }
},function(handlers,evn){
//连接失败!
})

message 一个连接监听器

//ws.message(callback)

ws.message(function(evn,handlers){
    console.log(evn.data,handlers)
})

send 通过Socket发送一条消息到服务器

//ws.send()

ws.send('{}') //=>handlers

关闭连接的监听器

//ws.disconnect(type,callback) 关闭类型

ws.disconnect("kick",function(data){

})

判断是websocket否连接

//ws.isConnect() //=> bool

ws.isConnect()  //=> true | false

About

websocket APIs 简单封装,还赠送一个nodejs搭建websocket服务实例

Resources

Stars

Watchers

Forks

Packages

No packages published