How to receive data using dynamic array in recv() api?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<p style="font:inherit; vertical-align:baseline; list-style-type:none; color:#666666; font-family:Segoe UI,Helvetica,Garuda,Arial,sans-serif; line-height:21px
Using ioctlsocket() api, am getting the bytes to read in that socket and based on that, i initialized one dynamic array buffer.
<p style="font:inherit; vertical-align:baseline; list-style-type:none; color:#666666; font-family:Segoe UI,Helvetica,Garuda,Arial,sans-serif; line-height:21px
int li_ret = ioctlsocket(Struct_obj51->ClientSocketId, FIONREAD, &li_BytesAvailable);
<p style="font:inherit; vertical-align:baseline; list-style-type:none; color:#666666; font-family:Segoe UI,Helvetica,Garuda,Arial,sans-serif; line-height:21px
<span style="white-space:pre Struct_obj100->BytesToRead = <span style="color:#666666; font-family:Segoe UI,Helvetica,Garuda,Arial,sans-serif; line-height:21px li_BytesAvailable
;
<p style="font:inherit; vertical-align:baseline; list-style-type:none; color:#666666; font-family:Segoe UI,Helvetica,Garuda,Arial,sans-serif; line-height:21px
char* buffer;
<p style="font:inherit; vertical-align:baseline; list-style-type:none; color:#666666; font-family:Segoe UI,Helvetica,Garuda,Arial,sans-serif; line-height:21px
buffer = new char[Struct_obj100->BytesToRead+1];
<p style="font:inherit; vertical-align:baseline; list-style-type:none; color:#666666; font-family:Segoe UI,Helvetica,Garuda,Arial,sans-serif; line-height:21px
int bytes= recv(Struct_obj100->HostSockID,buffer, Struct_obj100->BytesToRead, 0);
<p style="font:inherit; vertical-align:baseline; list-style-type:none; color:#666666; font-family:Segoe UI,Helvetica,Garuda,Arial,sans-serif; line-height:21px
//////////////////////////////////////////////////////////////
<p style="font:inherit; vertical-align:baseline; list-style-type:none; color:#666666; font-family:Segoe UI,Helvetica,Garuda,Arial,sans-serif; line-height:21px
<span style="color:#333333; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; font-size:13px; line-height:16px Am using ioctlsocket() and recv() in different DLLs. I copied li_BytesAvailable to Struct_obj100->BytesToRead and passed
that structure to another dll , where i will use that in recv api.
<p style="font:inherit; vertical-align:baseline; list-style-type:none; color:#666666; font-family:Segoe UI,Helvetica,Garuda,Arial,sans-serif; line-height:21px
<span style="color:#333333; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; font-size:13px; line-height:16px ///////////////////////////////////////////////////////////////////
<p style="font:inherit; vertical-align:baseline; list-style-type:none; color:#666666; font-family:Segoe UI,Helvetica,Garuda,Arial,sans-serif; line-height:21px
After receiving , recv api returned the exact value in <span style="color:#666666; font-family:Segoe UI,Helvetica,Garuda,Arial,sans-serif; line-height:21px bytes, but the buffer having one data(value present in first index of send buffer).
<p style="font:inherit; vertical-align:baseline; list-style-type:none; color:#666666; font-family:Segoe UI,Helvetica,Garuda,Arial,sans-serif; line-height:21px
Same thing , i did with static array and i can able to receive all bytes of data.
<p style="font:inherit; vertical-align:baseline; list-style-type:none; color:#666666; font-family:Segoe UI,Helvetica,Garuda,Arial,sans-serif; line-height:21px
char temp[1024];<br/>
memset(temp,0,sizeof(temp));<br/>
int li_len = recv(Struct_obj100->HostSockID,temp, Struct_obj100->BytesToRead, 0);
<p style="font:inherit; vertical-align:baseline; list-style-type:none; color:#666666; font-family:Segoe UI,Helvetica,Garuda,Arial,sans-serif; line-height:21px

<p style="font:inherit; vertical-align:baseline; list-style-type:none; color:#666666; font-family:Segoe UI,Helvetica,Garuda,Arial,sans-serif; line-height:21px
<span style="color:#666666; font-family:Segoe UI,Helvetica,Garuda,Arial,sans-serif; font-size:14px; line-height:21px could u plz tell how i can make use of dynamic array allocation and getting data in buffer
<br/>

View the full article
 
Back
Top