Thread: Socket Programmins

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    110

    Socket Programmins

    Okay, I am wondering exactly what can and can't be sent over a network using the send and recv commands. As the bulk of what is sent ( the data ) is of type void * or const void *, does this mean that any data type can be sent?

    If people could help me out by giving examples of what they have successfully sent and recieved using BSD like network sockets.

    Thanks
    WebmasterMattD
    WebmasterMattD.NET

  2. #2
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    I'll reply because I reply to most threads no matter what, but I'm not experienced in this area, however I believe that frameworks have more support for dispatching processes. Apparently the Java framework allows you to send objects as parameters to remote methods. It supports OOP, while traditional remote procedure calls (RPM's) are action based. You can only send data structures that are used by remote functions.

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793

    Re: Socket Programmins

    Originally posted by WebmasterMattD
    Okay, I am wondering exactly what can and can't be sent over a network using the send and recv commands. As the bulk of what is sent ( the data ) is of type void * or const void *, does this mean that any data type can be sent?

    If people could help me out by giving examples of what they have successfully sent and recieved using BSD like network sockets.

    Thanks
    The type of the data you are sending has no real meaning to sockets......you are writting/recieving a chunk of memory...so you specify the size and the send/recv functions simply work with the amount of memory they are told to...As long as you are specifying the size in bytes properly, you shouldnt hae a worry

    You only use types in your code to tell the compiler what the memory is for.....outside of your code....its just memory.

  4. #4
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    The types might also server parameter marshalling and unmarshalling -converting the machine dependant data to an intermediate language like (XDR). This is for compatibility between the client and the server.

  5. #5
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    Messages are sent back and forth, not just the size of data. lol.

  6. #6
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Originally posted by Troll_King
    Messages are sent back and forth, not just the size of data. lol.


    I know...and I didnt say that was the case.....

  7. #7
    Registered User
    Join Date
    Apr 2002
    Posts
    110
    Thanks for your help peoplez.

    I had a feeling that it was dealing with the memory, though not 100% sure.

    By the way, Troll King, is it easy to do socket programming in Java?
    I am not experianced in that language, though will be learning it next year as a part of the course that I am doing.

    Later
    WebmasterMattD
    WebmasterMattD.NET

  8. #8
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Socket in Java are real easy to use (as are threads, but when you realise the efficiency penalty, you may long to go back to C++)...

    If you want a brief primer on Java, then spend a little time here ...its a nice Java forum with loads of info.....sun's site is good too, but I found this one to be more to my taste (Oh...and they do have a strange cowboy thing going on over there......bit weird....but its still a good site)

  9. #9
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    Even though the message sends the size for memory, it is still just a data structure that is being returned, hence action based. On the other hand, a framework allows you to send and recieve objects, which are not just datastructures, but contain data and behavior.

    Java provides an easier interface to sockets and has a rich library of networking utilities.

  10. #10
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    Originally posted by Fordy
    Socket in Java are real easy to use (as are threads, but when you realise the efficiency penalty, you may long to go back to C++)...

    If you want a brief primer on Java, then spend a little time here ...its a nice Java forum with loads of info.....sun's site is good too, but I found this one to be more to my taste (Oh...and they do have a strange cowboy thing going on over there......bit weird....but its still a good site)
    I'd rather use a system like Java for the fact that it supports more complexity. If I were using C/C++ than it would be to build a system like the Java framework. I think that all solutions should be implemented in a higher level language than C/C++.

  11. #11
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    Ah! Java! It burns! IT BURNS!!

  12. #12
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    ...and Troll_King: We know you're not a Microsoft Loser; you are just a regular loser

  13. #13
    Registered User
    Join Date
    Apr 2002
    Posts
    110
    Okay, it seems as though Java is a good language for sockets. Though I am confused with what you mean by a higher leval language.

    In my opinion C++ is a higher leval language since it is Object Oriented, though it also differers between operating systems, whereas Java is the same no which operating system you use.

    By differs, I mean that implementations such as sockets are handled differently by each operating system.

    Later
    WebmasterMattD
    WebmasterMattD.NET

  14. #14
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    Java and C++ are very different, and I don't mean just the syntax.

    You'll find proponents of both. I suppose that it depends on a lot of things. Personally I associate C/C++ with open source development and Java and .net with development on vendor operating systems.

    When writing an application in C/C++ I think that it should be a system rather than a simple solution. I only say that because I'm thinking of all the examples out there like web browsers, servers, kernal subsystems, frameworks, etc. They are all implemented in C/C++, however it appears for certain that business solutions are implemented in Java.

  15. #15
    Registered User
    Join Date
    Apr 2002
    Posts
    110
    This is still getting on my nerves. I am trying to send a struct data type, though it does not want to be sent as it should.

    What i am doing is as folows:

    struct MsgPacket MyPacket; // This is the structure

    send( socket, &MyPacket, sizeof( MyPacket ), 0 );

    and then recieving by doing the following

    recv( socket, &MyPacket, sizeof( MyPacket ), 0 );

    Is there something that I am missing when I do this?
    the prototypes for send and recv are:
    send( int s, const void *msg, size_t len, int flags )
    recv( int s, void *buf, size_t len, int flags )

    Thanks for your help.

    Later,
    WebmasterMattD
    WebmasterMattD.NET

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Non-blocking socket connection problem
    By cbalu in forum Linux Programming
    Replies: 25
    Last Post: 06-03-2009, 02:15 AM
  2. socket programming question, closing sockets...
    By ursula in forum Networking/Device Communication
    Replies: 2
    Last Post: 05-31-2009, 05:17 PM
  3. Socket Help - Multiple Clients
    By project95talon in forum C Programming
    Replies: 5
    Last Post: 11-17-2005, 02:51 AM
  4. when to close a socket
    By Wisefool in forum Networking/Device Communication
    Replies: 5
    Last Post: 11-02-2003, 10:33 AM
  5. socket newbie, losing a few chars from server to client
    By registering in forum Linux Programming
    Replies: 2
    Last Post: 06-07-2003, 11:48 AM