caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* lablgtk2: receiving messages from network?
@ 2006-04-15 19:33 Ivan Matveich
  2006-04-15 19:45 ` [Caml-list] " yoann padioleau
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Ivan Matveich @ 2006-04-15 19:33 UTC (permalink / raw)
  To: caml-list

Dear ocaml users,

I'm writing a gtk program that must receive data through a tcp
connection and react to it immediately.

What's the best way to implement this?
Can gtk call me back when data is available on a socket?
How do I use Marshal without blocking?

Thank you.

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

* Re: [Caml-list] lablgtk2: receiving messages from network?
  2006-04-15 19:33 lablgtk2: receiving messages from network? Ivan Matveich
@ 2006-04-15 19:45 ` yoann padioleau
  2006-04-15 20:10 ` Markus Mottl
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: yoann padioleau @ 2006-04-15 19:45 UTC (permalink / raw)
  To: Ivan Matveich; +Cc: caml-list


On 15 avr. 06, at 21:33, Ivan Matveich wrote:

> Dear ocaml users,
>
> I'm writing a gtk program that must receive data through a tcp
> connection and react to it immediately.
>
> What's the best way to implement this?
> Can gtk call me back when data is available on a socket?
> How do I use Marshal without blocking?

I think that threads can be used for that kind of problem.
Welcome to the world of concurrency ...


>
> Thank you.
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs



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

* Re: [Caml-list] lablgtk2: receiving messages from network?
  2006-04-15 19:33 lablgtk2: receiving messages from network? Ivan Matveich
  2006-04-15 19:45 ` [Caml-list] " yoann padioleau
@ 2006-04-15 20:10 ` Markus Mottl
  2006-04-15 20:58 ` Eric Cooper
  2006-04-15 22:54 ` Remi Vanicat
  3 siblings, 0 replies; 7+ messages in thread
From: Markus Mottl @ 2006-04-15 20:10 UTC (permalink / raw)
  To: Ivan Matveich; +Cc: caml-list

On 4/15/06, Ivan Matveich <ivan.matveich@gmail.com> wrote:
> How do I use Marshal without blocking?

You can set the socket options Unix.SO_RCVTIMEO and Unix.SO_SNDTIMEO
using Unix.setsockopt_float, passing the number of seconds until
timeout as argument.

Regards,
Markus

--
Markus Mottl        http://www.ocaml.info        markus.mottl@gmail.com


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

* Re: [Caml-list] lablgtk2: receiving messages from network?
  2006-04-15 19:33 lablgtk2: receiving messages from network? Ivan Matveich
  2006-04-15 19:45 ` [Caml-list] " yoann padioleau
  2006-04-15 20:10 ` Markus Mottl
@ 2006-04-15 20:58 ` Eric Cooper
  2006-04-15 22:54 ` Remi Vanicat
  3 siblings, 0 replies; 7+ messages in thread
From: Eric Cooper @ 2006-04-15 20:58 UTC (permalink / raw)
  To: caml-list

On Sat, Apr 15, 2006 at 03:33:36PM -0400, Ivan Matveich wrote:
> I'm writing a gtk program that must receive data through a tcp
> connection and react to it immediately.
> 
> What's the best way to implement this?
> Can gtk call me back when data is available on a socket?
> How do I use Marshal without blocking?

You can use the Glib.IO interface to create a glib io_channel from
your TCP socket, and then use add_watch to associate a callback with
it.  Your socket will then be polled as part of the Glib main event loop.

-- 
Eric Cooper             e c c @ c m u . e d u


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

* Re: [Caml-list] lablgtk2: receiving messages from network?
  2006-04-15 19:33 lablgtk2: receiving messages from network? Ivan Matveich
                   ` (2 preceding siblings ...)
  2006-04-15 20:58 ` Eric Cooper
@ 2006-04-15 22:54 ` Remi Vanicat
  2006-04-16 22:28   ` Ivan Matveich
  3 siblings, 1 reply; 7+ messages in thread
From: Remi Vanicat @ 2006-04-15 22:54 UTC (permalink / raw)
  To: caml-list

2006/4/15, Ivan Matveich <ivan.matveich@gmail.com>:
> Dear ocaml users,
>
> I'm writing a gtk program that must receive data through a tcp
> connection and react to it immediately.

As someone already tell you, you could use the Glib.IO interface.
There is also equeue of Gerd Stolpman that is integrated with the Gtk
main loop, see
http://www.ocaml-programming.de/programming/equeue.html

(Sory for sending you this twice, the first time I forget to send it
on the list).


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

* Re: [Caml-list] lablgtk2: receiving messages from network?
  2006-04-15 22:54 ` Remi Vanicat
@ 2006-04-16 22:28   ` Ivan Matveich
  2006-04-16 23:45     ` Jacques Garrigue
  0 siblings, 1 reply; 7+ messages in thread
From: Ivan Matveich @ 2006-04-16 22:28 UTC (permalink / raw)
  To: caml-list

Thanks, module Glib.Io is what I needed.

Now I have another question. I've started writing some code,

module Channel =
  struct
    type event =
      | Connected of Unix.sockaddr
      | Dropped of Unix.sockaddr
      | Received of Unix.sockaddr * x
      | Sent of Unix.sockaddr * x
    type action =
      | Associate of Unix.sockaddr
      | Dissociate of Unix.sockaddr
      | Send of Unix.sockaddr * x

where x will be something returned by Marshal.from_string.

How do I properly specify its type?

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

* Re: [Caml-list] lablgtk2: receiving messages from network?
  2006-04-16 22:28   ` Ivan Matveich
@ 2006-04-16 23:45     ` Jacques Garrigue
  0 siblings, 0 replies; 7+ messages in thread
From: Jacques Garrigue @ 2006-04-16 23:45 UTC (permalink / raw)
  To: ivan.matveich; +Cc: caml-list

From: "Ivan Matveich" <ivan.matveich@gmail.com>

> Now I have another question. I've started writing some code,
> 
> module Channel =
>   struct
>     type event =
>       | Connected of Unix.sockaddr
>       | Dropped of Unix.sockaddr
>       | Received of Unix.sockaddr * x
>       | Sent of Unix.sockaddr * x
>     type action =
>       | Associate of Unix.sockaddr
>       | Dissociate of Unix.sockaddr
>       | Send of Unix.sockaddr * x
> 
> where x will be something returned by Marshal.from_string.
> 
> How do I properly specify its type?

I suppose x should be Obj.t, meaning that you're going to use Obj.repr
and Obj.obj. This is clearly unsafe, but any use of Marshal is.

Jacques Garrigue


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

end of thread, other threads:[~2006-04-16 23:45 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-04-15 19:33 lablgtk2: receiving messages from network? Ivan Matveich
2006-04-15 19:45 ` [Caml-list] " yoann padioleau
2006-04-15 20:10 ` Markus Mottl
2006-04-15 20:58 ` Eric Cooper
2006-04-15 22:54 ` Remi Vanicat
2006-04-16 22:28   ` Ivan Matveich
2006-04-16 23:45     ` Jacques Garrigue

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).