CrazyEngineers
  • sahana
    sahana

    MemberJun 9, 2008

    sockets

    hi everyone.i need a small help in C.
    i want to know if there can be a socket which is a blocking one.just the syntax and header files necessary.something like the socket has to wait untill it gets a packet
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • elric

    MemberJun 15, 2008

    i guess you are asking the syntax to functions to make a basic server, to do this you need to use listen() first and then accept()
    their prototypes are
    #include <sys/socket.h>
    int listen(int sockfd, int backlog);
    int accept(int sockfd, void *addr, int *addrlen);

    the sequence of system calls you will do is
    socket();
    bind();
    listen();
    accept();

    i hope you do know how to use socket() and bind() if not google it up or refer a good networking programming book cause you will have to take care of specifing addresses in host-byte order or network-byte order. There is a good guide to network programming on the net too, <a href="https://beej.us/guide/bgnet/" target="_blank" rel="nofollow noopener noreferrer">Beej's Guide to Network Programming</a> , is short and concise. check it out. Also the above details is for gcc.
    Are you sure? This action cannot be undone.
    Cancel
  • dropcards

    MemberJun 16, 2008

    usually the socket is blocking unless you set it otherwise with ioctl
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register