Skip to content
Snippets Groups Projects
Commit b9921c22 authored by rswindell's avatar rswindell
Browse files

Socket test module.

parent f4378b48
No related branches found
No related tags found
No related merge requests found
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
!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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment