[Tux4kids-commits] r1039 - tuxmath/branches/lan/server

akash gangil gangil-guest at alioth.debian.org
Fri Jun 12 23:01:13 UTC 2009


Author: gangil-guest
Date: 2009-06-12 23:01:12 +0000 (Fri, 12 Jun 2009)
New Revision: 1039

Modified:
   tuxmath/branches/lan/server/server.c
   tuxmath/branches/lan/server/testclient.c
Log:
setting up list , chatting , but segfaults on transfer of ques.

Modified: tuxmath/branches/lan/server/server.c
===================================================================
--- tuxmath/branches/lan/server/server.c	2009-06-12 20:33:49 UTC (rev 1038)
+++ tuxmath/branches/lan/server/server.c	2009-06-12 23:01:12 UTC (rev 1039)
@@ -35,6 +35,10 @@
         char buffer[512];
         char func;
         MC_FlashCard* fc;
+
+        fc = malloc(sizeof(MC_FlashCard));
+        fc->answer_string="";
+        fc->formula_string="";
  
         if (SDLNet_Init() < 0)
         {
@@ -43,7 +47,7 @@
         }
  
         /* Resolving the host using NULL make network interface to listen */
-        if (SDLNet_ResolveHost(&ip, NULL, 2740) < 0)
+        if (SDLNet_ResolveHost(&ip, NULL, 2950) < 0)
         {
                 fprintf(stderr, "SDLNet_ResolveHost: %s\n", SDLNet_GetError());
                 exit(EXIT_FAILURE);
@@ -77,6 +81,7 @@
                         quit2 = 0;
                         while (!quit2)
                         {
+                                func='\0';
                                 if (SDLNet_TCP_Recv(csd, buffer, 512) > 0)
                                 {
                                         printf("Client say: %s\n", buffer);
@@ -97,26 +102,33 @@
  
 					{
 						case '1':                                                //mainly to setup the question list
-                                                 if (!MC_StartGame())
-						  {
+                                                 
+                                                 {
+                                                   if (!MC_StartGame())
+						   {
 						    
-						    fprintf(stderr, "\nMC_StartGame() failed!");
-						    return 0;
-						  } 
-  
-						case '2':
+						     fprintf(stderr, "\nMC_StartGame() failed!");
+						     return 0;
+						   }                                                                                  
+                                                 
+                                                   break;                                           
+                                                 } 
+						
+                                                case '2':
                                                   
                                                   {
-                                                   if (!MC_NextQuestion(fc))
-                                                   { 
-                                                     /* no more questions available - cannot create comet.  */
-                                                     return 0;
-                                                   }
+                                                    if (!MC_NextQuestion(fc))
+                                                    { 
+                                                      /* no more questions available - cannot create comet.  */
+                                                      return 0;
+                                                    }
                                                      
-                                            //      if(!SendQuestion(fc))
-                                            //       {
-      				            //          printf("Unable to send Question\n");
-     				//		     }
+                                                    if(!SendQuestion(fc))
+                                                    {
+      				                       printf("Unable to send Question\n");
+     			                            }
+                                                  
+                                                    break;
                                                   }					
 					}
 
@@ -148,8 +160,9 @@
 }
 
 
-/*                 ********workin on this now*******
-int SendQuestion(MC_FlashCard* fc)                           //function to send a flashcard from the server to the client
+
+
+int SendQuestion(MC_FlashCard* fc)                           //function to send a flashcard(question) from the server to the client
 {
       char *ch;
 
@@ -173,13 +186,14 @@
 	       return 0;
               }
             }
-       }
-    return 1;
+        }
+      }
+      return 1;
 
 }
-*/
 
 
 
 
 
+

Modified: tuxmath/branches/lan/server/testclient.c
===================================================================
--- tuxmath/branches/lan/server/testclient.c	2009-06-12 20:33:49 UTC (rev 1038)
+++ tuxmath/branches/lan/server/testclient.c	2009-06-12 23:01:12 UTC (rev 1039)
@@ -23,13 +23,17 @@
 #include "SDL_net.h"
 #include "transtruct.h"
 
+TCPsocket sd;           /* Socket descriptor */
+
 int main(int argc, char **argv)
 {
         IPaddress ip;           /* Server address */
-        TCPsocket sd;           /* Socket descriptor */
         int quit, len;
         char buffer[512];
         MC_FlashCard* fc;
+        fc = malloc(sizeof(MC_FlashCard));
+        fc->answer_string="";
+        fc->formula_string="";
      
         /* Simple parameter checking */
         if (argc < 3)
@@ -71,11 +75,11 @@
                         fprintf(stderr, "SDLNet_TCP_Send: %s\n", SDLNet_GetError());
                         exit(EXIT_FAILURE);
                 }
-               /* if(strcmp(buffer,"b")==0)
+                if(strcmp(buffer,"b")==0)
 		{ 
-                 if(!ReceiveQuestion(fc))
+                 if(!RecvQuestion(fc))
                  printf("unable to recv question\n"); 
-                } */ 
+                }  
 
                 if(strcmp(buffer, "exit") == 0)
                         quit = 1;
@@ -88,3 +92,21 @@
  
         return EXIT_SUCCESS;
 }
+
+int RecvQuestion(MC_FlashCard* fc)                           //function to receive a flashcard(question) by the client
+{
+      char *ch="1";
+
+
+        SDLNet_TCP_Recv(sd,fc->formula_string,4);
+	SDLNet_TCP_Send(sd,ch,1); 		                  // send a conformation that the 1st item has been received				
+	SDLNet_TCP_Recv(sd,fc->answer_string,4);
+        SDLNet_TCP_Send(sd,ch,1);
+        SDLNet_TCP_Recv(sd,&(fc->answer),4);
+        SDLNet_TCP_Send(sd,ch,1);
+        SDLNet_TCP_Recv(sd,&(fc->difficulty),4);
+        SDLNet_TCP_Send(sd,ch,1);
+       
+       return 1;
+}
+ 




More information about the Tux4kids-commits mailing list