{"id":5986,"date":"2022-08-31T20:03:00","date_gmt":"2022-08-31T14:33:00","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-send-network-traffic-to-from-a-specific-ip-and-port-without-using-recvfrom-or-accept\/"},"modified":"2022-08-31T20:03:00","modified_gmt":"2022-08-31T14:33:00","slug":"solved-send-network-traffic-to-from-a-specific-ip-and-port-without-using-recvfrom-or-accept","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-send-network-traffic-to-from-a-specific-ip-and-port-without-using-recvfrom-or-accept\/","title":{"rendered":"[Solved] send network traffic to from a specific ip and port without using recvfrom or accept"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-50747897\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"50747897\" data-parentid=\"50731644\" data-score=\"4\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<blockquote>\n<p>Need to continuously send telemetry data over a network. Don&#8217;t really care who is going to get it, just need to send it out.<\/p>\n<\/blockquote>\n<p>Well, your sender need to know WHERE to send data to.<\/p>\n<p>Typically, a receiver would first send a request to your sender so it knows the receiver exists, and then your sender would know where to send packets to.  But, this requires your sender to keep track of all of the receivers so it can send a separate data packet to every receiver individually.  Either UDP or TCP can be used for this.<\/p>\n<p>If you don&#8217;t want to do things that way, you have 2 other choices:<\/p>\n<ul>\n<li>\n<p><strong>subnet broadcasting<\/strong> (works with IPv4 only) &#8211; your sender can create a UDP socket, then use <code>setsockopt()<\/code> to enable the <code>SO_BROADCAST<\/code> option on it, and then <code>sendto()<\/code> data packets to the broadcast IP address of a given subnet (or use <code>send()<\/code> if it <code>connect()<\/code>&#8216;s to the broadcast IP beforehand).  Each packet sent will be automatically delivered to <em>every<\/em> machine that is connected to that same subnet (whether the machines want the packets or not).<\/p>\n<p>Your receiver can then create and <code>bind()<\/code> a UDP socket to a local network interface that is connected to that same subnet, and then use <code>recvfrom()<\/code> to read the packets (or use <code>recv()<\/code> if it <code>connect()<\/code>&#8216;s to the sender&#8217;s IP address beforehand).<\/p>\n<\/li>\n<li>\n<p><strong>multicasting<\/strong> (works with both IPv4 and IPv6) &#8211; your sender can create a UDP socket and then <code>sendto()<\/code> data packets to the IP address of a given multicast group (or use <code>send()<\/code> if it <code>connect()<\/code>&#8216;s to the multicast group IP beforehand).  Every packet will be delivered <em>only<\/em> to receivers who have joined the same group.<\/p>\n<p>Your receiver can create and <code>bind()<\/code> a UDP socket to a local network interface that has a network route to the sender, then use <code>setsockopt()<\/code> to join the socket to the multicast group (using <code>IP_ADD_MEMBERSHIP<\/code> for IPv4, and <code>IPV6_ADD_MEMBERSHIP<\/code> for IPv6), and then use <code>recvfrom()<\/code> to read the packets (or use <code>recv()<\/code> if it <code>connect()<\/code>&#8216;s to the sender&#8217;s IP beforehand).<\/p>\n<\/li>\n<\/ul>\n<blockquote>\n<p>All the client needs to do is simply to connect to a specific IP and get data from a specific port and the data will be received by it.<\/p>\n<\/blockquote>\n<p>I would suggest using multicasting for this.  You get the benefits of being able to send fewer packets on the sender side and have them delivered across the network to (potentially) multiple receivers at the same time, and you reduce network overhead by isolating traffic to only the parties who actually want to receive the packets.<\/p>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\"><\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved send network traffic to from a specific ip and port without using recvfrom or accept <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] Need to continuously send telemetry data over a network. Don&#8217;t really care who is going to get it, just need to send it out. Well, your sender need to know WHERE to send data to. Typically, a receiver would first send a request to your sender so it knows the receiver exists, and then &#8230; <a title=\"[Solved] send network traffic to from a specific ip and port without using recvfrom or accept\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-send-network-traffic-to-from-a-specific-ip-and-port-without-using-recvfrom-or-accept\/\" aria-label=\"More on [Solved] send network traffic to from a specific ip and port without using recvfrom or accept\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[324,970,1074,1439],"class_list":["post-5986","post","type-post","status-publish","format-standard","hentry","category-solved","tag-c","tag-networking","tag-sockets","tag-udp"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>[Solved] send network traffic to from a specific ip and port without using recvfrom or accept - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-send-network-traffic-to-from-a-specific-ip-and-port-without-using-recvfrom-or-accept\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] send network traffic to from a specific ip and port without using recvfrom or accept - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] Need to continuously send telemetry data over a network. Don&#8217;t really care who is going to get it, just need to send it out. Well, your sender need to know WHERE to send data to. Typically, a receiver would first send a request to your sender so it knows the receiver exists, and then ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-send-network-traffic-to-from-a-specific-ip-and-port-without-using-recvfrom-or-accept\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-31T14:33:00+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-send-network-traffic-to-from-a-specific-ip-and-port-without-using-recvfrom-or-accept\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-send-network-traffic-to-from-a-specific-ip-and-port-without-using-recvfrom-or-accept\\\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/person\\\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] send network traffic to from a specific ip and port without using recvfrom or accept\",\"datePublished\":\"2022-08-31T14:33:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-send-network-traffic-to-from-a-specific-ip-and-port-without-using-recvfrom-or-accept\\\/\"},\"wordCount\":449,\"publisher\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#organization\"},\"keywords\":[\"c++\",\"networking\",\"sockets\",\"udp\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-send-network-traffic-to-from-a-specific-ip-and-port-without-using-recvfrom-or-accept\\\/\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-send-network-traffic-to-from-a-specific-ip-and-port-without-using-recvfrom-or-accept\\\/\",\"name\":\"[Solved] send network traffic to from a specific ip and port without using recvfrom or accept - JassWeb\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#website\"},\"datePublished\":\"2022-08-31T14:33:00+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-send-network-traffic-to-from-a-specific-ip-and-port-without-using-recvfrom-or-accept\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-send-network-traffic-to-from-a-specific-ip-and-port-without-using-recvfrom-or-accept\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-send-network-traffic-to-from-a-specific-ip-and-port-without-using-recvfrom-or-accept\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] send network traffic to from a specific ip and port without using recvfrom or accept\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#website\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/jassweb.com\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/jass-website-logo-1.png\",\"contentUrl\":\"https:\\\/\\\/jassweb.com\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/person\\\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/wp-content\\\/litespeed\\\/avatar\\\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777613206\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/wp-content\\\/litespeed\\\/avatar\\\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777613206\",\"contentUrl\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/wp-content\\\/litespeed\\\/avatar\\\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777613206\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\\\/\\\/jassweb.com\"],\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/author\\\/jaspritsinghghumangmail-com\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] send network traffic to from a specific ip and port without using recvfrom or accept - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-send-network-traffic-to-from-a-specific-ip-and-port-without-using-recvfrom-or-accept\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] send network traffic to from a specific ip and port without using recvfrom or accept - JassWeb","og_description":"[ad_1] Need to continuously send telemetry data over a network. Don&#8217;t really care who is going to get it, just need to send it out. Well, your sender need to know WHERE to send data to. Typically, a receiver would first send a request to your sender so it knows the receiver exists, and then ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-send-network-traffic-to-from-a-specific-ip-and-port-without-using-recvfrom-or-accept\/","og_site_name":"JassWeb","article_published_time":"2022-08-31T14:33:00+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-send-network-traffic-to-from-a-specific-ip-and-port-without-using-recvfrom-or-accept\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-send-network-traffic-to-from-a-specific-ip-and-port-without-using-recvfrom-or-accept\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] send network traffic to from a specific ip and port without using recvfrom or accept","datePublished":"2022-08-31T14:33:00+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-send-network-traffic-to-from-a-specific-ip-and-port-without-using-recvfrom-or-accept\/"},"wordCount":449,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["c++","networking","sockets","udp"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-send-network-traffic-to-from-a-specific-ip-and-port-without-using-recvfrom-or-accept\/","url":"https:\/\/jassweb.com\/solved\/solved-send-network-traffic-to-from-a-specific-ip-and-port-without-using-recvfrom-or-accept\/","name":"[Solved] send network traffic to from a specific ip and port without using recvfrom or accept - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-08-31T14:33:00+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-send-network-traffic-to-from-a-specific-ip-and-port-without-using-recvfrom-or-accept\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-send-network-traffic-to-from-a-specific-ip-and-port-without-using-recvfrom-or-accept\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-send-network-traffic-to-from-a-specific-ip-and-port-without-using-recvfrom-or-accept\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] send network traffic to from a specific ip and port without using recvfrom or accept"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777613206","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777613206","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777613206","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/5986","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=5986"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/5986\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=5986"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=5986"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=5986"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}