• Socket Test

    From MCMLXXIX@VERT/MDJ to Deuce on Tuesday, April 29, 2008 18:47:02
    Ok, so I messed with the code you sent me a little, and tried it using
    both "127.0.0.1" with port 5000 + bbs.node_num
    and "127.0.0." + bbs.node_num with port 5000

    both had the same result, listen error: 45
    but there didn't seem to be a problem binding them either way

    here's the code.. it's spammy
    I didn't really expect it to work, since I'm half guessing, but I thought I was on the right track.. maybe not.

    load("sockdefs.js");
    load("sbbsdefs.js");
    load("nodedefs.js");

    var stream=new Socket(SOCK_DGRAM, "InterNode");
    main();

    function main()
    {
    if(!stream.bind(9000+bbs.node_num, "127.0.0.1")) {
    writeln("Bind failed: "+stream.error);
    exit(1);
    }
    else
    {
    if(ConnectionListener()) Chat();
    else exit(1);
    }
    }
    function Chat()
    {
    //Receive();
    writeln("Test connection successful");
    exit(0);
    }
    function ConnectionListener()
    {
    write("Waiting for users to connect");
    for(i=0;i<10;i++)
    {
    for(node in system.node_list) {
    stream.sendto("ping","127.0.0.1",9000 + node);
    }
    if(stream.listen()) return true;
    if(console.inkey().toUpperCase()=="Q") exit(1);
    mswait(250);
    write(".");
    }
    writeln("\r\nListen failed: "+stream.error);
    exit(1);
    }

    ---
    þ Synchronet þ The BRoKEN BuBBLE (MDJ.ATH.CX)
  • From Deuce@VERT/SYNCNIX to MCMLXXIX on Tuesday, April 29, 2008 19:35:59
    Re: Socket Test
    By: MCMLXXIX to Deuce on Tue Apr 29 2008 06:47 pm

    both had the same result, listen error: 45
    but there didn't seem to be a problem binding them either way

    Heh, whoops, mixing my protocols there. You don't listen() for UDP since it's connectionless.

    Remove the listen() call and all should be good.

    ---
    Synchronet - Jump on the Web 0.2 bandwagon!

    ---
    þ Synchronet þ My Brand-New BBS (All the cool SysOps run STOCK!)
  • From Deuce@VERT/SYNCNIX to MCMLXXIX on Tuesday, April 29, 2008 20:24:57
    Re: Socket Test
    By: Deuce to MCMLXXIX on Tue Apr 29 2008 07:35 pm

    both had the same result, listen error: 45
    but there didn't seem to be a problem binding them either way

    Heh, whoops, mixing my protocols there. You don't listen() for UDP since it's connectionless.

    Remove the listen() call and all should be good.

    Here's the code updated to do it both ways:
    load("sbbsdefs.js");
    load("sockdefs.js");

    var base_port=5000;
    var use_ports=true;

    var s=new Socket(SOCK_DGRAM, "InterNode");

    var bind_addr="127.0.0.";
    var bind_port=base_port;
    if(use_ports) {
    bind_addr += "1";
    bind_port += bbs.node_num - 1;
    }
    else {
    bind_addr += bbs.node_num;
    }

    if(!s.bind(bind_port, bind_addr)) {
    writeln("Bind to "+bind_addr+":"+bind_port+" failed: "+s.error);
    exit(1);
    }

    writeln("Q to quit or # to send message to node");

    while(1) {
    var k=console.inkey(100);
    if(k.toUpperCase()=='Q')
    break;

    if(parseInt(k)>0) {
    console.write(": ");
    var msg=console.getstr("", 77);
    var port=base_port;
    var addr="127.0.0.";
    if(use_ports) {
    port += parseInt(k)-1;
    addr += '1';
    }
    else {
    addr += k;
    }

    s.sendto(msg, addr, port);
    }

    if(s.data_waiting) {
    var d;
    d=s.recvfrom();
    writeln("Message from "+d.ip_address+":"+d.port);
    writeln(d.data);
    writeln("");
    }
    }


    ---
    Synchronet - Jump on the Web 0.2 bandwagon!

    ---
    þ Synchronet þ My Brand-New BBS (All the cool SysOps run STOCK!)
  • From MCMLXXIX@VERT/MDJ to Deuce on Wednesday, April 30, 2008 08:35:32
    Re: Socket Test
    By: Deuce to MCMLXXIX on Tue Apr 29 2008 07:35 pm

    both had the same result, listen error: 45
    but there didn't seem to be a problem binding them either way

    Heh, whoops, mixing my protocols there. You don't listen() for UDP since it's connectionless.

    Remove the listen() call and all should be good.

    Is there a way to tell if there is anyone on the receiving end? I.E. if you're the only one trying to run the engine it will either wait for someone to connect, or kick you out. I guess I can make it send a "yo! I'm here!" message when anyone runs it.

    ---
    þ Synchronet þ The BRoKEN BuBBLE (MDJ.ATH.CX)
  • From Deuce@VERT/SYNCNIX to MCMLXXIX on Wednesday, April 30, 2008 11:08:54
    Re: Re: Socket Test
    By: MCMLXXIX to Deuce on Wed Apr 30 2008 08:35 am

    Is there a way to tell if there is anyone on the receiving end? I.E. if you're the only one trying to run the engine it will either wait for
    someone to connect, or kick you out. I guess I can make it send a "yo! I'm here!" message when anyone runs it.

    Not with UDP... with TCP this is possible.

    ---
    Synchronet - Jump on the Web 0.2 bandwagon!

    ---
    þ Synchronet þ My Brand-New BBS (All the cool SysOps run STOCK!)