0

I'm developing a module in Python, but I guess that programming platform doesn't matter here. I'm trying to make a client connect to a server inside one thread using asynchronous programming. This means there is an event-loop that performs asynchronous jobs. And what I want to do is to - when a request comes in - create a client on localhost:Xport - and make the server asynchronously accept the connection from Xport (and perform the request and so on, blah, blah).

Since asynchronous programming is based on an event-loop and non-blocking operations (but in fact it's just a straight sequence of operations), is it possible to [1] make a client connect to a server and [2] make the server accept the connection - all in a single thread, asyhcnronously?

If it's possible, could anyone give a code snippet or some explanation?

ducin
  • 25,621
  • 41
  • 157
  • 256
  • "in other languages you would not need an event loop" - sorry, but it's a nonsense. What is "other languages". C++? Ruby? No event loop? There has to be an event loop to provide asynchronous programming, at least it can be hidden behind the scenes (as in both javascripts). PS I do rely on a framework (twisted), but using a framework doesn't allow me not to understand what I'm basically doing. Framework helps me to write less code (avoid boilerplate), but it's useless if I don't understand what's going on. – ducin Nov 02 '13 at 20:49
  • I'm pretty sure that `.NET` architecture does have an event loop inside (though it can be called differently, because it's MS). Something just has to handle incomming events. The same case is with any browser and JavaScript. You don't write any loop in JavaScript. You write a handler for the click event. So it's the `subscriber` (from pubish/subscrbe pattern). And when you click a button, your callback is called in fact. So where is the `publisher`? And this is the event loop :). There is no magic, all platforms use the same pattern for event handling. – ducin Nov 03 '13 at 11:29
  • I think you might find this Q/A useful: http://stackoverflow.com/questions/5425863/what-is-a-browser-event-loop, http://en.wikipedia.org/wiki/Event_loop and http://en.wikipedia.org/wiki/Reactor_pattern. Besides, type `.net event loop` in google and look at the results. – ducin Nov 03 '13 at 11:31

0 Answers0