Ben or Random_Helpful_Person,
Using the plugin with DarkGDK.
Meh, so what am I doing wrong here? I did up a quick server and simply added a NetConnect( ) command to the entry of one of my pieces of source code. The server picks up the connection, then after about 30 seconds... it crashes. The error code is literally for app_crash. No info on the debugger or anything.
Hosting from the same computer I'm running the client from. I've tried using 127.0.0.1 and my computer's actual wireless ip address. Running wireless over a Linksys WRT54G V5.1 with DD-WRT blown on. I have Win7 Pro x64. Need anything else just let me know.
So here's the source for the server:
#include "DarkGDK.h"
#include "MultiSYNC.h"
#include <cstring>
using namespace std;
struct player_struct {
int slot_used;
char client_id[255];
char client_wel_msg[255];
} player[9999];
// the main entry point for the application is this function
void DarkGDK ( void )
{
dbSyncOn ( );
dbSyncRate ( 60 );
int max_pla = 9999, player_id_bin, player_id[50], i;
bool arf;
arf = NetHost ( max_pla );
if ( arf == 0 ) {
dbPrint ( "Connection failed! Press any key to exit." );
dbWaitKey ( );
return;
}
dbPrint ( "Connection success!" );
// our main loop
while ( LoopGDK ( ) )
{
dbCLS ( );
dbText ( 0, 0, "Listening for Clients." );
dbText ( 0, 10, "Clients connected: " );
dbText ( dbTextWidth ( "Clients connected: " ), 10, dbStr ( NetGetPlayerAmount ( ) ) );
// listen for joins
player_id_bin = NetPlayerJoined ( );
if ( player_id_bin > 0 ){
for ( i = 0; i < 9999; i++ ){
if ( player[i].slot_used = 0 ){
strcpy ( player[i].client_id, dbStr ( player_id_bin ) );
strcpy ( player[i].client_wel_msg, strcat ( "Player ", player[i].client_id ) );
strcpy ( player[i].client_wel_msg, strcat ( player[i].client_wel_msg, " has joined the server." ) );
dbText ( 0, 30, player[i].client_wel_msg );
player[i].slot_used = 1;
i = 10000;
break;
}
}
dbPrint ( player[i].client_wel_msg );
}
player_id_bin = NetPlayerLeft ( );
if ( player_id_bin > 0 ){
for ( i = 0; 1 < 9999; i++ ){
if ( player[i].slot_used > 0 ){
if ( player[i].client_id == dbLeft ( player[i].client_id, dbLen ( dbStr ( player_id_bin ) ) ) ){
strcpy ( player[i].client_wel_msg, "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" );
strcpy ( player[i].client_id, "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" );
player[i].slot_used = 0;
}
}
}
}
dbSync ( );
}
NetDisconnect ( );
// return back to windows
return;
}
BTW, love the concept. Are you planning on adding support for UDP?
Edit: Okay, so I know I posted this on April 1st... but it wasn't an April Fools joke. Was just noticing that.
Edit/Fix

