Hello frnds,
I have implemented client server arch. wherein I have implemented multithreading on server. This is working perfectly well. But I was unable to check whether really server executes all clients simultaneously since I could not start all clients at exactlt the same time so I tried multithreading on client side as well which is not working properly.
ReqClient is a class which has all methods to send req, send data, receive data..etc
Plz reply as soon as possible...I am stuck since yest.. 1 or 2 threads dont start at all..msgs are sent properly back to client.. I guess malloc() is causing some problems :(
Regards,
Aditi
Code is as follows:
void *createNewClientThread(void *msg) //multithreaded function
{
ReqClient newClient;
int portnum;
const char *ip1, *port1, *SessionCode;
char *filebuffer;
FILE *f;
long lsize;
size_t result;
SessionCode = (char *)msg;
newClient.SendRequest("127.0.0.1",2212); //Sending Request to Session Manager
newClient.SendData(SessionCode, strlen(SessionCode), 0); //Sending CODE to Session Manager
char *buffer = (char *)malloc(255),*addr = (char *)malloc(255);
const char *msgg = "hmm"; //Allocate memory for character pointers
int bytes = newClient.ReceiveData(buffer, 255, 0); //Receive IP Address and PORT from Session Manager
cout<<"Received Data from Session Manager : "<<buffer<<"\n";
strcpy(addr,buffer); //Copy in other pointer so that 'buffer' is not changed ...Remember call by reference
newClient.CloseSocket(); //Close Socket of Client
ip1 = newClient.getIP(addr); //Get IP Address in ip1 pointer
port1 = newClient.getPort(addr); //Get PORT in port1
portnum = atoi(port1); //Convert port1 from ascii to int
newClient.newSocket(); //Initialize new socket
newClient.SendRequest(ip1, portnum); //Send Request to Response Server
bytes = newClient.ReceiveData(buffer, 255, 0); //Receive data from Server
cout<<"Received Data from Response Server : "<<buffer<<"\n";
newClient.SendData(msgg, strlen(msgg), 0); //Send msg to Server
f = fopen("area.txt","rb+"); //Open file to be sent to Server
if(f == NULL)
{
fputs("File error",stderr);
exit(1);
}
/* Get Size of file */
fseek(f,0,SEEK_END);
lsize = ftell(f);
rewind(f);
filebuffer = (char *)malloc(sizeof(char) * (lsize));
if(filebuffer == NULL)
{
fputs("Memory error",stderr);
exit(2);
}
result = fread(filebuffer,sizeof(char),lsize,f); //Read file to be sent
Plz reply as soon as possible...I am stuck since yest.. 1 or 2 threads dont start at all..msgs are sent properly back to client.. I guess malloc() is causing some problems :(