• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
JoshKlint_34394

[Resolved] Simple enet program fails

17 posts in this topic

I am writing a Lua debugger using enet to communicate between processes. The debugger program is written in another language (but uses enet!), and works with a test executable also written in that language.

Now I am trying to add code to my C++ program to make it communicate with the debugger program. I have a simple program like this:
[code] if (enet_initialize()!=0)
{
Print("Failed to initialize enet.");
}
else
{
ENetAddress address;
ENetEvent enetevent;
address.host = ENET_HOST_ANY;
address.port = 7776;
InterpreterDebugHost = enet_host_create(&address,64,0,0);
if (InterpreterDebugHost==NULL)
{
Print("Failed to create host on port "+String(address.port));
}
else
{
Print("Checking for events loop...");
bool exitloop = false;
int time = Millisecs();
while (true)
{
int result = enet_host_service(InterpreterDebugHost,&enetevent,0);
if (result>0)
{
switch (enetevent.type)
{
case ENET_EVENT_TYPE_CONNECT:
Print("Connect");
exitloop=true;
break;
case ENET_EVENT_TYPE_DISCONNECT:
Print("Disconnect");
break;
case ENET_EVENT_TYPE_RECEIVE:
Print("Receive");
break;
case ENET_EVENT_TYPE_NONE:
Print("No event");
break;
}
}
else
{
if (result<0) Print("enet_host_service failed.");
}
if (Millisecs()-time>10000) exitloop = true;
if (exitloop) break;
}
Print("Done with events loop");
}
}
}
[/code]
For some reason, the C++ program never detects any events, even though it is pretty much identical to my other test program not written in C++.
0

Share this post


Link to post
Share on other sites
The code looks fine, you should try to verify that the problem is not on the other side, i.e. the client is not even attempting to connect. Here is my main loop just for your own sanity, which is basically a copy and paste from the enet web site. The below code works, so it has to be something else
[code]
ENetHost* Host=0;
void RunNetwork(uint32_t waittimeinms){
ENetEvent event;
/* Wait up to waittimeinms milliseconds for an event. */
while (enet_host_service (Host, &event, waittimeinms) > 0) {// this will send and receive data
switch (event.type) {
case ENET_EVENT_TYPE_RECEIVE:

Receive(event);
enet_packet_destroy (event.packet); //Clean up the packet now that we're done using it.
break;
case ENET_EVENT_TYPE_CONNECT:

Connect(event);
break;
case ENET_EVENT_TYPE_DISCONNECT:// this can be a timeout, or a regular disconnect
Disconnect(event);
break;
}
}
}
// and my server initi code
void InitServer(){
if(Host) enet_host_destroy(Host); // clean up the exisitng host and continue
ENetAddress address;
address.host = ENET_HOST_ANY;
address.port =port;
Host = enet_host_create (&address, /* create a client host */
20, /* numer of connections */
2, /* number of channels: channel 0 is for normal data, and channel 1 is for encrpyted data */
0, //incomingbandwith
0);//outgoingbandwith
if (Host == NULL){
OUTPUT_DEBUG_MSG("An error occurred while trying to create an ENet Server host.");
return false;
}
}
[/code]
0

Share this post


Link to post
Share on other sites
Why does your enet_host_create() command take five arguments, and mine only takes four? I downloaded enet 1.2.3.

I have verified the other program works. I have another test program not written in C++ that responds when my debugger program attempts to connect.

I also tried doing it the other way, having the test program connect to the debugger. Same results.

My firewall does say the C++ program is trying to connect (and I let it, of course). Could it be a problem with me including a wrong library or something like that? I can't see any reason the code itself would have a problem.

I added these additional libraries in the project settings:
ws2_32.lib
winmm.lib
0

Share this post


Link to post
Share on other sites
I was using two different incompatible versions of enet, but after fixing that problem, behavior is unchanged...
0

Share this post


Link to post
Share on other sites
Test to see if any data is being read in to enet by going to the function enet_protocol_receive_incoming_commands in the protocol.c file and change the function to add some output if any data is read in. This way you can know if any data is even being read.

The latest version of enet is 1.31 so make sure you and the client are using the same versions. Also, if you are building dlls, or lib files and linking them make sure you rebuild them for the appropriate version. I just compile the source in my project, I hate dlls and libs.
0

Share this post


Link to post
Share on other sites
Below are two simple C++ programs based on the tutorial here:
http://enet.bespin.org/Tutorial.html

They never connect! This isn't right.

I also notice if I unplug my network cable, my C++ client program gives this error:
[quote]Error sending outgoing packets: No error[/quote]

My BlitzMax programs, that are importing the exact same .c files (and compiling them with GCC) doesn't have any problem connecting when the network cable is plugged in or unplugged.

Here is the source for my C++ server and client programs:

