Here's a quick howto on how to go from server-ip and port to in_obj_channel and out_obj_channel.
It's really quite simple, but this might save you half an hour of searching:
(* You need these two modules *)
open Netchannels;;
open Netpop;;
(* this function opens a connection to a server with the
* Pervasives.in_channel and out_channel
*)
let open_con server port =
let server_addr = Unix.inet_addr_of_string server in
let sockaddr = Unix.ADDR_INET(server_addr,port) in
Unix.open_connection sockaddr
(* This converts Pervasives channels to
* Netchannels.in_obj_channel and out_obj_channel
*)
let perv_to_obj (in_c,out_c) =
let oic = new input_channel in_c in
let ooc = new output_channel out_c in
(oic,ooc)
(* the simply use both functions we just wrote to
* connect with server and port, getting a tuple:
* in_obj_channel * out_obj_channel as return value
*)
let open_obj_con server port =
let channels = open_con server port in
perv_to_obj channels
I needed this because I want to write some POP3 stuff with the Netpop library.
Hope this helps someone! :-)
0 comments:
Post a Comment