: Wow, so I completely didn't see this:
player_id_bin = NetPlayerLeft ( );
if ( player_id_bin > 0 ){
for ( i = 0; 1 < 9999; i++ ){
There might have been sort of an infinite loop problem occurring. Why the debugger didn't catch it is beyond me... but I found it at least. Server is 100% stable now. In fact, now it's just my client that's crashing. Gonna go have fun finding out why.
The question about UDP still stands though.
Update:
The client is crashing after I lock then unlock my computer. I also found out the connection will time out and disconnect the client after 30 seconds (oh hey look!) so I added a line to send up a 1 byte char (Z) every loop. Gonna let this post die. Its gotten kind of big. Sorry about that.
Here's the C++ source for all those requesting it. You'll notice the char consts at the beginning. I just kind of left them there to give people ideas. If you don't need them you know what to do.
Server:
// Dark GDK - The Game Creators - www.thegamecreators.com
// the wizard has created a very simple project that uses Dark GDK
// it contains the basic code for a GDK application
// whenever using Dark GDK you must ensure you include the header file
#include "DarkGDK.h"
#include "MultiSYNC.h"
#include <cstring>
using namespace std;
// structure to hold the client data
struct player_struct {
int slot_used;
char client_id[255];
} player[9999];
// the main entry point for the application is this function
void DarkGDK ( void )
{
dbSyncOn ( );
dbSyncRate ( 60 );
int max_pla = 9999, player_id_bin, player_id[50], i;
bool arf, msg_flag;
unsigned char INSTRUCTIONS_;
// initiate the connection
arf = NetHost ( max_pla );
// return to windows on failure
if ( arf == 0 ){
dbPrint ( "Connection failed! Press any key to exit." );
dbWaitKey ( );
return;
}
dbPrint ( "Connection success!" );
// our main loop
while ( LoopGDK ( ) )
{
dbCLS ( );
dbText ( 0, 0, "Listening for Clients." );
dbText ( 0, 10, "Clients connected: " );
// I know this is dirty... but its been a while
dbText ( dbTextWidth ( "Clients connected: " ), 10, dbStr ( NetGetPlayerAmount ( ) ) );
// listen for joins
player_id_bin = NetPlayerJoined ( );
if ( player_id_bin > 0 ){
for ( i = 0; i < 9999; i++ ){
if ( player[i].slot_used = 0 ){
// store their client id
strcpy ( player[i].client_id, dbStr ( player_id_bin ) );
// change the client's slot to 1 for used
player[i].slot_used = 1;
// break the for loop
i = 10000;
}
}
}
// listen for disconnects
player_id_bin = NetPlayerLeft ( );
if ( player_id_bin > 0 ){
for ( i = 0; i < 9999; i++ ){
if ( player[i].slot_used > 0 ){
if ( player[i].client_id == dbLeft ( player[i].client_id, dbLen ( dbStr ( player_id_bin ) ) ) ){
// write zeros to their client id just to tidy up
strcpy ( player[i].client_id, "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" );
// change the client's slot to 0 for unused
player[i].slot_used = 0;
// break the for loop
i=10000;
}
}
}
}
// get any incomming messages
msg_flag = NetGetMessage ( );
if ( msg_flag = 1 ){
// always call this first to find out what kind of data will follow
INSTRUCTIONS_ = NetGetByte ( );
switch ( INSTRUCTIONS_ ){
// dump this as its only a keep-alive packet
case 'Z':
break;
// not really sure if this'll EVER happen, but I'm including it anyway
default:
break;
}
}
dbSync ( );
}
// stop the connection and kick everyone off
NetDisconnect ( );
// return back to windows
return;
}
Client:
// Dark GDK - The Game Creators - www.thegamecreators.com
// the wizard has created a very simple project that uses Dark GDK
// it contains the basic code for a GDK application
// whenever using Dark GDK you must ensure you include the header file
#include "DarkGDK.h"
#include "MultiSYNC.h"
// these will always be the FIRST message sent
const unsigned char STRING_ = 'S', INT_ = 'I', FLOAT_ = 'F', MEMBLOCK_ = 'M', BYTE_ = 'B', WORD_ = 'W', LONG_ = 'L', KEEP_ = 'Z';
// these will tell the server what the data will
// be for and will always be te SECOND peice of
// info sent
/*
POS_ = float x, float y, float z
MSG_ = string cString ( max size TBD )
*/
// these are constant variables
const unsigned char POS_ = 'P', MSG_ = 'M';
// this will be the THIRD message sent it is
// your client id (need to set up an id_get
// ip_get etc
//
// these are global variables
unsigned char MY_ID_, MY_IP_;
// the main entry point for the application is this function
void DarkGDK ( void )
{
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn ( );
dbSyncRate ( 60 );
int i, arf;
// initiate the connection
dbText ( 0, 0, "Attempting to connect to server at 127.0.0.1 ..." );
arf = NetConnect ( "127.0.0.1" );
// return to windows on failure
if ( arf == 0 ){
dbCLS ( );
dbPrint ( "Could not connect to server! Press any key to continue." );
dbWaitKey ( );
return;
}
// our main loop
while ( LoopGDK ( ) )
{
dbCLS ( );
dbText ( 0, 0, "Connected to server at 127.0.0.1" );
// send a 1 byte packet every loop to keep the connection open
NetPutByte ( KEEP_ );
NetSend ( 0 );
// update the screen
dbSync ( );
}
// close the connection to the server
NetDisconnect ( );
// return back to windows
return;
}