{"id":787,"date":"2019-05-24T11:05:53","date_gmt":"2019-05-24T02:05:53","guid":{"rendered":"https:\/\/www.oji-koji.com\/?p=787"},"modified":"2021-07-28T10:40:44","modified_gmt":"2021-07-28T01:40:44","slug":"%e5%88%9d%e3%82%81%e3%81%a6%e3%81%aetcp-ip%e3%83%97%e3%83%ad%e3%82%b0%e3%83%a9%e3%83%a0simpleclient%e6%a6%82%e8%a6%81%e3%81%a8%e4%bd%bf%e7%94%a8%e3%81%99%e3%82%8bapi","status":"publish","type":"post","link":"https:\/\/www.oji-koji.com\/?p=787","title":{"rendered":"\u521d\u3081\u3066\u306eTCP\/IP\u30d7\u30ed\u30b0\u30e9\u30e0SimpleClient(\u6982\u8981\u3068\u4f7f\u7528\u3059\u308bAPI)"},"content":{"rendered":"\n<p class=\"program_discription\">\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u5074(SimpleClient)<br>\u5148\u305a\u306f\u5358\u7d14\u306a\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u3092\u4f5c\u308a\u307e\u3059\u3002<br>\u30de\u30eb\u30c1\u30b9\u30ec\u30c3\u30c9\u5316\u306a\u3069\u306f\u3001\u5f8c\u7a0b\u3053\u306e\u5358\u7d14\u306a\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u3092\u5143\u306b\u8003\u3048\u308b\u3053\u3068\u306b\u3057\u307e\u3059\u3002<br>\u6b21\u306e\u3088\u3046\u306a\u6a5f\u80fd\u3092\u5b9f\u73fe\u3057\u307e\u3059\u3002<br>  \u8d77\u52d5\u5f15\u6570\uff1a\u30b5\u30fc\u30d0\u30a2\u30c9\u30ec\u30b9 \u30b5\u30fc\u30d0\u30dd\u30fc\u30c8\u756a\u53f7<br>  \u3053\u3053\u3067\u6307\u5b9a\u3057\u305f\u30b5\u30fc\u30d0\u306b\u30dd\u30fc\u30c8\u756a\u53f7\u3067\u63a5\u7d9a\u8981\u6c42\u3092\u3057\u307e\u3059\u3002<br>  \u63a5\u7d9a\u304c\u6210\u529f\u3057\u305f\u3089\u6b21\u306e\u30e1\u30cb\u30e5\u30fc\u3092\u8868\u793a\u3057\u307e\u3059\u3002<br>  \u5931\u6557\u3057\u305f\u3089\u7d42\u4e86<br>   q:quit m:\u30e1\u30c3\u30bb\u30fc\u30b8\u9001\u4fe1 :<br>    \u2018q\u2019\u5165\u529b\u3067\u30d7\u30ed\u30b0\u30e9\u30e0\u7d42\u4e86<br>    &#8216;m\u2019\u5165\u529b\u3067\u6587\u5b57\u5217\u5165\u529b\u30e2\u30fc\u30c9\u3078\u79fb\u884c<br>      \u9001\u4fe1\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044 :<br>      \u6587\u5b57\u5217[ENTER]\u3067\u5165\u529b\u3055\u308c\u305f\u6587\u5b57\u5217\u3092\u30b5\u30fc\u30d0\u306b\u9001\u4fe1\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"source_code\">C:\\Products\\SimpleClient\\x64\\Debug&gt;SimpleClient fe80::11a0:ecd4:2cf8:6e5c 10000\nq:quit m:\u30e1\u30c3\u30bb\u30fc\u30b8\u9001\u4fe1 :\n\u9001\u4fe1\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044 : Hello\n<\/p>\n\n\n\n<p class=\"program_discription\">SimpleClient\u3067\u306f\u3001\u30bd\u30b1\u30c3\u30c8API\u3092\u4f7f\u7528\u3059\u308b\u95a2\u6570\u3092\u6b21\u306e\u3088\u3046\u306a\u95a2\u6570\u306b\u307e\u3068\u3081\u308b\u3053\u3068\u306b\u3057\u307e\u3059<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.oji-koji.com\/wp-content\/uploads\/2019\/05\/Client-1024x755.png\" alt=\"\" class=\"wp-image-791\" width=\"768\" height=\"566\" srcset=\"https:\/\/www.oji-koji.com\/wp-content\/uploads\/2019\/05\/Client-1024x755.png 1024w, https:\/\/www.oji-koji.com\/wp-content\/uploads\/2019\/05\/Client-300x221.png 300w, https:\/\/www.oji-koji.com\/wp-content\/uploads\/2019\/05\/Client-768x566.png 768w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/figure>\n\n\n\n<p class=\"program_discription\">CreateAndConnectSocket\u95a2\u6570\u3067\u306f\u3001\u6b21\u306e\u30bd\u30b1\u30c3\u30c8API\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<br>\u3053\u306e\u95a2\u6570\u3067\u306f\u6307\u5b9a\u3055\u308c\u305f\u30b5\u30fc\u30d0\u306b\u5bfe\u3059\u308b\u30a2\u30c9\u30ec\u30b9\u60c5\u5831(IPv4, IPv6\u3068\u8907\u6570\u3042\u308b\u5834\u5408\u3082<br>\u3042\u308a\u307e\u3059)\u306b\u5bfe\u3057\u3066\u30bd\u30b1\u30c3\u30c8\u3092\u4f5c\u6210\u3057\u3001\u9806\u756a\u306b\u63a5\u7d9a\u51e6\u7406\u3092\u884c\u3044\u6210\u529f\u3057\u305f\u3089\u3001\u305d\u306e\u30bd\u30b1\u30c3\u30c8<br>\u3092\u4f7f\u3063\u3066\u9001\u53d7\u51e6\u7406\u3092\u884c\u3044\u307e\u3059\u3002<br><strong>SOCKET socket(int af, int type, int protocol);<\/strong><br>  \u30bd\u30b1\u30c3\u30c8\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<br>  \u901a\u4fe1\u306e\u305f\u3081\u306e\u7aef\u70b9 (endpoint) \u3092\u4f5c\u6210\u3057\u3001 \u30c7\u30a3\u30b9\u30af\u30ea\u30d7\u30bf\u30fc\u3092\u8fd4\u3057\u307e\u3059\u3002<br>  af, type, protocol\u306e\u6307\u5b9a\u306b\u306f\u63a5\u7d9a\u5148\u30b5\u30fc\u30d0\u3092\u6307\u5b9a\u3057\u3066getaddrinfo\u3092\u547c\u3093\u3060<br>  \u7d50\u679c\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<br>  SimpleClient\u3067\u306f\u3053\u3053\u3067\u4f5c\u3063\u305f\u30bd\u30b1\u30c3\u30c8\u3092\u4f7f\u3063\u3066\u63a5\u7d9a\u51e6\u7406\u3082\u30c7\u30fc\u30bf\u306e<br>  \u9001\u53d7\u4fe1\u51e6\u7406\u3082\u884c\u3044\u307e\u3059\u3002<br><strong>int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);<\/strong><br>  \u30bd\u30b1\u30c3\u30c8\u306e\u63a5\u7d9a\u51e6\u7406\u3092\u884c\u3044\u307e\u3059\u3002<br>  \u30d5\u30a1\u30a4\u30eb\u30c7\u30a3\u30b9\u30af\u30ea\u30d7\u30bf\u30fc sockfd \u304c\u53c2\u7167\u3057\u3066\u3044\u308b\u30bd\u30b1\u30c3\u30c8\u3092\u4f7f\u3063\u3066 addr \u3067\u6307\u5b9a\u3055\u308c\u305f<br>  \u30a2\u30c9\u30ec\u30b9\u306b\u63a5\u7d9a\u51e6\u7406\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"program_discription\">DoSend\u95a2\u6570\u3067\u306f\u3001\u6b21\u306e\u30bd\u30b1\u30c3\u30c8API\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<br><strong>int send(int sockfd, const void *buf, size_t len, int flags);<\/strong><br>  \u63a5\u7d9a\u6e08\u307f\u30bd\u30b1\u30c3\u30c8sockfd\u306b\u30c7\u30fc\u30bf\u9001\u4fe1\u3092\u884c\u3044\u307e\u3059\u3002<br>  send\u306f\u3001\u30bd\u30b1\u30c3\u30c8\u304c \u63a5\u7d9a\u3055\u308c\u305f (connected) \u72b6\u614b\u306b\u3042\u308b\u5834\u5408\u306b\u306e\u307f\u4f7f\u7528\u3067\u304d\u307e\u3059\u3002<br>  send\u306f\u30d6\u30ed\u30c3\u30af\u3059\u308b\u306e\u3067\u3001\u547c\u3073\u51fa\u3059\u524d\u306b\u9001\u4fe1\u53ef\u80fd\u304b\u3069\u3046\u304b\u3092select\u3092 \u4f7f\u3063\u3066<br>  \u8abf\u3079\u308b\u3053\u3068\u306b\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"program_discription\">DestroySocket\u95a2\u6570\u3067\u306f\u3001\u6b21\u306e\u30bd\u30b1\u30c3\u30c8API\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<br><strong>int shutdown(SOCKET sockfd, int how);<\/strong><br>  \u30bd\u30b1\u30c3\u30c8\u306e\u7834\u68c4<br>  sockfd \u306b\u95a2\u9023\u3065\u3051\u3089\u308c\u3066\u3044\u308b\u30bd\u30b1\u30c3\u30c8\u306b\u3088\u308b\u5168\u4e8c\u91cd\u63a5\u7d9a (full-duplex<br>  connection)\u306e\u4e00\u90e8\u307e\u305f\u306f\u5168\u3066\u3092\u9589\u3058\u307e\u3059\u3002<br>  \u3053\u3053\u3067\u306f\u3001\u9001\u53d7\u4fe1\u3092\u9589\u3058\u308b\u305f\u3081\u6b21\u306e\u5024\u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002<br>  Windows\u3067\u306fhow\u306bSD_BOTH\u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002<br>  Linux\u3067\u306fhow\u306bSHUT_RDWR\u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002<br><strong>int closesocket(SOCKET sockfd); <\/strong> Windows\u7528<br><strong>int close(SOCKET sockfd);  <\/strong>            Linux\u7528<br>  \u30bd\u30b1\u30c3\u30c8\u30c7\u30a3\u30b9\u30af\u30ea\u30d7\u30bf\u30fc\u3092\u30af\u30ed\u30fc\u30ba\u3057\u307e\u3059 \u3002<\/p>\n\n\n\n<p class=\"program_discription\">\u4ee5\u4e0a\u306e\u3053\u3068\u3092\u5ff5\u982d\u306b\u5b9f\u969b\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u4f5c\u308b\u3053\u3068\u306b\u3057\u307e\u3059\u3002<br>\u4f5c\u6210\u306f\u3001\u6b21\u56de\u3068\u3044\u3046\u3053\u3068\u3067\u3002\u3002\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u5074(SimpleClient)\u5148\u305a\u306f\u5358\u7d14\u306a\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u3092\u4f5c\u308a\u307e\u3059\u3002\u30de\u30eb\u30c1\u30b9\u30ec\u30c3\u30c9\u5316\u306a\u3069\u306f\u3001\u5f8c\u7a0b\u3053\u306e\u5358\u7d14\u306a\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u3092\u5143\u306b\u8003\u3048\u308b\u3053\u3068\u306b\u3057\u307e\u3059\u3002\u6b21\u306e\u3088\u3046\u306a\u6a5f\u80fd\u3092\u5b9f\u73fe\u3057\u307e\u3059\u3002 \u8d77\u52d5\u5f15\u6570\uff1a\u30b5\u30fc\u30d0\u30a2\u30c9\u30ec\u30b9 \u30b5\u30fc\u30d0\u30dd\u30fc [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":129,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_locale":"ja","_original_post":"https:\/\/www.oji-koji.com\/?p=787","footnotes":""},"categories":[6],"tags":[],"class_list":["post-787","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-networkprograming","ja"],"_links":{"self":[{"href":"https:\/\/www.oji-koji.com\/index.php?rest_route=\/wp\/v2\/posts\/787","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oji-koji.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.oji-koji.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.oji-koji.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oji-koji.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=787"}],"version-history":[{"count":12,"href":"https:\/\/www.oji-koji.com\/index.php?rest_route=\/wp\/v2\/posts\/787\/revisions"}],"predecessor-version":[{"id":3096,"href":"https:\/\/www.oji-koji.com\/index.php?rest_route=\/wp\/v2\/posts\/787\/revisions\/3096"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.oji-koji.com\/index.php?rest_route=\/wp\/v2\/media\/129"}],"wp:attachment":[{"href":"https:\/\/www.oji-koji.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=787"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oji-koji.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=787"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oji-koji.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=787"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}