[Tux4kids-commits] r1042 - tuxmath/branches/lan/server
akash gangil
gangil-guest at alioth.debian.org
Sat Jun 13 17:53:00 UTC 2009
Author: gangil-guest
Date: 2009-06-13 17:52:59 +0000 (Sat, 13 Jun 2009)
New Revision: 1042
Modified:
tuxmath/branches/lan/server/server.c
tuxmath/branches/lan/server/testclient.c
Log:
some members of flashcard transferred
Modified: tuxmath/branches/lan/server/server.c
===================================================================
--- tuxmath/branches/lan/server/server.c 2009-06-13 14:38:09 UTC (rev 1041)
+++ tuxmath/branches/lan/server/server.c 2009-06-13 17:52:59 UTC (rev 1042)
@@ -35,6 +35,7 @@
char buffer[512];
char func;
MC_FlashCard* fc;
+ // size_t length;
if (SDLNet_Init() < 0)
@@ -44,7 +45,7 @@
}
/* Resolving the host using NULL make network interface to listen */
- if (SDLNet_ResolveHost(&ip, NULL, 4767) < 0)
+ if (SDLNet_ResolveHost(&ip, NULL, 4778) < 0)
{
fprintf(stderr, "SDLNet_ResolveHost: %s\n", SDLNet_GetError());
exit(EXIT_FAILURE);
@@ -195,27 +196,35 @@
char *ch;
- SDLNet_TCP_Send(csd,fc->formula_string,4);
- SDLNet_TCP_Recv(csd,ch,1); //will send in the next item only when the first one is receive
- if(*ch=='1')
- {
- SDLNet_TCP_Send(csd,fc->answer_string,4);
- SDLNet_TCP_Recv(csd,ch,1);
- if(*ch=='1')
- {
- SDLNet_TCP_Send(csd,&(fc->answer),4);
- SDLNet_TCP_Recv(csd,ch,1);
- if(*ch=='1')
- {
- SDLNet_TCP_Send(csd,&(fc->difficulty),4);
- SDLNet_TCP_Recv(csd,ch,1);
- if(*ch=='1')
- {
- return 0;
- }
- }
- }
- }
+ SDLNet_TCP_Send(csd,fc->formula_string,strlen(fc->formula_string));
+
+ printf("%d\n",strlen(fc->formula_string));
+// SDLNet_TCP_Recv(csd,ch,1); //will send in the next item only when the first one is receive
+// if(*ch=='1')
+// {
+ SDLNet_TCP_Send(csd,fc->answer_string,strlen(fc->answer_string));
+
+ printf("%d\n",strlen(fc->answer_string));
+// SDLNet_TCP_Recv(csd,ch,1);
+// if(*ch=='1')
+// {
+ SDLNet_TCP_Send(csd,&(fc->answer),sizeof(fc->answer));
+
+ printf("%d\n",sizeof(fc->answer));
+// SDLNet_TCP_Recv(csd,ch,1);
+// if(*ch=='1')
+// {
+ SDLNet_TCP_Send(csd,&(fc->difficulty),sizeof(fc->difficulty));
+ printf("%d\n",sizeof(fc->difficulty));
+
+// SDLNet_TCP_Recv(csd,ch,1);
+// if(*ch=='1')
+// {
+// return 0;
+// }
+// }
+// }
+// }
return 1;
}
Modified: tuxmath/branches/lan/server/testclient.c
===================================================================
--- tuxmath/branches/lan/server/testclient.c 2009-06-13 14:38:09 UTC (rev 1041)
+++ tuxmath/branches/lan/server/testclient.c 2009-06-13 17:52:59 UTC (rev 1042)
@@ -22,6 +22,8 @@
#include "SDL_net.h"
#include "transtruct.h"
+#include "mathcards.h"
+#include "mathcards.c"
TCPsocket sd; /* Socket descriptor */
@@ -31,10 +33,7 @@
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)
{
@@ -77,6 +76,25 @@
}
if(strcmp(buffer,"b")==0)
{
+ fc = (MC_FlashCard *)malloc(sizeof(MC_FlashCard));
+
+ if (fc == NULL)
+ {
+ printf("Allocation of comets failed");
+ return 0;
+ }
+
+ else
+ {
+ *fc = MC_AllocateFlashcard();
+ if (!MC_FlashCardGood(fc) )
+ {
+ //something's wrong
+ printf("Allocation of flashcard failed\n");
+ MC_FreeFlashcard(fc);
+ return 0;
+ }
+ }
if(!RecvQuestion(fc))
printf("unable to recv question\n");
}
@@ -98,16 +116,29 @@
char *ch="1";
- SDLNet_TCP_Recv(sd,fc->formula_string,4);
+ SDLNet_TCP_Recv(sd,fc->formula_string,strlen(fc->formula_string)+1);
+
+ printf("%d\n",strlen(fc->formula_string));
printf("RECEIVED >> %s\n",fc->formula_string);
- 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);
+// SDLNet_TCP_Send(sd,ch,1); // send a conformation that the 1st item has been received
+ SDLNet_TCP_Recv(sd,fc->answer_string,strlen(fc->answer_string)+1);
+ printf("%d\n",strlen(fc->answer_string));
+ printf("RECEIVED >> %s\n",fc->answer_string);
+// SDLNet_TCP_Send(sd,ch,1);
+ SDLNet_TCP_Recv(sd,&(fc->answer),sizeof(fc->answer));
+
+ printf("%d\n",sizeof(fc->answer));
+ printf("RECEIVED >> %d\n",fc->answer);
+// SDLNet_TCP_Send(sd,ch,1);
+ SDLNet_TCP_Recv(sd,&(fc->difficulty),sizeof(fc->difficulty));
+ printf("%d\n",sizeof(fc->difficulty));
+ printf("RECEIVED >> %d\n",fc->difficulty);
+// SDLNet_TCP_Send(sd,ch,1);
+
return 1;
}
+
+
+
More information about the Tux4kids-commits
mailing list