8.1.1. test/faio/faio-1.01.01

Start felix section to test/faio/faio-1.01.01-0.flx[1 /1 ]
     1: #line 700 "./lpsrc/flx_faio.pak"
     2: //Check sockets
     3: #import <flx.flxh>
     4: include "flx_stream";
     5: include "flx_socket";
     6: open Flx_stream;
     7: open Flx_socket;
     8: open Flx_stream::TerminalIOByteStream[Flx_socket::socket_t];
     9: 
    10: print "flx tcp stream test\n";
    11: 
    12: var listener: socket_t;
    13: var port = 0;  // you choose
    14: // var port = 1024;
    15: 
    16: // check errors. how is that done?
    17: mk_listener(&listener, &port, 1);
    18: // print "Got port: "; print port; endl;
    19: // print "accepting\n";
    20: 
    21: print "spawning connector\n";
    22: // not printing in thread to make output deterministic.
    23: // note that the connect shouldn't fail (immediately) because the
    24: // listener exists - it just hasn't called accept yet.
    25: spawn_fthread
    26: {
    27:   {
    28:     // print "Connector dude\n";  // get rid of, hard to test
    29:     var c: socket_t;
    30:     connect(&c, c"127.0.0.1", port); // connect to localhost
    31:     var st: string;
    32: 
    33:     get_line(c, &st);
    34:     print "connector got "; print st; endl;
    35:     write_string(c, "thanks\n");         // newline important
    36: 
    37:     ioclose(c);  // finished with this
    38:   };
    39: };
    40: 
    41: var s: socket_t;
    42: accept(listener, &s);
    43: ioclose(listener);  // not needed anymore
    44: 
    45: print "got connection\n";
    46: write_string(s, "server says hi\n");     // newline important here
    47: 
    48: var st: string;
    49: get_line(s, &st);
    50: 
    51: print "server got "; print st; endl;
    52: ioclose(s);
End felix section to test/faio/faio-1.01.01-0.flx[1]
Start data section to test/faio/faio-1.01.01-0.expect[1 /1 ]
     1: flx tcp stream test
     2: spawning connector
     3: got connection
     4: connector got server says hi
     5: server got thanks
End data section to test/faio/faio-1.01.01-0.expect[1]