English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Socket and Threads on windows
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-02-07 (10:30)
From: Olivier_Pérès <olivier.peres@l...>
Subject: Re: [Caml-list] Socket and Threads on windows
Julien Boulnois a écrit :
> let (ic,oc)=(Unix.in_channel_of_descr sock,Unix.out_channel_of_descr sock);;

    According to the manual, none of *_channel_of_descr works on sockets 
on Windows 95/98/Me. What are you using ? As for me, to avoid that kind 
of problems, when writing Amble I made my own send/receive functions. 
Send is trivial (Marshal to string and Unix.write), receive is also 
pretty simple :

let receive_message fd =
     (* 1 - allocate and read the header *)
     let hs = Marshal.header_size in
     let headerbuf = String.create hs in
     let hlen = Unix.read fd headerbuf 0 hs in

     (* 2 - prepare the buffer as a string that has the same size as the 
      *     and copy the header in the beginning
     let ds = Marshal.data_size headerbuf 0 in
     let buf = String.create (hs+ds) in
     String.blit headerbuf 0 buf 0 hs;

     (* 3 - receive the rest of the message (data part) *)
     let dlen = Unix.read fd buf hs ds in

     (* 4 - decoding (unmarshalling) *)
     Marshal.from_string buf 0

    You can get the whole thing from http://home.gna.org/amble/ ; 
licence : GPL.

    Hope this helps,