Comment on this socket code

This is a discussion on Comment on this socket code within the C Programming forums, part of the General Programming Boards category; Anyone care to comment on what this socket code does line by line? Thanks. Explain what each line does. Code: ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    10

    Comment on this socket code

    Anyone care to comment on what this socket code does line by line? Thanks. Explain what each line does.
    Code:
    status = WSAStartup(MAKEWORD(2,0),&Data);
    
    if (status !=0)
      printf ("Error: MAKEWORD\n");
    
    
    // Create Send Socket >>>>>>>>>>>>>>>>>
    
    memset(&sendSockAddr,0,sizeof(sendSockAddr));
    sendSockAddr.sin_port = ACRO_RDS_PORT;
    sendSockAddr.sin_family = AF_INET;
    
    sendSocket = socket(AF_INET,SOCK_DGRAM,0);
    
    if (sendSocket == INVALID_SOCKET)
      printf ("RDN Socket() Error\n");
    
    status = bind(sendSocket,(LPSOCKADDR) &sendSockAddr,
    		sizeof(sendSockAddr));
    
    if (status == SOCKET_ERROR)
      printf ("ERROR: BIND\n");
    
    size = gethostname(hostname,sizeof(hostname));
    printf ("HOST NAME: %s\n",hostname);
    
    phe = gethostbyname(hostname);
    printf ("NAME = %s\n",phe->h_name);
    
    memcpy(&sendSockAddr.sin_addr,phe->h_addr_list[0],phe->h_length); 
    
    status = setsockopt(sendSocket,SOL_SOCKET | SO_REUSEADDR,SO_BROADCAST, (char *) &enable,sizeof(enable));

    Code tagged by Hammer
    Go Angels!
    Go Lakers!
    Go Trojans!
    Go Stock Market!

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>Anyone care to comment on what this socket code does line by line? Thanks. Explain what each line does.
    Not really. Why don't you read the manual pages on each of the functions used in the code.

    In essence, it does this:

    - Starts Winsock
    - Gets and binds to a socket
    - Grabs some local host details
    - Sets some socket options.

    ... but I'm sure you knew that already.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by Hammer
    In essence, it does this:

    - Starts Winsock
    - Gets and binds to a socket
    - Grabs some local host details
    - Sets some socket options.

    ... but I'm sure you knew that already.
    You forgot:

    Does lousy error checking, that only tells you if there was an error, but continues on with the program's exeuction anyway...

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    10

    more help?

    Can anyone tell me something that isn't already obvious?

    Thanks.
    Go Angels!
    Go Lakers!
    Go Trojans!
    Go Stock Market!

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>Can anyone tell me something that isn't already obvious?
    It's a section of code from a new network based game to be released by M$ next month.

    What exactly are you wanting to know? Have you read up about Winsock yet?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826

    Re: more help?

    Originally posted by mashley
    Can anyone tell me something that isn't already obvious?

    Thanks.
    I could, if I knew what exactly you didn't understand. However, since I don't, I can't. I mean really, what's obvious to me is obviously not obvious to you. Otherwise, you wouldn't be asking for assistance. So, what's obvious to you? What exactly don't you understand?

    If you learn one thing at all about programming, it's that you need to be speficic in exactly what you need done. Otherwise you won't know how to do whatever it is you're supposed to do. I mean how could you?



    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with network code
    By cornholio in forum Linux Programming
    Replies: 1
    Last Post: 12-20-2005, 01:21 AM
  2. Shouldn't this code work?
    By DeepFyre in forum C++ Programming
    Replies: 3
    Last Post: 10-03-2004, 02:24 PM
  3. Socket Programming Introduction Source Code
    By Lynux-Penguin in forum Linux Programming
    Replies: 2
    Last Post: 04-30-2002, 06:29 PM
  4. Replies: 4
    Last Post: 01-16-2002, 12:04 AM
  5. Code for Client/Server Socket
    By Unregistered in forum C++ Programming
    Replies: 4
    Last Post: 01-15-2002, 09:30 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21