all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* synchronous network communication?
@ 2011-01-17  3:15 chris
  2011-01-17  7:21 ` Helmut Eller
  0 siblings, 1 reply; 3+ messages in thread
From: chris @ 2011-01-17  3:15 UTC (permalink / raw)
  To: help-gnu-emacs

Hi there,

I am trying to talk to a server over a telnet like protocol, using
open-network-stream like so:
* first open the stream:
(setq redis (open-network-stream "*redis*" buffer host port))

* All works well and I can talk to the process like so:

(process-send-string
 redis
 (format(concat
	 "hgetall "
	 (buffer-substring-no-properties beg end)
	 "\r\n"
	 "\r\n"))))

and find the results in my buffer.  However, this is an asynchronous
communication and if the answer takes a while, my code might try to
deal with the answer before it is ready.  So my question is:  is there
a way to do this communication in an asynchronous manner?  I looked
through the docs but could not find anything.

Any help appreciated,

Chris


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

* Re: synchronous network communication?
  2011-01-17  3:15 synchronous network communication? chris
@ 2011-01-17  7:21 ` Helmut Eller
  2011-01-18  7:04   ` chris
  0 siblings, 1 reply; 3+ messages in thread
From: Helmut Eller @ 2011-01-17  7:21 UTC (permalink / raw)
  To: help-gnu-emacs

* chris [2011-01-17 03:15] writes:

> and find the results in my buffer.  However, this is an asynchronous
> communication and if the answer takes a while, my code might try to
> deal with the answer before it is ready.  So my question is:  is there
> a way to do this communication in an asynchronous manner?

If you mean synchronous manner, then the answer is no.  A blocking API
would block the event loop and Emacs would appear to be "frozen".

You can however use a process-filter.  That's a function that is called
with the data received from the other end.  So you always know when data is
ready to process.

If you must use a synchronous mode (e.g. for the the completion code)
then you could use accept-process-output and/or recursive-edit but I
would avoid that as long as possible.

Helmut


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

* Re: synchronous network communication?
  2011-01-17  7:21 ` Helmut Eller
@ 2011-01-18  7:04   ` chris
  0 siblings, 0 replies; 3+ messages in thread
From: chris @ 2011-01-18  7:04 UTC (permalink / raw)
  To: help-gnu-emacs

On Jan 17, 4:21 pm, Helmut Eller <eller.hel...@gmail.com> wrote:
> >  So my question is:  is there
> > a way to do this communication in an asynchronous manner?
>
> If you mean synchronous manner, then the answer is no.

A yes, as I said in the subject line, this is what I was looking for.
  A blocking API
> would block the event loop and Emacs would appear to be "frozen".

I see.  Thinking of it, this makes sense:-)

>
> You can however use a process-filter.  That's a function that is called
> with the data received from the other end.  So you always know when data is
> ready to process.

Based on your answer, I found "accept-process-output", which seems to
more or less to do what I need, that is, giving the process time to do
its business and then allow me to continue.  Preliminary tests seem to
suggest that this speeds up things substantially.

Thanks a lot for your help,


Chris



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

end of thread, other threads:[~2011-01-18  7:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-17  3:15 synchronous network communication? chris
2011-01-17  7:21 ` Helmut Eller
2011-01-18  7:04   ` chris

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.