• Final Proxy Code

    From Drakmir@HDONE to Digital Man on Friday, October 07, 2005 01:34:00
    load("sbbsdefs.js"); // CON_RAW_IN
    load("sockdefs.js"); // SO_RCVBUF

    function sendData(socketA, socketB)
    {
    var bRetVal = false;
    var buf;

    if(socketA.data_waiting)
    {
    var numRead = socketA.nread;
    if (numRead >= 512) numRead = 512;
    buf = socketA.peek(numRead);

    if (numRead != buf.length)
    {
    while(numRead > 4)
    {
    buf = socketA.recvBin(4);
    socketB.sendBin(buf, 4);
    numRead -= 4;
    }

    if (numRead > 0)
    {
    buf = socketA.recvBin(numRead);
    socketB.sendBin(buf, numRead);
    }
    }
    else
    {
    buf = socketA.read(numRead);
    socketB.write(buf);
    }

    bRetVal = true;
    }

    return bRetVal;
    }

    try
    {
    if (argc < 2)
    {
    throw("No parameters passed.");
    };

    var socket = new Socket();

    if(!socket.bind()) {
    throw("!bind error " + socket.last_error + "\r\n");
    exit();
    }

    var addr=argv[0];
    var port=argv[1];

    if(!socket.connect(addr,port)) {
    throw("!connect error " + socket.last_error + "\r\n");
    exit();
    }
    log("\r\nConnected to " + addr + ":" + port + "\r\n");

    while(socket.is_connected && client.socket.is_connected)
    {
    if (sendData(socket, client.socket)) continue;
    if (sendData(client.socket, socket)) continue;
    sleep(1);
    }

    log("\r\nEnd of socktest!\r\n");
    }
    catch(E)
    {
    log("Caught error - " + E);
    exit(-1);
    }

    exit(0);

    ---
    ■ Synchronet ■ Holodeck One - bbs.holodeckone.com