Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Thread and Socket.

Status
Not open for further replies.

kathyayini

Programmer
Aug 16, 2002
52
IN
Hi,
I called "TP_CALL" function in a thread which will send the data on the particular port to server and should receive the data. Currently the program sends the data properly but is not waiting till the data comes back (recv()). and the thread terminates.
Please help me out.

void* TP_CALL(void* data)
{
int bytesSent;
int condition = 0;
int i=0;

memset(&sd, '\0', sizeof(sd));
memset(cSendBuf, '\0', 2000);
strcpy(cSendBuf,"");

for (i=0; i<((struct sdata*) (data))->ibytes; i++)
{
if(((struct sdata*) (data))->cmsg < ' ') printf("."); else printf("%c", ((struct sdata*) (data))->cmsg);
}

bytesSent=send(((struct sdata*) (data))->sock_id,((struct sdata*) (data))->cmsg,((struct sdata*) (data))->ibytes,0);

int z=recv(((struct sdata*) (data))->sock_id,cSendBuf,MESSAGE_LENGTH,MSG_NOSIGNAL);

memcpy(&sd,cSendBuf,z);
for (i=0; i<z; i++)
{
if(sd.cstrmsg < ' ') printf("."); else printf("%c", sd.cstrmsg);
}
}

waiting for the reply.

 
1. Please use the [ignore]
Code:
[/ignore]
tags when posting code.

2. Remove all of those casts, by declaring a suitable local variable.
Code:
void* TP_CALL(void* ptr)
{
        struct sdata *data = ptr;
        int bytesSent;
        int condition = 0;
        int i=0;

        memset(&sd, '\0', sizeof(sd));
        memset(cSendBuf, '\0', 2000);
        strcpy(cSendBuf,"");

        for (i=0; i<data->ibytes; i++)

3. What value is z after this call?
Code:
int z=recv(data->sock_id,cSendBuf,MESSAGE_LENGTH,MSG_NOSIGNAL);
Knowing the status result would help in figuring out why it's not working.

--
 
Upto "bytesSent" it gets printed after that nothing is getting printed.

 
I mean
Code:
int z=recv(data->sock_id,cSendBuf,MESSAGE_LENGTH,MSG_NOSIGNAL);
printf( "recv returned status=%d\n", z );

--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top