Server.cpp:
[code]int main()
{
ENetEvent event;
ENetAddress address;
ENetHost* server;

enet_initialize();

address.host = ENET_HOST_ANY;
address.port = 1234;

server = enet_host_create (&address,32,2,0,0);
if (server == NULL)
{
Print("An error occurred while trying to create an ENet server host.");
return 1;
}

int time = Millisecs();
while(true)
{
while (enet_host_service (server, &event,0) > 0)
{
switch (event.type)
{
case ENET_EVENT_TYPE_CONNECT:
printf ("A new client connected from %x:%u.\n",
event.peer -> address.host,
event.peer -> address.port);
event.peer -> data = "Client information";
break;

case ENET_EVENT_TYPE_RECEIVE:
printf ("A packet of length %u containing %s was received from %s on channel %u.\n",
event.packet -> dataLength,
event.packet -> data,
event.peer -> data,
event.channelID);
enet_packet_destroy (event.packet);
break;

case ENET_EVENT_TYPE_DISCONNECT:
printf ("%s disconected.\n", event.peer -> data);
event.peer -> data = NULL;
}
}
if (Millisecs()-time>10000) break;
}
Print("Nothing happened, I give up.");
Delay(3000);
return 0;
}[/code]

Client.cpp:
[code]int main()
{
ENetEvent event;
ENetHost * client;
ENetAddress address;

enet_initialize();

client = enet_host_create (NULL ,
1 ,
2 ,
57600 / 8 ,
14400 / 8 );

if (client == NULL)
{
fprintf (stderr,
"An error occurred while trying to create an ENet client host.\n");
exit (EXIT_FAILURE);
}

//address.host = 2130706433;
address.port = 1234;
enet_address_set_host (&address, "192.168.0.1");
enet_host_connect(client,&address,2,0);

int time = Millisecs();
while (true)
{
while (enet_host_service (client, & event, 0) > 0)
{
switch (event.type)
{
case ENET_EVENT_TYPE_CONNECT:
printf ("A new client connected from %x:%u.\n",
event.peer -> address.host,
event.peer -> address.port);


event.peer -> data = "Client information";

break;

case ENET_EVENT_TYPE_RECEIVE:
printf ("A packet of length %u containing %s was received from %s on channel %u.\n",
event.packet -> dataLength,
event.packet -> data,
event.peer -> data,
event.channelID);


enet_packet_destroy (event.packet);

break;

case ENET_EVENT_TYPE_DISCONNECT:
printf ("%s disconected.\n", event.peer -> data);

event.peer -> data = NULL;
}
}
if (Millisecs()-time>10000) break;
}
Print("Nothing happened, I give up.");
Delay(3000);
return 0;
}[/code]
0

Share this post


Link to post
Share on other sites
192.168.0.1 looks suspicious because routers are setup by default to either 192.168.1.1, or 192.168.2.1 ( i have one of these.. pissed me off). So, are you sure you are trying to connect to the right address? So, the information you provided tells me that you changed your routers internal ip, and also changed its range of given ip addresses.
1

Share this post


Link to post
Share on other sites
Yeah, I switched that ip with "localhost" and it fixed the error. Still doesn't explain why no connection is being made.
0

Share this post


Link to post
Share on other sites
Even more interesting: I removed Lua and Luabind, so I could package up the project and post it here, and now the connection magically works...
0

Share this post


Link to post
Share on other sites
Because of the fact that the connection works when you specify your local lost (127.0.0.1), I really think that you are trying to connect to the wrong address. An address of "192.168.0.1" would be reserved for the address of your router. You should be trying to connect to an address like, 192.168.0.2. Or, if you were on a standard setup, 192.168.1.2, or 192.168.1.3 .... etc
1

Share this post


Link to post
Share on other sites
[quote name='Josh Klint' timestamp='1304312213' post='4805280']
Even more interesting: I removed Lua and Luabind, so I could package up the project and post it here, and now the connection magically works...
[/quote]

Ouch. Are you sure you have made a full recompile of the project? If you insert those libraries again, is the problem reproduced? Can you ping directly via your O/S to the address you are trying to connect to?

Contrary to what the previous poster says, there's nothing wrong with having a zero as the third octet in an IPv4 address. For instance, this is the default on some Netgear routers.
They also do not have to (but usually do in typical setups) reside on the first IP in the range. There's nothing non-standard about this and it likely has nothing to do with your problem.
0

Share this post


Link to post
Share on other sites
The IP address thing is resolved. I just haven't done any network programming for a while, so I forgot the default local address.

I'll do some more testing and figure out exactly what I am including that messes up enet.
0

Share this post


Link to post
Share on other sites
Well, it works fine now after I added everything back in. Maybe my change to the IP address somehow wasn't get recompiled.
0

Share this post


Link to post
Share on other sites
Josh, that is great, but I am curious, you are saying it works using the 192.168.0.1 address? Sorry, I just have to know.

Oh and to SymLinked, thanks for voting down all of my posts, hopefully the moderators can rectify it.
1

Share this post


Link to post
Share on other sites
[quote name='smasherprog' timestamp='1304363254' post='4805602']
Josh, that is great, but I am curious, you are saying it works using the 192.168.0.1 address? Sorry, I just have to know.

Oh and to SymLinked, thanks for voting down all of my posts, hopefully the moderators can rectify it.
[/quote]

Please, no discussing personal issues on the board, or I will have to moderate it. Take it to PM if it matters.

Moderators do not get involved in ratings issues, unless there is some bug with the system. Over time, ratings tend to work themselves out.
0

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  
Followers 0