testing some unix stuff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Unix | |
let () = | |
let server_sock = socket PF_INET SOCK_STREAM 0 in | |
(* so we can restart our server quickly *) | |
setsockopt server_sock SO_REUSEADDR true ; | |
if not (getsockopt server_sock SO_REUSEADDR) then prerr_endline "fail1"; | |
(* build up my socket address *) | |
let address = (gethostbyname(gethostname())).h_addr_list.(0) in | |
bind server_sock (ADDR_INET (Unix.inet_addr_any, 9000)) ; | |
(* Listen on the socket. Max of 10 incoming connections. *) | |
listen server_sock 10 ; | |
(* accept and process connections *) | |
while true do | |
let (client_sock, client_addr) = accept server_sock in | |
Unix.setsockopt client_sock Unix.TCP_NODELAY true; | |
if not (Unix.getsockopt client_sock Unix.TCP_NODELAY) then | |
prerr_endline "FAIL"; | |
let str = "Hello\n" in | |
let len = String.length str in | |
let x = send client_sock str 0 len [] in | |
shutdown client_sock SHUTDOWN_ALL | |
done ;; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment