[Tux4kids-commits] r1131 - tuxmath/branches/lan/server
akash gangil
gangil-guest at alioth.debian.org
Thu Jul 2 13:15:10 UTC 2009
Author: gangil-guest
Date: 2009-07-02 13:15:07 +0000 (Thu, 02 Jul 2009)
New Revision: 1131
Modified:
tuxmath/branches/lan/server/server.c
tuxmath/branches/lan/server/testclient.c
Log:
trying to deal with crashed clients(unclosed sockets)
Modified: tuxmath/branches/lan/server/server.c
===================================================================
--- tuxmath/branches/lan/server/server.c 2009-07-02 05:03:20 UTC (rev 1130)
+++ tuxmath/branches/lan/server/server.c 2009-07-02 13:15:07 UTC (rev 1131)
@@ -54,7 +54,7 @@
/* "Local globals" for server.c: */
TCPsocket server_sock = NULL; /* Socket descriptor for server */
IPaddress ip;
-SDLNet_SocketSet client_set = NULL;
+SDLNet_SocketSet client_set = NULL,temp_sock=NULL,temp_set=NULL;
static client_type client[MAX_CLIENTS];
static int num_clients = 0;
static int numready = 0;
@@ -194,8 +194,10 @@
TCPsocket temp_sock = NULL; /* Just used when client can't be accepted */
int slot = 0;
int x = 0,j,c=0;
+ static int counter=0;
int sockets_used = 0;
char buffer[NET_BUF_LEN];
+ int numused,num_ready;
if(game_in_progress==1)
{
@@ -203,7 +205,7 @@
{
if(client[j].sock!=NULL)
{
- printf("Client %d is still alive...\n");
+ printf("%s is still connected...\n",client[j].name);
c=1;
break;
}
@@ -215,6 +217,34 @@
printf("ALL the players have been disconnected ... =(\n");
exit(1);
}
+ else
+ {
+ counter++;
+ printf("counter is %d",counter);
+ }
+ if (counter%5==0)
+ {
+ counter=0;
+ ping_client(j);
+ numused=SDLNet_TCP_AddSocket(temp_set,client[j].sock);
+ if(numused==-1)
+ {
+ printf("SDLNet_AddSocket: %s\n", SDLNet_GetError());
+ // perhaps you need to restart the set and make it bigger...
+ }
+ num_ready=SDLNet_CheckSockets(temp_set,0);
+ if(num_ready==-1)
+ {
+ printf("SDLNet_CheckSockets: %s\n", SDLNet_GetError());
+ //most of the time this is a system error, where perror might help you.
+ perror("SDLNet_CheckSockets");
+ }
+ else if(num_ready==0)
+ {
+ remove_client(j);
+ printf(" %s has been disconnected due to no activity\n",client[j].name);
+ }
+ }
}
/* See if we have a pending connection: */
Modified: tuxmath/branches/lan/server/testclient.c
===================================================================
--- tuxmath/branches/lan/server/testclient.c 2009-07-02 05:03:20 UTC (rev 1130)
+++ tuxmath/branches/lan/server/testclient.c 2009-07-02 13:15:07 UTC (rev 1131)
@@ -54,7 +54,7 @@
snprintf(buffer, NET_BUF_LEN,
"%s",
name);
- len = strlen(buffer) + 1;
+
/* Simple parameter checking */
if (argc < 3)
@@ -364,7 +364,7 @@
else
printf("Unable to parse buffer into FlashCard\n");
}
- if(strncmp(command,"PING", 4) == 0)
+ if(strncmp(command,"SEND_MESSAGE", 4) == 0)
{
server_pinged();
}
More information about the Tux4kids-commits
mailing list