Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] reading from socket connection
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Christian.Schaller@s...
Subject: [Caml-list] reading from socket connection
Hi,

When connecting, let's say to a nntp server and just exchanging some
information, the OCaml manual tells me to use open_connection from the Unix
library.  This works well, however, how can I read the output from the
remote server?  My first try was a readLines function (see below) to read
until EOF, however there's no EOF, thus my program hanging.  Any hints?  Is
this a cygwin related problem?

Thanks,
  Chris

open Unix

let server = inet_addr_of_string "10.10.10.10"
let sockaddr = ADDR_INET (server, 119)

let readLines ch =
  try
    while true do
      print_endline (input_line ch)
    done
  with End_of_file -> ();;

let client_fun ic oc =
  output_string oc "help\n";
  flush oc;
  readLines ic

let _ = 
  let ic, oc = open_connection sockaddr in
  client_fun ic oc;
  shutdown_connection ic

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners