0

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
timeba
  • 75
  • 8
  • Are you certain you aren't getting an error right before ws.send due to a missing "new" for your Blob constructor? For this use case, it's probably easier to use arraybuffers/typed arrays. Then you don't have to worry about the FileReader intermediary. Set ws.binaryType = "arraybuffer" ("blob" is the default). – kanaka Feb 26 '19 at 21:36
  • Alright I changed ***ws.binaryType = "arraybuffer";*** I am using ***var string = new TextDecoder().decode(arrayBuf);*** to read the arrayBuffer and ***var array = new TextEncoder("utf-8").encode(myString);*** to encode my string and sending to the server with ***ws.send(array);*** but I still don't receive anything server side. not even sure how to debug because i get no errors anywhere and ***console.log(array);*** looks good – timeba Feb 27 '19 at 04:10
  • I would suggest switching to unencrypted mode temporarily (ws://) and using `tcpdump -XX port 4000` so you can see what's actually being sent on the wire. – kanaka Feb 27 '19 at 15:38
  • I did as you suggested and updated my question with the output. It looks like it gets sent to websockify but never gets passed to the telnet server – timeba Mar 05 '19 at 06:40
  • Looks like it's still encrypted. I would switch to "ws://" unencrypted communication during debug and run two instances of tcpdump: one for the browser->websockify connection and one for the websockify->telnet connection. I suspect that data is making it all the way to the telnet server (otherwise websockify would be complaining) but perhaps the data is missing the proper line endings causing the server to keep waiting. – kanaka Mar 05 '19 at 15:30
  • I made another edit to my question with the log for websockify. I was connected as unencrypted ws:// – timeba Mar 06 '19 at 00:14
  • Given that wstelnet works and you are getting data back from the server, the main difference sounds like the use of Blob. Can you switch to arraybuffers/typed arrays? Also, seeing the tcpdump from the websockify to telnet server would be insightful. The tcpdump output you posted doesn't seem to have any textual data visible in it. If the data is being put on the wire unencrypted I would have expected to be able to see it in the textual output from tcpdump. – kanaka Mar 06 '19 at 16:48
  • Its gotta be something with my code, your telnet client with the VT100 that is included with the examples works, I can send and receive. But your websocket simple client does not. oddly enough the same stuff shows up on the tcpdump. How is the telnet client sending differently than the websocket simple client? I have also tried arraybuffers with the same results – timeba Mar 07 '19 at 01:09
  • As an update, I am interfacing with a telnet server, and thus it was expecting me to hit the enter button. so I could send the string over but it wouldn't do anything because the string was in a queue until i "hit" enter. So I sent over the byte "10" for "enter" and it transferred the queue over to the telnet server. – timeba Mar 10 '19 at 03:36
  • Okay, glad you figured it out. That's what I was trying to communicate above with "missing the proper line endings". I've added an answer that summarizes what we've worked out. It would be good to select it so that anybody else who runs into a similar issue knows that the question is an answered/resolved one. – kanaka Mar 11 '19 at 19:20

1 Answers1

0

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.

kanaka
  • 70,845
  • 23
  • 144
  • 140