Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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

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?


open Unix

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

let readLines ch =
    while true do
      print_endline (input_line ch)
  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 Archives:
Bug reports: FAQ:
Beginner's list: