Click to See Complete Forum and Search --> : Socket( PC to SUN)


tangzibo
July 12th, 1999, 09:44 PM
hi, all,
I want write a common class to transfer structs or classes from PC to SUN thru socket. The problem is the bit order is different. How to do it?
thanks

July 13th, 1999, 01:32 PM
My suggestion is to first make your own socket wrapper class which contains your connect, send, receive, methods. And force
whomever is sending you the data to have it byte ordered before passing it to your send call. They should just pass you a pointer
to a structure, and how many bytes to send. Otherwise unless you have set structures that they can tell you what type of structure
it is and you can do the byte ordering.

deano
July 14th, 1999, 01:50 AM
You'll need to use the host/network conversion functions to convert all of your numeric data before sending it betwen machines. For instance with a long integer use htonl()

(host to network long) to convert it from host to network format. Then at the receiving end use ntohl()

to convert it from network format into the receiving host's format. There are functions for the other numeric types as well.

If you used Berkely sockets then you should be able to write a general socket class that will compile and run on both NT and your UNIX platform - (apart from the WINSOCK initialisation the code should be identical).

Good luck.


Carl

tangzibo
July 14th, 1999, 03:02 AM
Sorry for my poor English. What I mean is write a common socket class to transfer classes. The socker class may be like:

CMySocket
{
...
Send( void*, size_t);
Receive( void*, size_t);
...
};




then, I can use this class like:

CClassA a;
CClassB b;
CMySocket mySocket;
mySocket.Send((void*)&a, sizeof(a));
mySocket.Send((void*)&b, sizeof(b));