{"id":253785,"date":"2026-07-13T03:03:36","date_gmt":"2026-07-13T00:03:36","guid":{"rendered":"https:\/\/1kitap1.com\/en\/beejs-guide-to-network-programming-brian-hall\/"},"modified":"2026-07-13T03:03:36","modified_gmt":"2026-07-13T00:03:36","slug":"beejs-guide-to-network-programming-brian-hall","status":"publish","type":"post","link":"https:\/\/1kitap1.com\/en\/beejs-guide-to-network-programming-brian-hall\/","title":{"rendered":"Beejs Guide To Network Programming &#8211; Brian Hall"},"content":{"rendered":"<figure style=\"text-align:center;margin:0 auto 1.5em;\"><img decoding=\"async\" src=\"https:\/\/1kitap1.com\/en\/wp-content\/uploads\/2026\/07\/12a121295aa1da3b.jpg\" alt=\" - Unknown book cover\" style=\"max-width:300px;width:100%;height:auto;box-shadow:0 4px 12px rgba(0,0,0,.25);border-radius:4px;\"\/><\/figure>\n<p>Slightly Advanced Techniques int get_listener_socket(void) { struct addrinfo hints, *ai, *p; int yes=1; \/\/ for setsockopt() SO_REUSEADDR, below int rv; int listener; \/\/ get us a socket and bind it memset(&#038;hints, 0, sizeof hints); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_PASSIVE; if ((rv = getaddrinfo(NULL, PORT, &#038;hints, &#038;ai)) != 0) { fprintf(stderr, &#8220;selectserver: %s\\n&#8221;, gai_strerror(rv)); exit(1); } for(p = ai; p != NULL; p = p->ai_next) { listener = socket(p->ai_family, p->ai_socktype, p->ai_protocol); if (listener < 0) { continue; } \/\/ lose the pesky \"address already in use\" error message setsockopt(listener, SOL_SOCKET, SO_REUSEADDR, &#038;yes, sizeof(int)); if (bind(listener, p->ai_addr, p->ai_addrlen) < 0) { close(listener); continue; } break; } \/\/ if we got here, it means we didn't get bound if (p == NULL) { fprintf(stderr, \"selectserver: failed to bind\\n\"); exit(2); } freeaddrinfo(ai); \/\/ all done with this \/\/ listen if (listen(listener, 10) == -1) { perror(\"listen\"); exit(3); } return listener; } Chapter 7.<\/p>\n<p>Slightly Advanced Techniques \/* * Add new incoming connections to the proper sets *\/ void handle_new_connection(int listener, fd_set *master, int *fdmax) { socklen_t addrlen; int newfd; \/\/ newly accept()ed socket descriptor struct sockaddr_storage remoteaddr; \/\/ client address char remoteIP[INET6_ADDRSTRLEN]; addrlen = sizeof remoteaddr; newfd = accept(listener, (struct sockaddr *)&#038;remoteaddr, &#038;addrlen); if (newfd == -1) { perror(&#8220;accept&#8221;); } else { FD_SET(newfd, master); \/\/ add to master set if (newfd > *fdmax) { \/\/ keep track of the max *fdmax = newfd; } printf(&#8220;selectserver: new connection from %s on &#8221; &#8220;socket %d\\n&#8221;, inet_ntop2(&#038;remoteaddr, remoteIP, sizeof remoteIP), newfd); } } \/* * Broadcast a message to all clients *\/ void broadcast(char *buf, int nbytes, int listener, int s, fd_set *master, int fdmax) { for(int j = 0; j <= fdmax; j++) { \/\/ send to everyone!<\/p>\n<p>if (FD_ISSET(j, master)) { \/\/ except the listener and ourselves if (j != listener &#038;&#038; j != s) { if (send(j, buf, nbytes, 0) == -1) { perror(&#8220;send&#8221;); } } } } } \/* * Handle client data and hangups *\/ void handle_client_data(int s, int listener, fd_set *master, int fdmax) Chapter 7.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/1kitap1.com\/en\/beejs-guide-to-network-programming-brian-hall\/#Book_Information\" >Book Information<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/1kitap1.com\/en\/beejs-guide-to-network-programming-brian-hall\/#Reading_Word_Statistics\" >Reading &amp; Word Statistics<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/1kitap1.com\/en\/beejs-guide-to-network-programming-brian-hall\/#Most_Frequent_Words\" >Most Frequent Words<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/1kitap1.com\/en\/beejs-guide-to-network-programming-brian-hall\/#PDF_Download\" >PDF Download<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Book_Information\"><\/span>Book Information<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul>\n<li><strong>Unique ID:<\/strong> 12a121295aa1da3b<\/li>\n<li><strong>File Extension:<\/strong> .pdf<\/li>\n<li><strong>File Size:<\/strong> 825,753 bytes (0.787 MB)<\/li>\n<li><strong>Title:<\/strong> &#8211;<\/li>\n<li><strong>Author:<\/strong> Unknown<\/li>\n<li><strong>ISBN:<\/strong> 0000000000<\/li>\n<li><strong>Pages:<\/strong> 133<\/li>\n<li><strong>Language:<\/strong> English (en)<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Reading_Word_Statistics\"><\/span>Reading &amp; Word Statistics<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul>\n<li><strong>Estimated Reading Time:<\/strong> 228.26 minutes<\/li>\n<li><strong>Total Words:<\/strong> 45,653<\/li>\n<li><strong>Total Characters:<\/strong> 260,953<\/li>\n<li><strong>Average Words per Page:<\/strong> 343.26<\/li>\n<li><strong>Average Characters per Page:<\/strong> 1962.05<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Most_Frequent_Words\"><\/span>Most Frequent Words<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>int (378), socket (362), struct (349), addr (291), inet (237), data (208), ipv (199), sockaddr (198), address (194), set (191), include (189), buf (174), use (168), hints (147), send (138), return (133), port (130), get (129), network (129), chapter (126), function (124), char (122), call (121), one (116), long (115), sockets (106), sockfd (105), want (104), unsigned (104), see (102), like (101), family (98), recv (97), it\u2019s (97), getaddrinfo (95), host (93), error (92), https (89), sin (88), number (87), sizeof (86), descriptor (85), server (84), you\u2019re (84), res (84), connect (81), client (81), stream (80), bind (78), listener (77), man (76), protocol (75), packet (75), system (73), size (73), byte (72), bytes (71), don\u2019t (70), addresses (69), also (69), connection (69), sock (69), example (68), sys (68), select (66), errno (66), bit (64), returns (64), null (64), file (61), read (61), name (61), guide (60), rfc (60), printf (60), first (59), information (58), need (58), accept (57), org (57), string (57), pages (56), len (56), case (54), order (52), code (52), type (52), perror (51), well (51), value (51), now (49), types (49), you\u2019ll (49), that\u2019s (49), time (48), new (48), ready (48), void (48), using (47), close (47).<\/p>\n<h2><span class=\"ez-toc-section\" id=\"PDF_Download\"><\/span>PDF Download<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align:center;\"><a href=\"https:\/\/1kitap1.com\/en\/wp-content\/uploads\/2026\/07\/beejs-guide-to-network-programming-brian-hall.pdf\" download rel=\"nofollow\" style=\"display:inline-block;background:#2271b1;color:#ffffff;padding:14px 36px;border-radius:6px;text-decoration:none;font-weight:bold;font-size:1.05em;\">&#11015;&#65039; PDF Download<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Slightly Advanced Techniques int get_listener_socket(void) { struct addrinfo hints, *ai, *p; int yes=1; \/\/ for setsockopt() SO_REUSEADDR, below int rv; int listener; \/\/ get us a socket and bind it memset(&#038;hints, 0, sizeof hints); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_PASSIVE; if ((rv = getaddrinfo(NULL, PORT, &#038;hints, &#038;ai)) != 0) { fprintf(stderr, &#8220;selectserver: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":253783,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-253785","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-english"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/1kitap1.com\/en\/wp-json\/wp\/v2\/posts\/253785","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/1kitap1.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/1kitap1.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/1kitap1.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/1kitap1.com\/en\/wp-json\/wp\/v2\/comments?post=253785"}],"version-history":[{"count":0,"href":"https:\/\/1kitap1.com\/en\/wp-json\/wp\/v2\/posts\/253785\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/1kitap1.com\/en\/wp-json\/wp\/v2\/media\/253783"}],"wp:attachment":[{"href":"https:\/\/1kitap1.com\/en\/wp-json\/wp\/v2\/media?parent=253785"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/1kitap1.com\/en\/wp-json\/wp\/v2\/categories?post=253785"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/1kitap1.com\/en\/wp-json\/wp\/v2\/tags?post=253785"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}