I have a telnet server running circlemud. I have websockify running as python proxying the connection. I can receive data as well as send data with the enclosed wstelnet.html that comes with websockify. However when I use the included simple.html file or the following code, it will receive data but will not send, or at least the telnet server never receives anything.
I am assuming the data I am receiving is blob, because that is the only way I can parse it. When you output the raw data to console it doesn't specify what data type it is. Also I am using the default Websocket api with my only include being jquery.
In the following I receive the message $('#message').html("asking for username"); as intended but the ws.send(blob); never sends anything, I have also tried just regular ws.send("test123"); to no avail.
$(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);
};
});
});
Edit: Showing log output from 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 ......
edit 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
Make sure your client is sending line endings (i.e. ASCII character 10 or '\n') that the telnet server is expecting because it won't do anything with the text you sent until it sees a whole line.