websockify ws.send未将字符串发送到telnet服务器

时间:2019-02-26 06:05:40

标签: javascript websocket telnet websockify

我有一个运行circlemud的telnet服务器。我有websockify作为代理连接的python运行。我可以使用websockify随附的wstelnet.html接收数据,也可以发送数据。但是,当我使用包含的simple.html文件或以下代码时,它将接收数据但不会发送,或者至少telnet服务器从不接收任何信息。

我假设接收到的数据是blob,因为这是解析它的唯一方法。当您将原始数据输出到控制台时,不会指定原始数据类型。另外,我正在使用默认的Websocket api,但只有jquery。

在下面,我收到消息 $('#message')。html(“要求用户名”); ,但消息却是 ws.send(blob); 从不发送任何内容,我还尝试了常规的 ws.send(“ test123”); 无济于事。

$(document).ready(function(){
    $("#connect").click(function(){
        // open a web socket
        const url = 'wss://mywebsite.com:4000';
        const ws = new WebSocket(url, ['binary', 'base64']);
        // Web Socket is connected, send data using send()
        ws.onopen = function() {
            $('#connection_status').html("Connected.");
        };

        ws.onmessage = function (evt) {
            const blb    = new Blob([evt.data], {type: "text/plain"});
            const reader = new FileReader();
            reader.addEventListener('loadend', (e) => {
              const text = e.srcElement.result;
              const compare = text.trim();
              if(compare == '<username>'){
                $('#message').html("asking for username");
                var blob = Blob(["test123"], {type: "text/plain"})
                ws.send(blob);
              } else if(compare == '<password>'){
                $('#message').html("asking for password");
                ws.send("mypw");
              } else if(compare == '<interface version>'){
                ws.send("bllkjsbjlqw")
              } else {
                $('#message').html(document.createTextNode(text));
              }
              //$('#message').append(document.createTextNode(text));
            });
            reader.readAsText(blb);
        };
        // websocket is closed.
        ws.onclose = function() { 
            $('#connection_status').html("Disconnected.");
        };
        // Log errors
        ws.onerror = function (error) {
           console.log('WebSocket Error ' + error);
        };
    });
});

编辑:显示 sudo tcpdump -v -XX端口4000的日志输出

22:36:45.710377 IP (tos 0x0, ttl 128, id 23764, offset 0, flags [DF], proto TCP (6), length 52)
    192.168.1.128.51393 > mud-server.4000: Flags [P.], cksum 0xe18c (correct), seq 571:583, ack 251, win 2052, length 12
        0x0000:  0800 277c ba24 2c4d 5451 e051 0800 4500  ..'|.$,MTQ.Q..E.
        0x0010:  0034 5cd4 4000 8006 1a08 c0a8 0180 c0a8  .4\.@...........
        0x0020:  0117 c8c1 0fa0 d8f9 b9b5 6739 4d4c 5018  ..........g9MLP.
        0x0030:  0804 e18c 0000 8286 f106 b76c 9269 d315  ...........l.i..
        0x0040:  9237                                     .7
22:36:45.710462 IP (tos 0x0, ttl 128, id 23765, offset 0, flags [DF], proto TCP (6), length 52)
    192.168.1.128.51393 > mud-server.4000: Flags [P.], cksum 0x3bb0 (correct), seq 583:595, ack 251, win 2052, length 12
        0x0000:  0800 277c ba24 2c4d 5451 e051 0800 4500  ..'|.$,MTQ.Q..E.
        0x0010:  0034 5cd5 4000 8006 1a07 c0a8 0180 c0a8  .4\.@...........
        0x0020:  0117 c8c1 0fa0 d8f9 b9c1 6739 4d4c 5018  ..........g9MLP.
        0x0030:  0804 3bb0 0000 8286 2a20 f2d1 494f 96a8  ..;.....*...IO..
        0x0040:  4911                                     I.
22:36:45.710602 IP (tos 0x0, ttl 64, id 21205, offset 0, flags [DF], proto TCP (6), length 40)
    mud-server.4000 > 192.168.1.128.51393: Flags [.], cksum 0x8402 (incorrect -> 0x0b51), ack 595, win 237, length 0
        0x0000:  2c4d 5451 e051 0800 277c ba24 0800 4500  ,MTQ.Q..'|.$..E.
        0x0010:  0028 52d5 4000 4006 6413 c0a8 0117 c0a8  .(R.@.@.d.......
        0x0020:  0180 0fa0 c8c1 6739 4d4c d8f9 b9cd 5010  ......g9ML....P.
        0x0030:  00ed 8402 0000                           ......

编辑2:

192.168.1.128: new handler Process
192.168.1.128 - - [04/Mar/2019 22:36:38] "GET / HTTP/1.1" 101 -
192.168.1.128 - - [04/Mar/2019 22:36:38] 192.168.1.128: Plain non-SSL (ws://) WebSocket connection
192.168.1.128 - - [04/Mar/2019 22:36:38] 192.168.1.128: Version hybi-13, base64: 'False'
192.168.1.128 - - [04/Mar/2019 22:36:38] connecting to: 192.168.1.23:8080

1 个答案:

答案 0 :(得分:0)

请确保您的客户端正在发送telnet服务器期望的行尾(例如ASCII字符10或'\ n'),因为在看到整行之前,它不会对您发送的文本执行任何操作。