|
-
October 11th, 2008, 12:31 PM
#1
sending structure from client to server
Hi ,
I want to send a structure (user defined) for example :
struct bank{
int empid;
char name[50];
float amount;
} per;
I want to send this from a client to server on unix.Can any1 tell me how to send this(from client) and read the data at the other end(at server).tnx in advance...
-
October 11th, 2008, 01:19 PM
#2
Re: sending structure from client to server
Read about CAsyncSocket class.
Here yau have an example:
http://www.codeproject.com/KB/IP/MFCSockets.aspx
Regards
-
October 11th, 2008, 03:18 PM
#3
Re: sending structure from client to server
My method I use for my server pretty simple..
Code:
struct Packet {
unsigend short size;
unsigned char opCode;
char* data;
};
Code:
Packet packet;
fill it up...
...
Code:
int BytesToSend = sizeof(Packet);
const char *pBytesToSend = (const char *)&packet;
while (BytesToSend > 0)
{
int BytesSent = send(socket, pBytesToSend, BytesToSend, 0);
if (BytesSent == SOCKET_ERROR)
{
int SockErr = WSAGetLastError();
if (SockErr != WSAEWOULDBLOCK)
{
// handle errors here
break;
}
BytesSent = 0;
}
pBytesToSend += BytesSent;
BytesToSend -= BytesSent;
}
-
October 13th, 2008, 07:55 AM
#4
Re: sending structure from client to server
 Originally Posted by mvksagar45
Hi ,
I want to send a structure (user defined) for example :
struct bank{
int empid;
char name[50];
float amount;
} per;
I want to send this from a client to server on unix.Can any1 tell me how to send this(from client) and read the data at the other end(at server).tnx in advance...
You need to make sure that the structures are aligned on the same boundaries. By default, I believe VC++ (most versions) pack structures on 64 bit boundaries. You need to be sure the receiving unix server has the same structure alignment or change your alignment to match the server using the #pragma pack directive.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|