From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id UAA17115 for caml-redist@pauillac.inria.fr; Fri, 5 May 2000 20:44:08 +0200 (MET DST) Resent-Message-Id: <200005051844.UAA17115@pauillac.inria.fr> Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id TAA08582 for ; Fri, 5 May 2000 19:28:56 +0200 (MET DST) Received: from nobuko-cum.uchicago.edu (nobuko-cum.uchicago.edu [128.135.21.33]) by concorde.inria.fr (8.8.7/8.8.7) with ESMTP id TAA20716 for ; Fri, 5 May 2000 19:28:29 +0200 (MET DST) Received: from localhost (tyler@localhost) by nobuko-cum.uchicago.edu (8.9.3/8.9.3) with ESMTP id MAA01471; Fri, 5 May 2000 12:29:15 -0500 Date: Fri, 5 May 2000 12:29:15 -0500 (CDT) From: tyler To: Ravi Chamarty cc: caml-list@inria.fr Subject: Re: Netwoking examples.. In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Resent-From: weis@pauillac.inria.fr Resent-Date: Fri, 5 May 2000 20:44:08 +0200 Resent-To: caml-redist@pauillac.inria.fr Hey, These are two very short programs I hacked up that worked when I tried them. Here's a server: open Unix let _ = let this_socket = (Unix.socket PF_INET SOCK_STREAM 0) in let this_socket_addr = ADDR_INET ((Unix.inet_addr_of_string "127.0.0.1"), 60648) in Unix.bind this_socket this_socket_addr; Unix.listen this_socket 3; let (client_socket, client_addr) = Unix.accept this_socket in let this_string = String.create 100 in let number_read = Unix.read client_socket this_string 0 100 in let number_written = Unix.write client_socket this_string 0 number_read in Unix.close this_socket; exit 0 ;; Here's a client: open Unix let _ = let this_socket = (Unix.socket PF_INET SOCK_STREAM 0) in let server_addr = ADDR_INET ((Unix.inet_addr_of_string "127.0.0.1"), 60648) in Unix.connect this_socket server_addr; let num_written = Unix.write this_socket "hello world" 0 11 in let response_string = String.create 20 in let num_read = Unix.read this_socket response_string 0 20 in print_string response_string; Unix.close this_socket; exit 0 ;; Compile them, start up the server program, and then run the client program. It should print out "hello world". Again, it's way simple, but it should hopefully give you some ideas. For a server, make the socket, then bind it to an address, then have it listen on a port, then have it accept a connection. When you're done, close the socket (is there an ocaml function for flushing a file descriptor, not an out_channel?). For a client, just make the socket and tell it where to connect to. Its own address and port are handled automatically. You might want to look around for a socket tutorial in c (I've seen one somewhere before...). If you understand what's happening on both ends, it's a question of syntax at that point. Have fun! tyler On Thu, 4 May 2000, Ravi Chamarty wrote: > > Hi, > > Can anyone give me a pointer to a few networking examples in > OCaml using sockets and connects ?? > > > Thanks, > Ravi > ---------------------------------------------------------- > Ravi S Chamarty E-mail: ravi@ittc.ukans.edu > Graduate Research Assistant, Voice :785-864-7799 > ITTC,2291 Irving Hill Road, > University of Kansas, > Lawrence KS 66044-7541 >