<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Sockets addon</title>
		<link>http://www.allegro.cc/forums/view/611518</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Fri, 30 Nov 2012 07:11:15 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I think a sockets addon for allegro would be extremely useful. Even just some basic functions that abstract sockets across platforms would be useful. Pretty much all of my games require sockets, and if allegro included sockets it would be the only library I need. I think a lot of modern games use network connectivity for various things, and sockets should be a part of game libraries, and by being a simple addon, people could still use more advanced socket libraries if they want (like RakNet).</p><p>Just thought I would throw the idea out there. What are your thoughts on this?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (TrieBr)</author>
		<pubDate>Wed, 28 Nov 2012 05:25:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You don&#39;t need another library to use sockets. Under Linux/OSX/iOS they are part of libc. Under Windows you just have to link against wsock2 which is a system component. I don&#39;t know about Android but I&#39;m quite sure it also has sockets.</p><p>So, if you use sockets, they should be available everywhere.</p><p>I do agree though, a wrapper to hide the platform differences would be nice. Maybe just copy the sockets API, with reduced functionality and always blocking. Something like:</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span><span class="k1">int</span> my_init<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  2</span>
<span class="number">  3</span><span class="k1">int</span> my_socket<span class="k2">(</span><span class="k1">char</span> <span class="k1">const</span> <span class="k3">*</span>protocol<span class="k2">)</span><span class="k2">;</span> <span class="c">// e.g. s = my_socket("udp6")</span>
<span class="number">  4</span>
<span class="number">  5</span><span class="k1">int</span> my_listen<span class="k2">(</span><span class="k1">int</span> socket, <span class="k1">char</span> <span class="k1">const</span> <span class="k3">*</span>address<span class="k2">)</span><span class="k2">;</span> <span class="c">// e.g.my_listen(s, "0.0.0.0:8080");</span>
<span class="number">  6</span>
<span class="number">  7</span><span class="k1">int</span> my_connect<span class="k2">(</span><span class="k1">int</span> socket, <span class="k1">char</span> <span class="k1">const</span> <span class="k3">*</span>address<span class="k2">)</span><span class="k2">;</span> <span class="c">// e.g. my_connect(s, "www.allegro.cc:80");</span>
<span class="number">  8</span>
<span class="number">  9</span><span class="k1">int</span> my_accept<span class="k2">(</span><span class="k1">int</span> socket<span class="k2">)</span><span class="k2">;</span> <span class="c">// e.g. s2 = my_accept(s);</span>
<span class="number"> 10</span>
<span class="number"> 11</span><span class="k1">int</span> my_send<span class="k2">(</span><span class="k1">int</span> socket, <span class="k1">char</span> <span class="k1">const</span> <span class="k3">*</span>buffer, <span class="k1">int</span> bytes<span class="k2">)</span><span class="k2">;</span> <span class="c">// would send all bytes, unlike the socket send()</span>
<span class="number"> 12</span>
<span class="number"> 13</span><span class="k1">int</span> my_recv<span class="k2">(</span><span class="k1">int</span> socket, <span class="k1">char</span> <span class="k3">*</span>buffer, <span class="k1">int</span> max_bytes<span class="k2">)</span><span class="k2">;</span> <span class="c">// blocking</span>
<span class="number"> 14</span>
<span class="number"> 15</span><span class="k1">int</span> my_shutdown<span class="k2">(</span><span class="k1">int</span> socket<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 16</span>
<span class="number"> 17</span><span class="k1">int</span> my_done<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
</div></div><p>

Each function would either return &gt;= 0 if successful or a negative error code. Would probably only need one error code which tells to close the socket and recreate it.</p><p>I think it would take about half an hour to write, including the platform differences (e.g. under Windows, have to call WSAInit...). Still, I&#39;d feel like a serious case of re-inventing the wheel <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Wed, 28 Nov 2012 06:21:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>To me, an Allegro addon would mean something like integration with the file API:
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/al_fwrite"><span class="a">al_fwrite</span></a><span class="k2">(</span>socket, <span class="s">"Hello"</span>, <span class="n">6</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
and the events API:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">if</span> <span class="k2">(</span>event.type <span class="k3">=</span><span class="k3">=</span> ALLEGRO_EVENT_PACKET_RECEIVED<span class="k2">)</span> 
<span class="k2">{</span>
<span class="k2">}</span>
</pre></div></div><p>

(Not that you&#39;d use those two methods together.)</p><p>Anybody wanting to write some low-latency networking code would use something else.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Wed, 28 Nov 2012 06:46:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;ve said this for years and been told to write one of my own to submit as a possible add-on for Allegro. Sadly my socket programming is minimal so the start I had on an add-on is rather pathetic. I need to scrap my old code (minimal as it is) and start playing with it again.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Specter Phoenix)</author>
		<pubDate>Wed, 28 Nov 2012 09:33:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/611518/971076#target">Matthew Leverton</a> said:</div><div class="quote"><p>Anybody wanting to write some low-latency networking code would use something else.</p></div></div><p>
I agree. But then I don&#39;t really see the point anymore. Instead of using a TCP stream to access a website, why not use libcurl which handles a lot of stuff like ssl and cookies and so on. And instead of sending UDP packets, why not use Enet which already handles all the platform differences and has a way of sending reliable messages.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Wed, 28 Nov 2012 16:37:31 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I guess the point would be to have all the &quot;basics&quot; in a single Library, particularly in a game game-versed one like Allegro to be more complete.</p><p>...so the &quot;basic&quot; user may have only one single actual dependency in his projects.</p><p>I suppose thou that having only &quot;basics&quot; is not really attractive altogether in a <i>low-level</i> lib like Allegro.</p><p>And, but that may be just me since I am no hard-core programmer at all, I do not think that linking aganist a set of dependencies instead of just one (which in any case shells a sub-tree of them) matters all that much.</p><p>Of course this requires you to master more than one API. <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (pkrcel)</author>
		<pubDate>Wed, 28 Nov 2012 16:50:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>This would mostly mean creating the Windows .dll in a way which includes Enet and/or libcurl. No code changes to Allegro required. Just Mical would have to adjust his Windows build scripts.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Wed, 28 Nov 2012 19:37:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/611518/971083#target">Elias</a> said:</div><div class="quote"><p> But then I don&#39;t really see the point anymore. Instead of using...</p></div></div><p>My main point is that a network addon that does not integrate with Allegro is completely useless, due to other libraries already existing. </p><p>e.g., Using libcurl as the backend, you could do this:
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/al_fopen"><span class="a">al_fopen</span></a><span class="k2">(</span><span class="s">"https://www.allegro.cc/forums/recent"</span>, <span class="s">"r"</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

But if you&#39;re just going to write a low level API or a higher thing that mimics something like enet without proper Allegro integration, then it&#39;s a complete waste of time in my opinion.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Wed, 28 Nov 2012 21:05:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><a href="http://libevent.org/">http://libevent.org/</a></p><p>Libevent is a portable way to do networking on all sorts of platforms. It&#39;s BSD licenced, and it has very high performance. Some wrapper functions could be written to inegrate this better with allegro, but I don&#39;t see much need for that. There&#39;s a lot of portable libraries for C out there that need not be integrated in allegro to use them. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (beoran)</author>
		<pubDate>Thu, 29 Nov 2012 01:58:59 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It&#39;d be stupid simple to support BSD Sockets via the fshooks api. Espeically if all you care about is blocking sockets. Some additions would have to be made to support non blocking sockets (ie: add <span class="source-code">al_select</span>, <span class="source-code">ALLEGRO_SOCKET_<span class="k3">*</span>_EVENT</span>, etc). To support host/server type sockets more apis would be needed like <span class="source-code">al_listen</span> and <span class="source-code">al_accept</span>.</p><p>But again, its not a difficult job. If anyone wants to do it, I&#39;d be up for mentoring should they need it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Thu, 29 Nov 2012 02:33:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I was thinking of developing an addon even just for personal use since I do have good experience working with sockets, but I&#39;m not really sure how the internals of allegro are structured and how to actually go about making an addon.</p><p>I normally use RakNet for my larger projects, and I have no trouble linking more than one library, but I do think sockets built into allegro would be handy for some small projects I like to throw together sometimes. RakNet seems also pretty bloated for use on a mobile device, which is primarily what I&#39;ll be aiming at in the next little while.</p><p>Anyway, Maybe I&#39;ll look at some of the other addons and play around with it and write one eventually.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (TrieBr)</author>
		<pubDate>Fri, 30 Nov 2012 05:54:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If you really wanted to do this, you could start with the memfile addon as a base for the sockets addon. It implements a bare fshook driver that you can extend to support sockets.</p><p>Some extra APIs will need to be added, they may need to be hung off the core fshook driver vtables. I think its fairly straight forward, especially if you&#39;re familiar with sockets already.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Fri, 30 Nov 2012 07:11:15 +0000</pubDate>
	</item>
</rss>
