Thread: Socket programming in C with socket.h

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    6

    Socket programming in C with socket.h

    Hi all.
    I'm trying to code a socket program using socket.h. As instruction, i download socket.h and paste into sys folder of my compiler home. Then i include this header file into my .c file but there're many errors when i make this file. I wonder if that is standard header file or not? Please help me to solve this problem because i think socket programing in c is basic and socket.h must be wellknown.

    Thanks alot.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You might want to read Beej's Guide to Network Programming.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    6
    Oh, thank you very much.
    Because i attempt to use socket.h for programming in window enviroment although this document recommend us using winsock.h. So i will try with my linux at home.

    Thanks again.

  4. #4
    Registered User
    Join Date
    Apr 2007
    Posts
    6
    By the way, may i have your yahoo id so that i can ask you some time. Fogive me if my words disturbs you.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Because i attempt to use socket.h for programming in window enviroment although this document recommend us using winsock.h. So i will try with my linux at home.
    Well, why must you use socket.h? There is no network programming library specified by the standard.

    By the way, may i have your yahoo id so that i can ask you some time.
    I do not use YIM, and it is better to ask here on cprogramming.com anyway.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    Apr 2007
    Posts
    6
    Quote Originally Posted by laserlight View Post
    Well, why must you use socket.h? There is no network programming library specified by the standard.
    I read it in instruction and i thought it is the simplest way to start practicing socket in c language. i'm using lcc as compiler because my notebook working in window xp enviroment ,but i have a linux pc at home. I have started studying c socket for a few days and i want to do some study about networking programming so i need somebody's help.
    Thank you.

  7. #7
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Well you have the whole internet at your fingertips, there's no need to target one person.

  8. #8
    Registered User
    Join Date
    Apr 2007
    Posts
    6
    Hi i'm back with a question!
    I have problem with winsock2.h. I'm using VS C++ 6 and i try to compile a program using pcap. But my winsock2.h do not define sockaddr_storage struct. How can i update this header file? is it ok if i copy this struct from msdn to this file or where can i download the newer.

    Thanks

  9. #9
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by funzy View Post
    Hi all.
    As instruction, i download socket.h and paste into sys folder of my compiler home. Then i include this header file into my .c file but there're many errors when i make this file.
    A header file is not code. It does nothing for you but tell you what you COULD do, if you had the library. Think of the header file as the menu in a restaurant. The library is like the food. You'd be pretty disappointed if you went to a restaurant and all you could do was look at the menu and not actually order anything.

    Whatever kind of computer you are working with, it most likely already has socket development libraries installed on it. Downloading some header off the Internet is meaningless.

  10. #10
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by funzy View Post
    Hi i'm back with a question!
    I have problem with winsock2.h. I'm using VS C++ 6 and i try to compile a program using pcap. But my winsock2.h do not define sockaddr_storage struct. How can i update this header file? is it ok if i copy this struct from msdn to this file or where can i download the newer.
    To use my previous analogy, editing a header file that you didn't make yourself is like taking a menu and writing down new entrees. People who do that are known as "crazy."

  11. #11
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    did you make sure you linked to winsock2.lib ? Iknow ive made that mistake a few times when writing client/server skeletons.

  12. #12
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Quote Originally Posted by abachler View Post
    did you make sure you linked to winsock2.lib ? Iknow ive made that mistake a few times when writing client/server skeletons.
    you mean, ws32_2.lib Kind of stupid as it was called winsock.lib and now its totally different :|

  13. #13
    Registered User
    Join Date
    Aug 2008
    Posts
    1

    About C language Socket Programs

    Hi LaserLight.
    I have send a massage to U also.
    Whether U have solved the problem of header files in C language/
    I want to use them in DOS mode or windows mode.
    What can I do. From where I can get the required header files.

  14. #14
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    This thread is over half a year old - there is a rule on this forum of "don't wake old threads". Start a new thread if you want, and in that, perhaps you can describe a bit better what it is you are trying to do, what is or isn't happening that is different from what you expect, etc.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. socket programming question, closing sockets...
    By ursula in forum Networking/Device Communication
    Replies: 2
    Last Post: 05-31-2009, 05:17 PM
  2. Socket Help - Multiple Clients
    By project95talon in forum C Programming
    Replies: 5
    Last Post: 11-17-2005, 02:51 AM
  3. when to close a socket
    By Wisefool in forum Networking/Device Communication
    Replies: 5
    Last Post: 11-02-2003, 10:33 AM
  4. problem closing a socket
    By Wisefool in forum C Programming
    Replies: 1
    Last Post: 10-28-2003, 01:38 PM
  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