精华内容
下载资源
问答
  • DR</strong>: 2 different actionlib_clients connected to actionlib_servers via rosbridge_server websocket result in differing behaviour. <p>Hello, here's my setup: 1 Kinova MICO robotic manipulator...
  • python websocket-server websocket_client

    千次阅读 2019-02-26 09:34:19
    websocket-server # pip install websocket-server from websocket_server import WebsocketServer # 当新的客户端连接时会提示 def new_client(client, server): print("当新的客户端连接时会提示:%s&...

    websocket-server

    # pip install websocket-server
    from websocket_server import WebsocketServer
    
    
    # 当新的客户端连接时会提示
    def new_client(client, server):
        print("当新的客户端连接时会提示:%s" % client['id'])
        server.send_message_to_all("Hey all, a new client has joined us")
    
    
    # 当旧的客户端离开
    def client_left(client, server):
        print("客户端%s断开" % client['id'])
    
    
    # 接收客户端的信息。
    def message_received(client, server, message):
        print("Client(%d) said: %s" % (client['id'], message))
        server.send_message_to_all(message)
    
    
    if __name__ == '__main__':
    
        server = WebsocketServer(8131, "0.0.0.0")
        server.set_fn_new_client(new_client)
        server.set_fn_client_left(client_left)
        server.set_fn_message_received(message_received)
        server.run_forever()

    websocket_client

    # pip install websocket_client
    import websocket
    import threading
    import time
    
    file = True
    num = 0
    def on_message(ws, message):
        print(message)
        print('**********************')
    
    
    
    def on_error(ws, error):
        print(error)
    
    
    def on_close(ws):
        print('关闭')
        "### closed ###"
    
    
    def on_open(ws):
        def run(*args):
            global num
            while num<5:
                time.sleep(1)
                num += 1
                print("{'message': 'num_%s'}" %num)
                ws.send('{"message": "num_%s"}')
            # ws.send('{"message": "num_%s"}')
            time.sleep(1)
            ws.close()
            print("thread close...")
    
        th = threading.Thread(target=run, args=())
        th.start()
    
    
    
    
    if __name__ == "__main__":
        # websocket.enableTrace(True)
        ws = websocket.WebSocketApp("ws://127.0.0.1:8131/ws/status/555/",
                                    on_message=on_message,
                                    on_error=on_error,
                                    on_close=on_close,
                                    on_open=on_open)

     

     

     

     

     

    展开全文
  • [08/13/16 15:06:13] [EROR] key: 33_3 server websocket failed error(websocket: close 1001 (going away)) [08/13/16 15:06:13] [DEBG] key: 33_3 wakeup exit dispatch goroutine [08/13/16 15:06:13] [DEBG] ...
  • nodejs server websocket

    2018-03-14 23:23:00
    1 var WebSocketServer = require('websocket').server; 2 var http = require('http'); 3 4 var server = http.createServer(function(request, response) { 5 console.log((new Date()) + ' Recei...
     1 var WebSocketServer = require('websocket').server;
     2 var http = require('http');
     3 
     4 var server = http.createServer(function(request, response) {
     5     console.log((new Date()) + ' Received request for ' + request.url);
     6     response.writeHead(404);
     7     response.end();
     8 });
     9 server.listen(8080, function() {
    10     console.log((new Date()) + ' Server is listening on port 8080');
    11 });
    12 
    13 wsServer = new WebSocketServer({
    14     httpServer: server,
    15     // You should not use autoAcceptConnections for production
    16     // applications, as it defeats all standard cross-origin protection
    17     // facilities built into the protocol and the browser.  You should
    18     // *always* verify the connection's origin and decide whether or not
    19     // to accept it.
    20     autoAcceptConnections: false
    21 });
    22 
    23 function originIsAllowed(origin) {
    24   // put logic here to detect whether the specified origin is allowed.
    25   return true;
    26 }
    27 
    28 wsServer.on('request', function(request) {
    29     if (!originIsAllowed(request.origin)) {
    30       // Make sure we only accept requests from an allowed origin
    31       request.reject();
    32       console.log((new Date()) + ' Connection from origin ' + request.origin + ' rejected.');
    33       return;
    34     }
    35 
    36     var connection = request.accept('echo-protocol', request.origin);
    37     console.log((new Date()) + ' Connection accepted.');
    38     connection.on('message', function(message) {
    39         if (message.type === 'utf8') {
    40             console.log('Received Message: ' + message.utf8Data);
    41             connection.sendUTF(message.utf8Data);
    42         }
    43         else if (message.type === 'binary') {
    44             console.log('Received Binary Message of ' + message.binaryData.length + ' bytes');
    45             connection.sendBytes(message.binaryData);
    46         }
    47     });
    48     connection.on('close', function(reasonCode, description) {
    49         console.log((new Date()) + ' Peer ' + connection.remoteAddress + ' disconnected.');
    50     });
    51 });

     

    转载于:https://www.cnblogs.com/wblade/p/8570795.html

    展开全文
  • WebSocketServer

    2015-10-07 22:25:57
    iOS本地WebSocketServer服务端
  • server php websocket

    2012-11-22 21:51:43
    web socket php 实现的server
  • However, I am having difficulty making the HTTPS and WebSocket SSL server side work. Would be great if there are examples that show HTTPS and WebSocket SSL server code. SSL is very important as nowa...
  • I am upgrading a WebSocket proxy to Warp from previous library and almost everything works: the last remaining item missing is the ability to send server side WebSocket keepalives. They are useful ...
  • windows Server 2008 上IIS为7.5 ,现在要IIS8.0才有支持WebSocket,请问有没有什么办法?
  • python websocket server javascript websocket client
  • 一个WebSocket服务器可以和多个WebSocket客户端连接。 clientAddress:web socket服务器for Webshop的IP地址和端口号 clientSocketID:web shop webpage的WebSocket ID: 之前只是把dataFromWebShop存储到了map的...

    一个WebSocket服务器可以和多个WebSocket客户端连接。

    clientAddress:web socket服务器for Webshop的IP地址和端口号
    clientSocketID:web shop webpage的WebSocket ID:

    之前只是把dataFromWebShop存储到了map的value里,这是不够的。因为接下来KOI app点了confirm后,还要通知连接另一方的web shop,因此KOI app发出的confirm request需要找到对应的web shop。

    故最后改成了把整个oJSON作为value存储起来。

    要获取更多Jerry的原创文章,请关注公众号"汪子熙":

    展开全文
  • 想实现网页前端和后端的数据同步...python websocket github 地址:git@github.com:Aplexchenfl/python-websocket-server.git下载之后:ECM_5412@chenfl:/var/www/html$ lsclient.html README.md server.py se...

    想实现网页前端和后端的数据同步交互,就有必要使用 websocket 的方式进行通信。

    python websocket github 地址:git@github.com:Aplexchenfl/python-websocket-server.git

    下载之后:

    ECM_5412@chenfl:/var/www/html$ ls

    client.html README.md server.py setup.py tests websocket_server

    其中,服务端的代码如下:

    vim server.py

    from websocket_server import WebsocketServer

    // 当新的客户端连接时会提示

    # Called for every client connecting (after handshake)

    def new_client(client, server):

    print("New client connected and was given id %d" % client['id'])

    server.send_message_to_all("Hey all, a new client has joined us")

    // 当旧的客户端离开

    # Called for every client disconnecting

    def client_left(client, server):

    print("Client(%d) disconnected" % client['id'])

    // 接收客户端的信息。

    # Called when a client sends a message

    def message_received(client, server, message):

    if len(message) > 200:

    message = message[:200]+'..'

    print("Client(%d) said: %s" % (client['id'], message))

    PORT=9001

    server = WebsocketServer(PORT, "0.0.0.0")

    server.set_fn_new_client(new_client)

    server.set_fn_client_left(client_left)

    server.set_fn_message_received(message_received)

    server.run_forever()

    // 通过 python3 启动这个客户端

    python3 server.py

    客户端代码如下:

    Simple client

    var ws;

    function init() {

    // 获取服务端ip

    var ip_addr = document.location.hostname;

    window.WebSocket = window.WebSocket || window.MozWebSocket;

    ws = new WebSocket('ws://' + ip_addr +':9001'); // 申请新的客户端

    // Connect to Web Socket

    //ws = new WebSocket("ws://localhost:9001/");

    // Set event handlers.

    ws.onopen = function() {

    output("onopen");

    };

    ws.onmessage = function(e) {

    // e.data contains received string.

    output("onmessage: " + e.data);

    };

    ws.onclose = function() {

    output("onclose");

    };

    ws.onerror = function(e) {

    output("onerror");

    console.log(e)

    };

    }

    function onSubmit() {

    var input = document.getElementById("input");

    // You can send message to the Web Socket using ws.send.

    ws.send(input.value);

    output("send: " + input.value);

    input.value = "";

    input.focus();

    }

    function onCloseClick() {

    ws.close();

    }

    function output(str) {

    var log = document.getElementById("log");

    var escaped = str.replace(/&/, "&").replace(/, "<").

    replace(/>/, ">").replace(/"/, """); // "

    log.innerHTML = escaped + "
    " + log.innerHTML;

    }

    close

    // 通过网页启动客户端。

    展开全文
  • WebSocket Server

    2012-11-22 22:11:53
    基于Tomcat的WebSocket(5月8日...WebServer   之前大概的看过WebSocket,当时Tomcat还不支持WebSocket,所以当时写了一篇基于Jetty的WebSocket实现,地址如下: http://redstarofsleep.iteye.com/blog/13076
  • <div><p>I am able to get my websocket client connect to the websocket server when i connect trough the private IP adress without using proxy. Same websocketclient code when tries to connect to the ...
  • (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:" is as it follows: <p>"WebSocket closed reason: Stream end encountered and code: 1001 and was clean: 0" <p>Have someone had that ...
  • <div><p>I am using the v1.6 <code>SuperSocket.WebSocket.WebSocketServer</code> server and I am experiencing random slow performance. At random times all clients are receiving delayed messages and the ...
  • WebSocket Client连接远程WebSocket Server

    千次阅读 2017-10-25 20:30:17
    在这篇文章中,简单介绍了WebSocket的使用,客户端可以使用了JavaScript向服务...下面介绍客户端如何连接远程WebSocket Server并推送消息,参照gs-messaging-stomp-websocket中的TestCase,我们简单修改下代码@Slf4j
  • <p>I try to setup a websocket server (from https://www.boost.org/doc/libs/1_69_0/libs/beast/example/websocket/server/async/websocket_server_async.cpp) and add an http server (from ...
  • '''Host a multiplayer sever via WebSocket protocol...
  • In the example sketch : <a href="https://github.com/Links2004/arduinoWebSockets/blob/master/examples/WebSocketServer_LEDcontrol/WebSocketServer_LEDcontrol.ino">WebSocketServer_LEDcontrol.ino, is there...
  • Websocketclient is disconnected from websocketserver after client get a ping from server <p><strong>To Reproduce Library : 0.4.11 Board : NodeMCU Steps to reproduce the behavior. <p><strong>Expected...
  • /************************************************************************** python-websocket-server hacking* 说明:* 跟一下python-websocket-server怎么使用,这个lib还算是目前想用的。** ...
  • 参考文章:使用nginx作为websocket的proxy server WebSocket WebSocket协议为创建客户端和服务器端需要实时双向通讯的webapp提供了一个选择。其为HTML5的一部分,WebSocket相较于原来开发这类app的...
  • websocket server crashes

    2021-01-07 11:23:45
    I have added the websocket part to my server (not the one on github, the server is kind a commercial software, not really comfortable to put it on github ). During test, it crashes quite often. When ...
  • <div><p>Love ur work, but how i can access server over ws ? Tried server_ip:1883. The connection keeps refusing</p><p>该提问来源于开源项目:chkr1011/MQTTnet</p></div>

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 13,461
精华内容 5,384
关键字:

serverwebsocket