Seems like i had trouble with really high wait times for enet_host_service. This may not be the problem but try changing your server code to<br>enet_host_service( enethost, &event, 10 ) instead of 10000<br><br><br><div>
<span class="gmail_quote">On 12/13/07, <b class="gmail_sendername">Shawn Yarbrough</b> <<a href="mailto:shawnyar217@yahoo.com">shawnyar217@yahoo.com</a>> wrote:</span><blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div style="font-family:courier,monaco,monospace,sans-serif;font-size:12pt"><div>Hi,<br><br>This is my first try with ENet, enet-1.1 stable release, on Linux.<br><br>My client-server ENet test programs aren't working as expected. The client connects to the server and sees a connection event, but the server never sees the connection event.
<br><br>I've included sample runs and code below. If I'm doing something boneheaded, I was hoping somebody could point out my mistake.<br><br>Also I was looking thru the ENet source code trying to understand it. It looks like the UNIX accept() function is never called, or actually it is called by enet_socket_accept(), but then enet_socket_accept() is never called. I assume I'm missing something. I'm not supposed to call the ENet socket functions myself, am I? The tutorial doesn't mention them at
all.<br><br>Regards,<br><br>Shawn Yarbrough<br><br><br><br><br><br><br>$ ./enet_server<br>listening on: [<a href="http://0.0.0.0:1234" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">0.0.0.0:1234</a>
]<br>accepting<br>accepting<br><span style="font-style:italic">(NOTE: here is where ./enet_client was run!)</span><br>accepting<br>accepting<br>accepting<br>accepting<br>event:<br>unexpected event type: 0<br>accepting<br>
<br><br>$ ./enet_client<br>
connecting to: [<a href="http://127.0.0.1:1234" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">127.0.0.1:1234</a>]<br>
connecting<br>
connected to: [<a href="http://127.0.0.1:1234" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">127.0.0.1:1234</a>]<br>
<br>
<br><br><br><br>// enet_client.cpp<br><br>#include <iostream><br>#include <sstream><br>#include <unistd.h><br>#include "enet/enet.h"<br><br>bool enet_initialized = false;<br>::ENetHost *enethost;
<br><br>void<br>check_enet_initialized()<br>{<br> // ENet initialization.<br> if( !enet_initialized )<br> {<br> if( ::enet_initialize() != 0 )<br> throw "failed to initialize ENet";<br>
enet_initialized = true;<br> atexit( ::enet_deinitialize );<br> }<br>}<br><br>void<br>connect_enet()<br>{<br> check_enet_initialized();<br><br> // Initiate the ENet connection.<br> enethost = ::enet_host_create(
NULL, // don't bind as a server<br> 2, // one connection, only<br> 0, // default incoming bandwidth<br> 0 ); // default outgoing bandwidth
<br> if(
enethost == NULL )<br> throw "failed to open ENet connection";<br><br> ::ENetAddress remote_address;<br> ::enet_address_set_host( &remote_address, "<a href="http://127.0.0.1" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
127.0.0.1</a>" );<br> remote_address.port = 1234;<br><br> ::ENetPeer *enetpeer;<br> enetpeer = ::enet_host_connect( enethost, &remote_address, 2 );<br> if( enetpeer == NULL )<br> {<br> ::enet_host_destroy( enethost );
<br> throw "no available ENet peers";<br> }<br> char buf[256];<br> ::enet_address_get_host_ip( &remote_address, buf, sizeof(buf) );<br> std::cout << "connecting to: "<br> << "["
<< buf << ":" << remote_address.port << "]"<br> << std::endl;<br><br><br> ////<br> ENetEvent event;<br>doconnect:<br> std::cout << "connecting"
<br> << std::endl;<br> while( ::enet_host_service( enethost, &event, 1000 ) > 0 )<br> {<br> switch( event.type )<br> {<br> case ENET_EVENT_TYPE_CONNECT:<br> {
<br> char
buf[256];<br> ::enet_address_get_host_ip( &event.peer->address, buf, sizeof(buf) );<br><br> std::stringstream ss;<br> ss << buf<br> << ":"
<br> << event.peer->address.port;<br> std::cout << "connected to:
"<br> << "[" << ss.str() << "]"<br> << std::endl;<br> event.peer->data = new std::string(ss.str());<br>
goto connected;<br> }<br> case ENET_EVENT_TYPE_DISCONNECT:<br> {<br>
throw "unexpected disconnection received on connecting socket";<br> }<br> case ENET_EVENT_TYPE_RECEIVE:<br> {<br> throw "unexpected data packet received on connecting socket";
<br> }<br> }<br> }<br> goto doconnect;<br> ////<br><br>connected:;<br>}<br><br>int<br>main( int argc, char *argv[] )<br>{<br> connect_enet();<br> return 0;<br>}<br><br><br>// enet_server.cpp
<br><br>#include <iostream><br>#include <sstream><br>#include <unistd.h><br>#include
"enet/enet.h"<br><br>bool enet_initialized = false;<br>::ENetHost *enethost;<br><br>void<br>check_enet_initialized()<br>{<br> // ENet initialization.<br> if( !enet_initialized )<br> {<br> if( ::enet_initialize() != 0 )
<br> throw "failed to initialize ENet";<br> enet_initialized = true;<br> atexit( ::enet_deinitialize );<br> }<br>}<br><br>void<br>listen_enet()<br>{<br> check_enet_initialized();<br>
<br> // Initiate the ENet connection.<br> ::ENetAddress local_address;<br> local_address.host = ENET_HOST_ANY;<br> local_address.port = 1234;<br><br> enethost = ::enet_host_create(
&local_address, // bind as a server<br> 32, // max number of connections allowed<br> 0, // default incoming
bandwidth<br> 0 ); // default outgoing bandwidth<br> if( enethost == NULL )<br> throw "failed to open ENet connection";<br><br> char buf[256];<br>
::enet_address_get_host_ip( &local_address, buf, sizeof(buf) );<br> std::cout << "listening on: "<br> << "[" << buf << ":" << local_address.port << "]"
<br> <<
std::endl;<br>}<br><br>void<br>accept_enet()<br>{<br> ENetEvent event;<br>doaccept:<br> std::cout << "accepting"<br> << std::endl;<br> while( ::enet_host_service( enethost, &event, 10000 ) > 0 )
<br> {<br> std::cout << "event:" << std::endl;<br> switch( event.type )<br> {<br> case ENET_EVENT_TYPE_CONNECT:<br> {<br> char buf[256];<br>
::enet_address_get_host_ip( &event.peer->address, buf, sizeof(buf) );<br><br> std::stringstream ss;<br> ss << buf<br> << ":"<br> <<
event.peer->address.port;<br> std::cout << "connection from: "<br> << "[" << ss.str() <<
"]"<br> << std::endl;<br> event.peer->data = new std::string(ss.str());<br> return;<br> }<br> case ENET_EVENT_TYPE_DISCONNECT:
<br> {<br> throw "unexpected disconnection received on listen socket";<br> }<br>
case ENET_EVENT_TYPE_RECEIVE:<br> {<br> throw "unexpected data packet received on listen socket";<br> }<br> default: std::cout << "unexpected event type: " <<
event.type << std::endl;<br> }<br> }<br> goto doaccept;<br>}<br><br>int<br>main( int argc, char *argv[] )<br>{<br> listen_enet();<br> accept_enet();<br> return 0;<br>}<br><span class="ad"><br></span>
</div></div><span class="ad"><br>
<hr size="1">Looking for last minute shopping deals? <a href="http://us.rd.yahoo.com/evt=51734/*http://tools.search.yahoo.com/newsearch/category.php?category=shopping" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
Find them fast with Yahoo! Search.</a></span></div><br>_______________________________________________<br>ENet-discuss mailing list<br><a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:ENet-discuss@cubik.org">
ENet-discuss@cubik.org</a><br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://lists.cubik.org/mailman/listinfo/enet-discuss" target="_blank">http://lists.cubik.org/mailman/listinfo/enet-discuss</a><br>
<br></blockquote></div><br>