我有一个运行 circlemud 的 telnet 服务器。我有 websockify 作为 python 代理连接运行。我可以使用 websockify 附带的 wstelnet.html 接收数据以及发送数据。但是,当我使用包含的 simple.html 文件或以下代码时,它会接收数据但不会发送,或者至少 telnet 服务器不会收到任何东西。
我假设我收到的数据是 blob,因为这是我可以解析它的唯一方法。当您将原始数据输出到控制台时,它不会指定它是什么数据类型。我也使用默认的 Websocket api,我唯一的包括 jquery。
在下面我收到消息$('#message').html("asking for username"); 正如预期的那样,但是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 port 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