CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 1999
    Posts
    37

    Socket( PC to SUN)

    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


  2. #2
    Guest

    Re: Socket( PC to SUN)

    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.


  3. #3
    Join Date
    Jul 1999
    Location
    UK
    Posts
    14

    Re: Socket( PC to SUN)

    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

  4. #4
    Join Date
    Apr 1999
    Posts
    37

    Re: Socket( PC to SUN)

    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));





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured