diff --git a/exec/examples/socktest.js b/exec/examples/socktest.js new file mode 100644 index 0000000000000000000000000000000000000000..8d92bab8fe1e80bde7b82c8479f5575d1531fcd2 --- /dev/null +++ b/exec/examples/socktest.js @@ -0,0 +1,45 @@ +load("sbbsdefs.js"); // CON_RAW_IN + +function test() +{ + var socket = new Socket(); + + socket.debug=true; + + if(!socket.bind()) { + printf("!bind error %d\r\n",socket.last_error); + exit(); + } + + var addr=prompt("address"); + var port=Number(prompt("port")); + + if(!socket.connect(addr,port)) { + printf("!connect error %d\r\n",socket.last_error); + exit(); + } + + printf("\r\nConnected to %s:%d - Ctrl-] to abort\r\n",addr,port); + console.pause(); + + while(socket.is_connected && client.socket.is_connected) { + if(socket.data_waiting) { + buf = socket.read(); + client.socket.write(buf); + continue; + } + if((input=console.inkey())!="") { + if(input=="\x1d") /* Ctrl-] */ + break; + socket.write(input); + continue; + } + sleep(1); + } +} + +console.status |= CON_RAW_IN; // Enable RAW input mode (pass-through ctrl chars) +test(); +console.status &= ~CON_RAW_IN; // Disable raw input mode + +print("\r\nEnd of socktest!\r\n"); \ No newline at end of file diff --git a/exec/socktest.src b/exec/socktest.src new file mode 100644 index 0000000000000000000000000000000000000000..263dfe903debf1985a5175635c9f012c7f740431 --- /dev/null +++ b/exec/socktest.src @@ -0,0 +1,63 @@ +!include sbbsdefs.inc + +int sock len +str buf + +socket_open sock +if_false + print "open failure\r\n" + return + end_if +setstr "cvs.synchro.net" +socket_connect sock str 23 +if_false + print "connect failure\r\n" + return + end_if + +or _console CON_RAW_IN +loop + + inchar + if_true + compare_key ^] + if_equal + break + end_if + copy_char buf + socket_write sock buf + if_false + print "\r\nError writing to socket\r\n" + break + end_if + continue + end_if + + socket_check sock + if_false + print "\r\nSocket disconnected\r\n" + break + end_if + + socket_nread sock len + if_false + print "\r\nError getting read length\r\n" + break + end_if + + compare len 0 + if_equal + continue + end_if + +# printf "reading %d" len + + socket_read sock buf len + if_true + pause_reset + print buf + end_if + end_loop + +socket_close sock +xor _console CON_RAW_IN \ No newline at end of file