From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id EAA14370; Wed, 18 Sep 2002 04:51:54 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 EAA12847 for ; Wed, 18 Sep 2002 04:51:53 +0200 (MET DST) Received: from grover.msi.co.jp ([192.51.53.141]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g8I2pq104611 for ; Wed, 18 Sep 2002 04:51:52 +0200 (MET DST) Received: from localhost [127.0.0.1] (ikeda) by grover.msi.co.jp with esmtp (Exim 3.12 #1 (Debian)) id 17rUwQ-0006Hc-00; Wed, 18 Sep 2002 11:51:50 +0900 To: caml-list@inria.fr Subject: [Caml-list] Client/Server socket communication X-Mailer: Mew version 1.94.2 on Emacs 20.7 / Mule 4.0 (HANANOEN) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20020918115148K.ikeda@msi.co.jp> Date: Wed, 18 Sep 2002 11:51:48 +0900 From: IKEDA Katsumi X-Dispatcher: imput version 990905(IM130) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi, I use Ocaml 3.06 on Vine Linux 2.1.5. Vine Linux is RedHat 5.* and 6.* based distribution and ... kernel: 2.2.18 libc: 6 -> 2.1.3 I make Client/Server socket communication program. The followings are the lists. ---------------- server.ml ---------------- (* server.ml *) let openSock port = let sock = Unix.socket Unix.PF_INET Unix.SOCK_STREAM 0 in begin Unix.bind sock (Unix.ADDR_INET(Unix.inet_addr_any,port)); Unix.listen sock 20; sock end ;; let waitChild s = print_string "server: waitChild called\n"; flush stdout ; let s = Unix.waitpid [ Unix.WNOHANG ] 0 in () ;; let main() = Sys.set_signal Sys.sigchld (Sys.Signal_handle waitChild) ; print_string "server started.\n"; flush stdout; let port = 999999 in let sock = openSock port in begin while true do try let (fd,a) = Unix.accept sock in begin print_string "server accepted \n"; flush stdout; let pid = Unix.fork() in match pid with 0 -> begin print_string "run a child process.\n"; flush stdout; let buf = String.create 10 in let ret = Unix.read fd buf 0 10 in begin print_string "ret = "; print_int ret; print_newline(); print_string buf; print_newline(); flush stdout; Unix.sleep(3); print_string "exit a child process.\n"; flush stdout; exit 0 end end | _ -> (* parent process *) begin print_string "server parent side\n"; flush stdout ; end end with Unix.Unix_error(err, ctx1, ctx2) -> if (err = Unix.EINTR) then print_string "Function interrupted by signal\n" else begin print_string "Unix.Unix_error in main\n"; end | _ -> print_string "Unexpected Exception\n" done; end ;; main();; -------------------------------- ---------------- client.ml ---------------- let main() = let server_address = "127.0.0.1" and port = 999999 in let sock = Unix.socket Unix.PF_INET Unix.SOCK_STREAM 0 in Unix.connect sock(Unix.ADDR_INET((Unix.inet_addr_of_string server_address), port)); let msg = "Hello!" in let ret = Unix.write sock msg 0 (String.length msg) in print_string "reg = "; print_int ret; print_newline(); flush stdout; Unix.close sock; ;; main();; ---------------- I compiled these by ocamlc. Now, I make run_client.sh script ---------------- run_client.sh ---------------- #!/bin/sh ./client & ./client & ./client & ./client & ./client & ./client & ./client & ./client & ./client & ./client & -------------------------------- I run "./server &". Then I run "./run_client.sh" several times. I found something wrong. I run "ps" command, it displays the following: PID TTY TIME CMD 1225 pts/3 00:00:00 sh 3156 pts/3 00:00:00 server 3197 pts/3 00:00:00 server 3226 pts/3 00:00:00 ps Why "server " is occurred. What do I have to do to correct ? thanks. -- IKEDA Katsumi ------------------- 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