1. tinou
  2. StarML

Source

StarML / main.ml


let accept_con _ =
    let sock = Unix.socket Unix.PF_INET Unix.SOCK_STREAM 0 in
    let saddr = Unix.ADDR_INET (Unix.inet_addr_any, 13337) in
    Unix.bind sock saddr;
    Unix.listen sock 4;
    Unix.accept sock

let main _ =
    print_endline "Sup dawg, I heard you like starcraft";
    print_endline "------------------------------------";
    print_endline "Waiting...";
    let (fd, _) = accept_con () in
    print_endline "Got it !";
    let buf = String.make 512 'X' in
    while true do
        let z = Unix.recv fd buf 0 512 [] in
        Printf.printf "Recv %d chars : <%s>" z
            (String.sub buf 0 z)
    done

let _ = main ()