I have been on learning Ocaml for a week, some things got clear, the others rather not. I'm trying to compose a simple Tic-Tac-Toe server accepting connections via telnet. Just for a word. I have to use Lwt and rigth now it seems for me a darken place because I had faced too much of language pecularities. The begining of the code:
let sock = Lwt_unix.socket Unix.PF_INET Unix.SOCK_STREAM 0
let setting_up_server_socket =
let sockaddr = (Unix.ADDR_INET(Unix.inet_addr_of_string "127.0.0.1", 23233)) in
Lwt_unix.set_close_on_exec sock;
Lwt_unix.setsockopt sock Unix.SO_REUSEADDR true;
Lwt_unix.bind sock sockaddr;
Lwt_unix.listen sock 20
OK, that's clear. The server socket is set to listen for clients connections. Let's try to get a first guest:
let handle_income =
Lwt_unix.accept sock;;
Seems to be clear, but:
val handle_income : (Lwt_unix.file_descr * Lwt_unix.sockaddr) Lwt.t = <abstr>
Here I'm stacked. I don't know even how to send a message to client socket. Unlike general Unix.accept it returns ('a * 'b) Lwt.t. Some questions:
- How can I get pure client "Lwt_unix.file_descr" from that?
- ('a * 'b) Lwt.t. is a tuple belonging to Lwt.t object, isn't it? Or it just a field? I am confused at all.
P.S. Sorry if my English is not acceptable. I was learning it long time ago. As the question is already asked please give a piece of advise, where I can get the best information about Ocaml. The best a mean short/clearness. Due reading O'REILLY I instantly forget what I was reading 5 min ago because it's never clear what this or that the author talking about is used for. Ocaml is quite different with Java and JS I had started with.