caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] cdk & glob
@ 2001-08-04  0:05 Alexander V. Voinov
  2001-08-05 17:10 ` [Caml-list] Socket example dsfox
  0 siblings, 1 reply; 4+ messages in thread
From: Alexander V. Voinov @ 2001-08-04  0:05 UTC (permalink / raw)
  To: caml-list

Hi CDK maintainer(s) & contributor(s),

I tried to recompile cdk 3.01+1 on Sparc/Solaris 2.7 and found that only
those flags are supported:

#define GLOB_ERR 0x0001  /* Don't continue on directory error */
#define GLOB_MARK 0x0002  /* Mark directories with trailing / */
#define GLOB_NOSORT 0x0004  /* Don't sort pathnames */
#define GLOB_NOCHECK 0x0008  /* Return unquoted arg if no match */
#define GLOB_DOOFFS 0x0010  /* Ignore gl_offs unless set */
#define GLOB_APPEND 0x0020  /* Append to previous glob_t */
#define GLOB_NOESCAPE 0x0040  /* Backslashes do not quote M-chars */

I had to comment unsupported flags from glob_c.c (unix2).

I compiled everything with gcc-2.95.2.

When I tried gcc 3.00, ocamlc(?) supplied within cdk, dumped core, so
that the build was impossible.

Is there a way to specify location of wrapped packages (like Tk)
somewhere in ./configure?

Alexander


-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Caml-list] Socket example
  2001-08-04  0:05 [Caml-list] cdk & glob Alexander V. Voinov
@ 2001-08-05 17:10 ` dsfox
  2001-08-06  1:57   ` Felix Terkhorn
  2001-08-15 22:13   ` [Caml-list] ffi-1.2 - this version reads C header files! dsfox
  0 siblings, 2 replies; 4+ messages in thread
From: dsfox @ 2001-08-05 17:10 UTC (permalink / raw)
  To: caml-list

If anyone can forward me a dead simple example of using the ocaml Unix
module to open a socket pair to a server and reading and writing to
it, I would be very grateful.
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Socket example
  2001-08-05 17:10 ` [Caml-list] Socket example dsfox
@ 2001-08-06  1:57   ` Felix Terkhorn
  2001-08-15 22:13   ` [Caml-list] ffi-1.2 - this version reads C header files! dsfox
  1 sibling, 0 replies; 4+ messages in thread
From: Felix Terkhorn @ 2001-08-06  1:57 UTC (permalink / raw)
  To: dsfox; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 3629 bytes --]

dsfox@cogsci.ucsd.edu wrote:
> If anyone can forward me a dead simple example of using the ocaml Unix
> module to open a socket pair to a server and reading and writing to
> it, I would be very grateful.

Here's a pretty simple example.  First of all, get two terminals open:
one is going to be your 'client' terminal, and the other, your
'server' terminal.  Run OCaml toplevel on both (one that has support
for the Unix library).  Now, on each terminal, type this:


let sock = socket PF_INET SOCK_STREAM 0;;


This will give you an unconnected/unbound socket descriptor with which
to play.  Now, on the server terminal, type:


bind sock (ADDR_INET (inet_addr_of_string "127.0.0.1",55555));;
listen sock;;
let (client_sock,client_addr) = accept sock;;



"bind" hooks up the socket to a specific IP address and port.  Here,
we use 127.0.0.1:55555.  We write inet_addr_of_string "127.0.0.1"
because OCaml expects to receive its own type of ip address
abstraction.  inet_addr_of_string creates that.  ADDR_INET simply tags
the inet_addr and port number as a 'sockaddr'.

"listen" flags the socket as "listening," ie, it should be expecting
to receive a connection from somewhere in the internet.

"accept" places the program in a wait-state until a connection has
been made with another socket.  When that connection is made, accept
returns a tuple consisting of the client socket and the address from
which the client is connecting.  The original socket is not changed:
it is now dedicated to handling "incoming calls."  Instead, a new
socket is connected on another port, and that is the socket through
which the server can communicate with its client.

Remember: the server must bind, then listen, then accept to receive
connections.


Now, on the client terminal, type:


connect sock (ADDR_INET (inet_addr_of_string "127.0.0.1",55555));;


This hooks up the socket on the client side to the socket on the
server side.

So on the client side, we can do


send sock "hello" 0 5 [];;


and that will send the string "hello" (starting at index 0, and taking
a slice of 5 characters) across the socket.  The empty list is a list
"message flags."  Since I don't know what they do, I haven't put any
in the list. :)

Then, on the server side, we can do


let buf = String.create 32;;
recv client_sock buf 0 5 [];;


recv works basically like send... and they both work more or less like
Unix.read and Unix.write.  'buf' is the string that is to be
side-effected by recv when it gets data from the socket.  If you look
at 'buf' after this call, you'll see (hopefully) 'hello' sitting at
the front of the string.

send and recv both return how many characters they sent or received,
respectively.  Keep in mind that you may have to do multiple
sends/recvs in order to get very large chunks of text across.  One way
to handle this a little more elegantly is to do something like


let (sock_in,sock_out) = 
   (in_channel_of_descr sock,out_channel_of_descr sock);;


which should work on the client side (or the server side, if you
change 'sock' to 'client_sock'), and which will let you then use all
of the pervasive library's input and output functions on the "socket
channels" you've created, eg...


output_string sock_out "i (heart) ocaml";;
flush sock_out;;
input_string sock_in  (* and hope the other side has sent something back *)


This is a lot nicer than messing with side-effecting and string
buffers, IMHO.  Just don't forget to flush. ;)

Hope this helps.

Felix


-- 
'(felix-terkhorn . masterkh@indiana.edu)

[-- Attachment #2: Type: application/pgp-signature, Size: 251 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Caml-list] ffi-1.2 - this version reads C header files!
  2001-08-05 17:10 ` [Caml-list] Socket example dsfox
  2001-08-06  1:57   ` Felix Terkhorn
@ 2001-08-15 22:13   ` dsfox
  1 sibling, 0 replies; 4+ messages in thread
From: dsfox @ 2001-08-15 22:13 UTC (permalink / raw)
  To: caml-list

I've just completed a rewrite of my FFI generator, and this one is
much easier to use than the the previous ones.  There are three
examples, one uses the system header file to interface to stdlib, the
others use the unmodified Xlib header files to generate X applications.
I've uploaded the package to ftp://foxthompson.net/pub/ffi-1.2.tar.gz.
Please send me mail if you try this!
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2001-08-15 22:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-04  0:05 [Caml-list] cdk & glob Alexander V. Voinov
2001-08-05 17:10 ` [Caml-list] Socket example dsfox
2001-08-06  1:57   ` Felix Terkhorn
2001-08-15 22:13   ` [Caml-list] ffi-1.2 - this version reads C header files! dsfox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).