<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>[A5] Event and socket messages ?</title>
		<link>http://www.allegro.cc/forums/view/614032</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sun, 16 Mar 2014 21:10:56 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi everybody,</p><p>I am beginning a new (game) project, and I&#39;m using both Allegro and network communication for the first time. The documentation of Allegro is easy and complete so I have a good time using it, but I still have just notions of how a network works (I am still learning about what sockets are exactly).</p><p>I am now at the point where I need the game client to retrieve data such as position of players sent from a server.<br />So, as in my main loop I am waiting for an event, using :<br /><span class="source-code"><a href="http://www.allegro.cc/manual/al_wait_for_event"><span class="a">al_wait_for_event</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_EVENT_QUEUE"><span class="a">ALLEGRO_EVENT_QUEUE</span></a>, <a href="http://www.allegro.cc/manual/ALLEGRO_EVENT"><span class="a">ALLEGRO_EVENT</span></a><span class="k3">*</span><span class="k2">)</span><span class="k2">;</span></span><br />and as this function &quot;freezes&quot; the program, I can&#39;t call such things as &#39;recv&#39; or &#39;recvfrom&#39; to process the data I should receive,<br />I imagined I could create an user event which would be emitted whenever data was retrieved.</p><p>Sadly, I couldn&#39;t find a similar question or an example about events and network, so I am referring to your wisdom.</p><p>My questions are : <br /> - Is it the &quot;proper way&quot; to handle data communication over a network ?<br />  - if not, what method should I use ?<br />  - if yes, how do I have to &quot;emit&quot; my event ? (do I have to use multithreading (which I have never used either) ? Is there a way to &quot;overload&quot; the al_wait_for_event function ?)</p><p>I apologize if the terms I used aren&#39;t exact (I hope it&#39;s still understandable).</p><p>Thanks in advance for your answers.</p><p>edit : I omitted to mention I wish to use only C language (so no objects).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (dt65536)</author>
		<pubDate>Sun, 16 Mar 2014 07:35:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If you don&#39;t feel comfortable making your networking code feed an allegro event queue, you can use <span class="source-code"><a href="http://www.allegro.cc/manual/al_wait_for_event_timed"><span class="a">al_wait_for_event_timed</span></a></span> or <span class="source-code"><a href="http://www.allegro.cc/manual/al_get_next_event"><span class="a">al_get_next_event</span></a></span>, and handle your own waiting.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Sun, 16 Mar 2014 08:54:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks for your reply,<br />The fact is I have no idea what method to use, as both creating my own waiting loop and using the threading seems it can work.<br />Anyway, I&#39;ll stick to using <span class="source-code"><a href="http://www.allegro.cc/manual/al_wait_for_event"><span class="a">al_wait_for_event</span></a></span> and create an <span class="source-code"><a href="http://www.allegro.cc/manual/ALLEGRO_THREAD"><span class="a">ALLEGRO_THREAD</span></a></span>, I&#39;m not sure how to create a loop that wakes the program up only if an event is sent or a message is received.</p><p>Is there any project to one day support network communications and sockets as a part of Allegro (either as an addon or in the core) ?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (dt65536)</author>
		<pubDate>Sun, 16 Mar 2014 20:04:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If you go the thread route, you can send your own custom messages to your main loop&#39;s event queue to wake it up and handle whatever you need to handle. (see: <span class="source-code"><a href="http://www.allegro.cc/manual/al_init_user_event_source"><span class="a">al_init_user_event_source</span></a></span> and <span class="source-code"><a href="http://www.allegro.cc/manual/al_emit_user_event"><span class="a">al_emit_user_event</span></a></span>)</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/614032/997838#target">dt65536</a> said:</div><div class="quote"><p>I&#39;m not sure how to create a loop that wakes the program up only if an event is sent or a message is received.</p></div></div><p>event queue&#39;s will wake <span class="source-code"><a href="http://www.allegro.cc/manual/al_wait_for_event"><span class="a">al_wait_for_event</span></a></span> up when they get an event, no matter who sends the event.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Sun, 16 Mar 2014 21:10:56 +0000</pubDate>
	</item>
</rss>
