[Tux4kids-commits] r1075 - tuxmath/branches/lan/server
akash gangil
gangil-guest at alioth.debian.org
Fri Jun 19 20:15:22 UTC 2009
Author: gangil-guest
Date: 2009-06-19 20:15:21 +0000 (Fri, 19 Jun 2009)
New Revision: 1075
Modified:
tuxmath/branches/lan/server/server.c
tuxmath/branches/lan/server/testclient.c
tuxmath/branches/lan/server/transtruct.h
Log:
Debugged some , still many bugs in there(workin)
Modified: tuxmath/branches/lan/server/server.c
===================================================================
--- tuxmath/branches/lan/server/server.c 2009-06-19 18:34:44 UTC (rev 1074)
+++ tuxmath/branches/lan/server/server.c 2009-06-19 20:15:21 UTC (rev 1075)
@@ -24,7 +24,7 @@
#include "transtruct.h"
#include "mathcards.h"
-
+#define LAN_DEBUG
#define NUM_CLIENTS 16
TCPsocket sd; /* Socket descriptor */
@@ -48,7 +48,7 @@
char buffer[NET_BUF_LEN];
int command_type = -1;
int sockets_used,numready,j;
- static int i=0;
+ static int i=-1;
static int num_clients=0;
// size_t length;
MC_FlashCard flash;
@@ -95,6 +95,9 @@
quit = 0; /*****can say this loop to be the connection manager, which after accepting starts the game*****/
while (!quit)
{
+
+ i++;
+
/* This check the sd if there is a pending connection.
* If there is one, accept that, and open a new socket for communicating */
if (client[i].csd = SDLNet_TCP_Accept(sd))
@@ -115,13 +118,17 @@
}
else
fprintf(stderr, "SDLNet_TCP_GetPeerAddress: %s\n", SDLNet_GetError());
- i++;
+
sockets_used = SDLNet_TCP_AddSocket(client_set,client[i].csd);
if(sockets_used == -1)
{
printf("SDLNet_AddSocket: %s\n", SDLNet_GetError());
// perhaps you need to restart the set and make it bigger...
}
+
+#ifdef LAN_DEBUG
+ printf("%d\n",sockets_used);
+#endif
client[i].flag=1;
}//end of *if(client[i].csd = SDLNet_TCP_Accept(sd))*
//This is supposed to check to see if there is activity:
@@ -136,25 +143,38 @@
{
#ifdef LAN_DEBUG
printf("There are %d sockets with activity!\n", numready);
+ SDL_Delay(2000);
+
#endif
// check all sockets with SDLNet_SocketReady and handle the active ones.
for(j=0;j<=(numready-1);j++)
{
+#ifdef LAN_DEBUG
+ printf("I am here\n");
+ #endif
char buf[NET_BUF_LEN];
- if(SDLNet_SocketReady(client[j].csd))
- {
- buf[0] = '\0';
- SDLNet_TCP_Recv(sd, buf, sizeof(buf));
+ int x;
+ buf[0]='\0';
+// if(SDLNet_SocketReady(client[j].csd))
+// {
+ x=SDLNet_TCP_Recv(client[j].csd, buf, sizeof(buf));
+ if(x<=0) {
+ // An error may have occured, but sometimes you can just ignore it
+ // It may be good to disconnect sock because it is likely invalid now.
+ }
+
+
+
#ifdef LAN_DEBUG
printf("buf is %s\n", buf);
- #endif
+#endif
/* Now we process the buffer according to the command: */
- if(strcmp(buf, "game") == 0)
+ if(strcmp(buf, "set_up_list") == 0)
{
quit=1;
break; //tell the server to stop accepting connections and start the game
}
- }//end of *if*
+// }//end of *if*
}//end of *for* loop
}//end of *else*
} // End of *while(!quit)* loop
Modified: tuxmath/branches/lan/server/testclient.c
===================================================================
--- tuxmath/branches/lan/server/testclient.c 2009-06-19 18:34:44 UTC (rev 1074)
+++ tuxmath/branches/lan/server/testclient.c 2009-06-19 20:15:21 UTC (rev 1075)
@@ -25,6 +25,8 @@
#include "mathcards.h"
#include "testclient.h"
+#define LAN_DEBUG
+
TCPsocket sd; /* Server socket descriptor */
SDLNet_SocketSet set;
@@ -216,6 +218,9 @@
//Tell server to start new game:
snprintf(buf, NET_BUF_LEN, "%s\n", "set_up_list");
+#ifdef LAN_DEBUG
+ printf("%s\n",buf);
+#endif
if (SDLNet_TCP_Send(sd, (void *)buf, NET_BUF_LEN) < NET_BUF_LEN)
{
fprintf(stderr, "SDLNet_TCP_Send: %s\n", SDLNet_GetError());
@@ -238,6 +243,12 @@
numready = 1;
while(numready > 0)
{
+
+
+ SDL_Delay(5000);
+
+
+
char command[NET_BUF_LEN];
int i = 0;
Modified: tuxmath/branches/lan/server/transtruct.h
===================================================================
--- tuxmath/branches/lan/server/transtruct.h 2009-06-19 18:34:44 UTC (rev 1074)
+++ tuxmath/branches/lan/server/transtruct.h 2009-06-19 20:15:21 UTC (rev 1075)
@@ -16,7 +16,7 @@
//#define LAN_DEBUG
#define NET_BUF_LEN 512
-#define DEFAULT_PORT 4778
+#define DEFAULT_PORT 4789
#define MC_USE_NEWARC
#define MC_FORMULA_LEN 40
More information about the Tux4kids-commits
mailing list