[Tux4kids-commits] r1111 - tuxmath/branches/lan/server
akash gangil
gangil-guest at alioth.debian.org
Mon Jun 29 18:57:03 UTC 2009
Author: gangil-guest
Date: 2009-06-29 18:57:02 +0000 (Mon, 29 Jun 2009)
New Revision: 1111
Modified:
tuxmath/branches/lan/server/server.c
tuxmath/branches/lan/server/testclient.c
Log:
solved the connection problem
Modified: tuxmath/branches/lan/server/server.c
===================================================================
--- tuxmath/branches/lan/server/server.c 2009-06-29 17:53:08 UTC (rev 1110)
+++ tuxmath/branches/lan/server/server.c 2009-06-29 18:57:02 UTC (rev 1111)
@@ -152,7 +152,7 @@
else if(numready)
{
#ifdef LAN_DEBUG
- printf("There are %d sockets with activity!\n", numready);
+// printf("There are %d sockets with activity!\n", numready);
#endif
// check all sockets with SDLNet_SocketReady and handle the active ones.
@@ -595,6 +595,8 @@
strncpy(client[slot].name, buffer, NAME_SIZE);
num_clients = sockets_used;
printf(" JOINED ::: %s\n", client[slot].name);
+// client[slot].game_ready=1;
+ printf("slot %d is %d\n",slot,client[slot].game_ready);
//FIXME AFAICT, num_clients and i are always the same /* ya they are same , but would have to check for it*/
}
/* Now we can communicate with the client using client[i].sock socket
@@ -623,7 +625,7 @@
}
-//Returns the index of the first vacant client, or -1 if all clients full)
+//Returns the index of the first vacant client, or -1 if all clients full
int find_vacant_client(void)
{
int i = 0;
Modified: tuxmath/branches/lan/server/testclient.c
===================================================================
--- tuxmath/branches/lan/server/testclient.c 2009-06-29 17:53:08 UTC (rev 1110)
+++ tuxmath/branches/lan/server/testclient.c 2009-06-29 18:57:02 UTC (rev 1111)
@@ -42,6 +42,16 @@
char buf[NET_BUF_LEN]; // for network messages from server
char buffer[NET_BUF_LEN]; // for command-line input
+ /* first just take in the name */
+ char *check1;
+ char name[NAME_SIZE];
+ printf("Enter your Name.\n");
+ check1=fgets(buffer,NET_BUF_LEN,stdin);
+ strncpy(name,check1,strlen(check1));
+ snprintf(buffer, NET_BUF_LEN,
+ "%s",
+ name);
+ len = strlen(buffer) + 1;
/* Simple parameter checking */
if (argc < 3)
@@ -91,6 +101,19 @@
while (!quit)
{
//Get user input from command line and send it to server:
+
+
+ if (SDLNet_TCP_Send(sd, (void *)buffer, NET_BUF_LEN) < NET_BUF_LEN)
+ {
+ fprintf(stderr, "SDLNet_TCP_Send: %s\n", SDLNet_GetError());
+ exit(EXIT_FAILURE);
+ }
+#ifdef LAN_DEBUG
+ printf("Sent the name of the player %s\n",check1);
+#endif
+
+
+ /*now display the options*/
printf("Welcome to the Tux Math Test Client!\n");
printf("Type:\n"
"'game' to start math game;\n"
@@ -112,23 +135,6 @@
}
else if (strncmp(buffer, "game",4) == 0)
{
- char name[NAME_SIZE];
- printf("Enter your Name.\n");
- check=fgets(buffer,NET_BUF_LEN,stdin);
- strncpy(name,check,strlen(check));
- snprintf(buffer, NET_BUF_LEN,
- "%s",
- name);
- len = strlen(buffer) + 1;
- if (SDLNet_TCP_Send(sd, (void *)buffer, NET_BUF_LEN) < NET_BUF_LEN)
- {
- fprintf(stderr, "SDLNet_TCP_Send: %s\n", SDLNet_GetError());
- exit(EXIT_FAILURE);
- }
-#ifdef LAN_DEBUG
- printf("Sent the name of the player %s\n",check);
-#endif
-
printf("Starting math game:\n");
playgame();
printf("Math game finished.\n");
@@ -228,27 +234,27 @@
int len = 0;
char buf[NET_BUF_LEN];
char buffer[NET_BUF_LEN];
+ char ch;
#ifdef LAN_DEBUG
printf("Entering playgame()\n");
#endif
-
- snprintf(buffer, NET_BUF_LEN,
+
+ snprintf(buffer, NET_BUF_LEN,
"%s\n",
"start");
- len = strlen(buffer) + 1;
- if (SDLNet_TCP_Send(sd, (void *)buffer, NET_BUF_LEN) < NET_BUF_LEN)
- {
- fprintf(stderr, "SDLNet_TCP_Send: %s\n", SDLNet_GetError());
- exit(EXIT_FAILURE);
- }
-#ifdef LAN_DEBUG
- printf("Sent the game notification %s\n",buffer);
-#endif
+ len = strlen(buffer) + 1;
+ if (SDLNet_TCP_Send(sd, (void *)buffer, NET_BUF_LEN) < NET_BUF_LEN)
+ {
+ fprintf(stderr, "SDLNet_TCP_Send: %s\n", SDLNet_GetError());
+ exit(EXIT_FAILURE);
+ }
+ #ifdef LAN_DEBUG
+ printf("Sent the game notification %s\n",buffer);
+ #endif
+
-
-
if( SDLNet_TCP_Recv(sd, buf, sizeof(buf)))
{
if(strncmp(buf,"Sorry",5) == 0)
@@ -294,7 +300,7 @@
else
{
#ifdef LAN_DEBUG
- printf("There are %d sockets with activity!\n", numready);
+// printf("There are %d sockets with activity!\n", numready);
#endif
// check all sockets with SDLNet_SocketReady and handle the active ones.
if(SDLNet_SocketReady(sd))
More information about the Tux4kids-commits
mailing list