{"id":800,"date":"2019-05-24T14:41:09","date_gmt":"2019-05-24T05:41:09","guid":{"rendered":"https:\/\/www.oji-koji.com\/?p=800"},"modified":"2021-07-28T10:39:27","modified_gmt":"2021-07-28T01:39:27","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%a0simpleclientwindows%e7%89%88","status":"publish","type":"post","link":"https:\/\/www.oji-koji.com\/?p=800","title":{"rendered":"\u521d\u3081\u3066\u306eTCP\/IP\u30d7\u30ed\u30b0\u30e9\u30e0SimpleClient(Windows\u7248)2019\/06\/08\u66f4\u65b0"},"content":{"rendered":"\n<p class=\"program_discription\">\u300c\u30d5\u30a1\u30a4\u30eb\u300d\u2192\u300c\u65b0\u898f\u4f5c\u6210\u300d\u2192\u300cVisualC++\u300d\u2192\u300c\u7a7a\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u300d<br>  \u300c\u30bd\u30ea\u30e5\u30fc\u30b7\u30e7\u30f3\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u4f5c\u6210\u3059\u308b\u300d\u306e\u30c1\u30a7\u30c3\u30af\u3092\u5916\u3057\u307e\u3059\u3002<br>  \u300c\u5834\u6240\u300d\u306f\u5404\u81ea\u304c\u8aad\u307f\u66f8\u304d\u3067\u304d\u308b\u30d5\u30a9\u30eb\u30c0\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<br>  \u300c\u540d\u524d\u300d\u306fSimpleClient\u3068\u3057\u307e\u3059\u3002<br>\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u2192\u65e2\u5b58\u306e\u9805\u76ee\u306e\u8ffd\u52a0\u3092\u9078\u3073<a href=\"https:\/\/www.oji-koji.com\/pro-files\/CommonWin.zip\">stdThread.cpp, stdThread.h<\/a>\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<br>\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u2192\u65b0\u898f\u306e\u9805\u76ee\u306e\u8ffd\u52a0\u3092\u9078\u3073SimpleClient.cpp\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<br>\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u2192\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u69cb\u6210\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u6587\u5b57\u30bb\u30c3\u30c8\u304c\u300c\u30de\u30eb\u30c1 \u30d0\u30a4\u30c8\u6587\u5b57\u30bb\u30c3\u30c8\u3092<br>\u4f7f\u7528\u3059\u308b\u300d\u306b\u306a\u3063\u3066\u3044\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3057\u3066\u304f\u3060\u3055\u3044\u3002<br>\u30d7\u30e9\u30c3\u30c8\u30d5\u30a9\u30fc\u30e0\u306f64bits(x64)\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/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\">\u4e0a\u56f3\u306e\u95a2\u6570\u3092main\u3067\u9806\u756a\u306b\u547c\u3073\u51fa\u3057\u307e\u3059\u3002<br>\u3053\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u306f\u3001\u307e\u3060\u30de\u30eb\u30c1\u30b9\u30ec\u30c3\u30c9\u5316\u3057\u3066\u3044\u307e\u305b\u3093\u3002<br><\/p>\n\n\n\n<p class=\"source_code\">\u3010SimpleClient.cpp\u3011\n#include   \u201cstdThread.h\u201d\n#include    &lt;conio.h&gt;            \/\/ \u30ad\u30fc\u5165\u529b\u691c\u67fb\u306e\u305f\u3081\n\n#ifdef _MSC_VER                  \/\/ Windows\u306e\u3068\u304d\n#define DISABLE_C4996   __pragma(warning(push)) __pragma(warning(disable:4996))\n#define ENABLE_C4996    __pragma(warning(pop))\n#else                            \/\/ Linux\u306e\u3068\u304d\n#define DISABLE_C4996\n#define ENABLE_C4996\n#endif\n\n\/\/ \u30e1\u30cb\u30e5\u30fc\u3067\u4f7f\u7528\u3059\u308b\u6587\u5b57\n#define        CMD_QUIT_CHAR        &#8216;q&#8217;\n#define        CMD_SEND_MSG_CHAR    &#8216;m&#8217;\n\n\/\/ \u95a2\u6570\u306e\u5ba3\u8a00\nBOOL InitSocketLib();                                         \/\/ WinSockDLL\u306e\u521d\u671f\u5316\nBOOL UninitSocketLib();                                       \/\/ WinSockDLL\u306e\u7d42\u4e86\nBOOL CreateAndConnectSocket(LPCSTR szAddress, WORD wPort);    \/\/ \u30bd\u30b1\u30c3\u30c8\u306e\u4f5c\u6210\u3068\u63a5\u7d9a\u51e6\u7406\nBOOL DoSend(char *pcData, int iSize);                         \/\/ \u9001\u4fe1\u51e6\u7406\u306e\u5b9f\u884c\nBOOL DestroySocket(SOCKET &amp;fd);                               \/\/ \u5207\u65ad\u3068\u30bd\u30b1\u30c3\u30c8\u306e\u7834\u68c4\nvoid Stop();                                                  \/\/ \u3059\u3079\u3066\u306e\u30bd\u30b1\u30c3\u30c8\u3092\u7834\u68c4\u3059\u308b\nvoid DispMenu();                                              \/\/ \u30e1\u30cb\u30e5\u30fc\u306e\u8868\u793a\nint     GetKeyString(LPSTR pszString, int iSize);             \/\/ \u30ad\u30fc\u30dc\u30fc\u30c9\u5165\u529b\u6587\u5b57\u306e\u53d6\u5f97\n\n\/\/ \u5909\u6570\u306e\u5ba3\u8a00\nSOCKET        m_fdClient;                                     \/\/ \u63a5\u7d9a\u3001\u901a\u4fe1\u7528\u30bd\u30b1\u30c3\u30c8\n\nint main(int argc, char *argv[])\n{\n    char    szKeyInBuff[81];\n    int     iSize;\n    LPBYTE  pbDest = NULL;\n\n    m_fdClient = INVALID_SOCKET;\n    \/\/ \u8d77\u52d5\u30d1\u30e9\u30e1\u30fc\u30bf\u30c1\u30a7\u30c3\u30af\n    if (argc != 3)\n    {\n        fprintf(stderr, &#8220;Usage:  %s &lt;ServerAddress&gt; &lt;ServerPort&gt;\\n&#8221;, argv[0]);\n        goto L_END;\n    }\n    \/\/ \u30bd\u30b1\u30c3\u30c8\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u521d\u671f\u5316\n    if (InitSocketLib() == FALSE)\n        goto L_END;\n    \/\/ \u30bd\u30b1\u30c3\u30c8\u306e\u4f5c\u6210\u3068\u63a5\u7d9a\u51e6\u7406\n    \/\/ m_fdClient\u304c\u63a5\u7d9a\u6e08\u307f\u72b6\u614b\u306b\u306a\u308b\n    if (CreateAndConnectSocket(argv[1], (WORD)atol(argv[2])) == FALSE)\n        goto L_END;\n    \/\/ \u30e1\u30cb\u30e5\u30fc\u306e\u8868\u793a\n    DispMenu();\n    while (1)\n    {\n        \/\/ \u30ad\u30fc\u30dc\u30fc\u30c9\u304b\u3089\u5165\u529b\u3055\u308c\u305f\u6587\u5b57\u5217\u304c&#8217;q&#8217;\u306a\u3089\u7d42\u4e86\n        \/\/ &#8216;m&#8217;\u306a\u3089\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u5165\u529b\u5f8c\u306f\u9001\u4fe1\u3059\u308b        \n        switch (GetKeyString(szKeyInBuff, sizeof(szKeyInBuff)))\n        {\n            case 0:                            \/\/ \u5165\u529b\u306a\u3057\u3001\u4f55\u3082\u3057\u306a\u3044\n                break;\n            case CMD_QUIT_CHAR:                \/\/ &#8216;q&#8217;\u5165\u529b\u7d42\u4e86\n                goto L_END;\n            case CMD_SEND_MSG_CHAR:            \/\/ &#8216;m&#8217;\u5165\u529bszKeyInBuff\u306b\u6587\u5b57\u5217\u304c\u683c\u7d0d\u3055\u308c\u3066\u3044\u308b\n                DoSend(szKeyInBuff, strlen(szKeyInBuff));\n                \/\/ \u30e1\u30cb\u30e5\u30fc\u306e\u8868\u793a\n                DispMenu();\n                break;\n        }\n    }\nL_END:\n    \/\/ \u5207\u65ad\u3068\u3059\u3079\u3066\u306e\u30bd\u30b1\u30c3\u30c8\u306e\u7834\u68c4\n    Stop();\n    \/\/ \u30bd\u30b1\u30c3\u30c8\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u958b\u653e\n    UninitSocketLib();\n    return(0);\n}<\/p>\n\n\n\n<p class=\"program_discription\">Windows\u306e\u307f\u306b\u5fc5\u8981\u306a\u3001\u30bd\u30b1\u30c3\u30c8\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u521d\u671f\u5316\u3068\u7d42\u4e86\u306e<br>\u305f\u3081\u306e\u95a2\u6570\u3067\u3059\u3002<\/p>\n\n\n\n<p class=\"source_code\">\u3010SimpleClient.cpp\u3011\n\n\/\/ \u5fc5\u8981\u3068\u3059\u308bWINSOCK.DLL(WSOCK32.DLL \u306e\u30d0\u30fc\u30b8\u30e7\u30f3)\n#define     VERSION_RECESTED    MAKEWORD(2, 0)    \n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\/\/ function\n\/\/    \u30bd\u30b1\u30c3\u30c8\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30ed\u30fc\u30c9\n\/\/ parameter\n\/\/    \u306a\u3057\n\/\/ retun\n\/\/    \u306a\u3057\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\nBOOL InitSocketLib()\n{\n    WORD    wVersionRequested;        \/\/ \u30d0\u30fc\u30b8\u30e7\u30f3\u60c5\u5831\u683c\u7d0d\u30a8\u30ea\u30a2\n    WSADATA    wsaData;               \/\/ WinSock \u60c5\u5831\u683c\u7d0d\u30a8\u30ea\u30a2\n    BOOL    fRet;\n\n    wVersionRequested = VERSION_RECESTED;        \/\/ \u521d\u671f\u5316\u51e6\u7406\n    fRet = (WSAStartup(wVersionRequested, &amp;wsaData) == 0) ? TRUE : FALSE;\n    return(fRet);\n}\n\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\/\/ function\n\/\/    \u30bd\u30b1\u30c3\u30c8\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u958b\u653e\n\/\/ parameter\n\/\/    \u306a\u3057\n\/\/ retun\n\/\/    \u306a\u3057\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\nBOOL UninitSocketLib()\n{\n    BOOL    fRet;\n\n    fRet = (WSACleanup() == 0) ? TRUE : FALSE;    \/\/ \u89e3\u653e\u51e6\u7406\n    return(fRet);\n}<\/p>\n\n\n\n<p class=\"program_discription\">\u8d77\u52d5\u5f15\u6570\u3067\u6307\u5b9a\u3055\u308c\u305f\u30a2\u30c9\u30ec\u30b9\u3001\u30dd\u30fc\u30c8\u756a\u53f7\u3092\u6307\u5b9a\u3057getaddrinfo\u3092\u547c\u3073\u51fa\u3057\u307e\u3059\u3002<br>\u5f97\u3089\u308c\u305f\u60c5\u5831\u3092\u4f7f\u3063\u3066\u30bd\u30b1\u30c3\u30c8\u3092\u4f5c\u6210\u3057\u3001\u63a5\u7d9a\u3092\u8981\u6c42\u3057\u307e\u3059\u3002<br>\u63a5\u7d9a\u304c\u5931\u6557\u3057\u305f\u6642\u306f\u3001\u6b21\u306e\u60c5\u5831\u3092\u4f7f\u3063\u3066\u30bd\u30b1\u30c3\u30c8\u4f5c\u6210\u3001\u63a5\u7d9a\u8981\u6c42\u3092\u884c\u3044\u307e\u3059\u3002<br>\u6210\u529f\u3057\u305f\u6642\u306f\u63a5\u7d9a\u6e08\u307f\u30bd\u30b1\u30c3\u30c8\u3092m_fdClient\u306b\u683c\u7d0d\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"source_code\">\u3010SimpleClient.cpp\u3011\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\/\/ function\n\/\/  TCP\u30bd\u30b1\u30c3\u30c8\u306e\u4f5c\u6210, connect\u306e\u5b9f\u884c\n\/\/  \u63a5\u7d9a\u6210\u529f\u3057\u305f\u3068\u304d\u30bd\u30b1\u30c3\u30c8\u306fm_fdClient\u306b\u683c\u7d0d\u3059\u308b\n\/\/ parameter\n\/\/  LPCSTR       szAddress      [in]\u63a5\u7d9a\u5148\u30a2\u30c9\u30ec\u30b9\n\/\/  WORD         wPort          [in]\u63a5\u7d9a\u5148\u30dd\u30fc\u30c8\n\/\/ return\n\/\/  TRUE\/FALSE\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\nBOOL CreateAndConnectSocket(LPCSTR szAddress, WORD wPort)\n{\n    BOOL            fRet = TRUE;\n    SOCKET    fd;\n    struct addrinfo        hints, *pres = NULL, *pTemp = NULL;\n    char            szPort[NI_MAXSERV];\n\n    memset(&amp;hints, 0, sizeof(hints));\n    hints.ai_socktype = SOCK_STREAM;        \/\/ TCP\n    DISABLE_C4996\n    sprintf(szPort, &#8220;%d&#8221;, wPort);           \/\/ \u30dd\u30fc\u30c8\u756a\u53f7=\u30b5\u30fc\u30d3\u30b9\n    ENABLE_C4996\n\n    \/\/ \u30a2\u30c9\u30ec\u30b9\u3092\u6307\u5b9a\u3057\u3066getaddrinfo\u3092\u5b9f\u884c \u63a5\u7d9a\u5148\u30a2\u30c9\u30ec\u30b9\u60c5\u5831\u3092\u5f97\u308b\n    if (getaddrinfo(szAddress, szPort, &amp;hints, &amp;pres) == 0)\n    {\n        pTemp = pres;\n        while (pTemp != NULL)\n        {\n            \/\/ socket, connect\u3092\u5b9f\u884c\n            if ((fd = socket(pTemp-&gt;ai_family, pTemp-&gt;ai_socktype, pTemp-&gt;ai_protocol)) == INVALID_SOCKET)\n                goto L_NEXT;\n            if (connect(fd, pTemp-&gt;ai_addr, (int)pTemp-&gt;ai_addrlen) == SOCKET_ERROR)\n            {\n                fprintf(stderr, &#8220;Err:connect %d\\n&#8221;, WSAGetLastError());\n                DestroySocket(fd);\n                goto L_NEXT;\n            }\n            \/\/ \u63a5\u7d9a\u6210\u529f\u3057\u305f\u306e\u3067\u3053\u306e\u30bd\u30b1\u30c3\u30c8\u63a1\u7528\u3059\u308b\u3053\u3068\u306b\u3057\u3066\u629c\u3051\u308b\n            fRet = TRUE;\n            break;\nL_NEXT:\n            pTemp = pTemp-&gt;ai_next;\n        }\n        freeaddrinfo(pres);\n    }\n    if (fd == INVALID_SOCKET)    \/\/ \u63a5\u7d9a\u306b\u5931\u6557\n    {\n        fprintf(stderr, &#8220;Err:connect %d\\n&#8221;, WSAGetLastError());\n        fRet = FALSE;\n        goto L_END;\n    }\n    m_fdClient = fd;            \/\/ \u63a5\u7d9a\u6e08\u307f\u72b6\u614b\u306e\u30bd\u30b1\u30c3\u30c8\u3092m_fdClient\u306b\u683c\u7d0d\n\nL_END:\n    return(fRet);\n}<\/p>\n\n\n\n<p class=\"program_discription\">\u6e21\u3055\u308c\u305f\u30c7\u30fc\u30bf\u3092\u30bd\u30b1\u30c3\u30c8\u306b\u9001\u4fe1\u3057\u307e\u3059\u3002<br>\u3053\u3053\u3067\u306f\u3001\u9001\u4fe1\u30b5\u30a4\u30ba(send\u306b\u6e21\u305b\u308b\u30b5\u30a4\u30ba)\u306b\u3064\u3044\u3066\u30c1\u30a7\u30c3\u30af\u3092\u3057\u3066\u3044\u307e\u305b\u3093\u3002<br>\u9001\u4fe1\u53ef\u80fd\u30b5\u30a4\u30ba\u3092\u8abf\u3079\u308b\u3079\u304d\u3067\u3059\u304c\u3001\u30ad\u30fc\u30dc\u30fc\u30c9\u304b\u3089\u306e<br>\u5165\u529b\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u305d\u308c\u307b\u3069\u5927\u304d\u304f\u306a\u3044\u3068\u3044\u3046\u3053\u3068\u3067\u7701\u7565\u3057\u3066\u3044\u307e\u3059\u3002<br>(getsockopt\u306b\u30d1\u30e9\u30e1\u30fc\u30bfSO_MAX_MSG_SIZE\u3092\u6307\u5b9a\u3057\u3066\u547c\u3073\u51fa\u305b\u3070\u8abf\u3079\u3089\u308c\u307e\u3059)<\/p>\n\n\n\n<p class=\"source_code\">\u3010SimpleClient.cpp\u3011\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\/\/ function\n\/\/    send\u306e\u5b9f\u884c\n\/\/ parameter\n\/\/    char       *pcData      [in]\u9001\u4fe1\u30c7\u30fc\u30bf\n\/\/    int        iSize        [in]\u30c7\u30fc\u30bf\u6570\n\/\/ return\n\/\/    TRUE\/FALSE\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\nBOOL DoSend(char *pcData, int iSize)\n{\n    BOOL            fRet = TRUE;\n    fd_set          wfds;\n    struct timeval  tv;\n\n    while (1)\n    {\n        tv.tv_sec = 0;\n        tv.tv_usec = 10 * 1000;                        \/\/ 10msec\n        FD_ZERO(&amp;wfds);\n        FD_SET(m_fdClient, &amp;wfds);                     \/\/ \u9001\u4fe1\u53ef\u80fd\u304b\u76e3\u8996\n        select(FD_SETSIZE, NULL, &amp;wfds, NULL, &amp;tv);    \/\/ \u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u307e\u3067Sleep\u3068\u540c\u7b49\n        if (FD_ISSET(m_fdClient, &amp;wfds))               \/\/ \u9001\u4fe1\u53ef\u80fd\u306a\u3089send\u5b9f\u65bd\n        {\n            if (send(m_fdClient, pcData, iSize, 0) != iSize)\n            {\n                fprintf(stderr, &#8220;Err:send %d\\n&#8221;, WSAGetLastError());\n                fRet = FALSE;\n            }\n            break;\n        }\n    }\n    return(fRet);\n}<\/p>\n\n\n\n<p class=\"program_discription\">\u30bd\u30b1\u30c3\u30c8\u3092\u7834\u68c4\u3059\u308b\u95a2\u6570\u3067\u3059\u3002<br>DestroySocket\u306f\u6307\u5b9a\u3057\u305f\u30bd\u30b1\u30c3\u30c8\u3092\u7834\u68c4\u3057\u307e\u3059\u3002<br>Stop\u306f\u3059\u3079\u3066\u306e\u30bd\u30b1\u30c3\u30c8\u3092\u7834\u68c4\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"source_code\">\u3010SimpleClient.cpp\u3011\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\/\/ function\n\/\/    TCP\u30bd\u30b1\u30c3\u30c8\u306e\u7834\u68c4\n\/\/ parameter\n\/\/    SOCKET        &amp;fd[in\/out]\u7834\u68c4\u3059\u308b\u30bd\u30b1\u30c3\u30c8\n\/\/ return\n\/\/    TRUE\/FALSE\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\nBOOL DestroySocket(SOCKET &amp;fd)\n{\n    if (fd != INVALID_SOCKET)\n    {\n        fprintf(stderr, &#8220;DestroySocket()\\n&#8221;);\n        shutdown(fd, SD_BOTH);     \/\/ \u53d7\u4fe1\u3082\u9001\u4fe1\u3082\u505c\u6b62\n        closesocket(fd);\n        fd = INVALID_SOCKET;\n    }\n    return(TRUE);\n}\n\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\/\/ function\n\/\/    \u3059\u3079\u3066\u306e\u30bd\u30b1\u30c3\u30c8\u306e\u5207\u65ad\u3001\u7834\u68c4\n\/\/ parameter\n\/\/    \u306a\u3057\n\/\/ return\n\/\/    \u306a\u3057\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\nvoid Stop()\n{\n    int        ii;\n\n    fprintf(stderr, &#8220;Stop()\\n&#8221;);\n    DestroySocket(m_fdClient);\n}<\/p>\n\n\n\n<p class=\"program_discription\">\u30bd\u30b1\u30c3\u30c8\u3068\u306f\u95a2\u4fc2\u306e\u306a\u3044\u3001\u30e1\u30cb\u30e5\u30fc\u3092\u8868\u793a\u3059\u308b\u95a2\u6570\u3068\u30ad\u30fc\u30dc\u30fc\u30c9\u304b\u3089\u306e<br>\u5165\u529b\u3092\u8abf\u3079\u308b\u95a2\u6570\u3067\u3059\u3002<br>_kbhit\u3067\u30ad\u30fc\u306e\u62bc\u4e0b\u3092\u30c1\u30a7\u30c3\u30af\u3092\u3057\u3001\u62bc\u3055\u308c\u305f\u6587\u5b57\u306b\u3088\u3063\u3066\u52d5\u4f5c\u3092<br>\u5909\u3048\u3066\u3044\u307e\u3059\u3002&#8217;m&#8217;\u304c\u62bc\u3055\u308c\u305f\u3068\u304d\u306f\u6587\u5b57\u5217\u306e\u5165\u529b\u3092\u5f85\u3061\u307e\u3059\u3002<br>\u3053\u308c\u3089\u306e\u51e6\u7406\u306fWindows\u72ec\u81ea\u3067\u3059\u306e\u3067Linux\u7248\u306e\u6642\u306b\u306f\u9055\u3046\u65b9\u6cd5\u3092<br>\u8003\u3048\u308b\u3053\u3068\u306b\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"source_code\">\u3010SimpleClient.cpp\u3011\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\/\/ function\n\/\/    \u30e1\u30cb\u30e5\u30fc\u306e\u8868\u793a\n\/\/ parameter\n\/\/    \u306a\u3057\n\/\/ return\n\/\/    \u306a\u3057\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\nvoid DispMenu()\n{\n    fprintf(stderr, &#8220;%c:quit %c:\u30e1\u30c3\u30bb\u30fc\u30b8\u9001\u4fe1 : &#8220;, CMD_QUIT_CHAR, CMD_SEND_MSG_CHAR);\n}\n\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\/\/ function\n\/\/    \u30ad\u30fc\u30dc\u30fc\u30c9\u5165\u529b(\u6539\u884c\u307e\u3067)\u306e\u53d6\u5f97\n\/\/        \u5165\u529b\u304c\u306a\u3044\u3068\u304d\u306f\u3059\u3050\u306b\u30ea\u30bf\u30fc\u30f3\n\/\/ parameter\n\/\/    LPSTR        pszString    [in\/out]\u30c7\u30fc\u30bf\u683c\u7d0d\u7528\u30d0\u30c3\u30d5\u30a1\n\/\/    int          iSize        [in]\u30d0\u30c3\u30d5\u30a1\u306e\u30b5\u30a4\u30ba\n\/\/ return\n\/\/    0:\u5165\u529b\u306a\u3057 CMD_QUIT_CHAR:\u7d42\u4e86 CMD_SEND_MSG_CHAR:\u30e1\u30c3\u30bb\u30fc\u30b8\u9001\u4fe1\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\nint GetKeyString(LPSTR pszString, int iSize)\n{\n    int        iRet = 0;\n\n    memset(pszString, 0, iSize);\n    if (_kbhit())\n    {\n        switch (_getch())\n        {\n            case CMD_QUIT_CHAR:\n                iRet = CMD_QUIT_CHAR;\n                break;\n            case CMD_SEND_MSG_CHAR:\n                fprintf(stderr, &#8220;\\n\u9001\u4fe1\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044 : &#8220;);\n                fgets(pszString, iSize, stdin);\n                if (strlen(pszString) &gt; 0)\n                {\n                    \/\/ \u6539\u884c\u307e\u3067\u8aad\u307f\u8fbc\u3093\u3067\u3044\u308b\u306e\u3067\n                    if (pszString[strlen(pszString) &#8211; 1] == &#8216;\\n&#8217;)\n                        pszString[strlen(pszString) &#8211; 1] = 0;\n                    iRet = CMD_SEND_MSG_CHAR;\n                }\n                break;\n            default:\n                break;\n        }\n    }\n    return(iRet);\n}<\/p>\n\n\n\n<p class=\"program_discription\">\u3053\u308c\u3067SimpleClient.cpp\u304c\u5b8c\u6210\u3067\u3059\u3002<br>\u30d3\u30eb\u30c9\u3057\u3066\u52d5\u304b\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<br>\u6298\u89d2\u3067\u3059\u306e\u3067\u3001\u30b5\u30fc\u30d0\u5074\u306fSimpleServer\u3092\u4f7f\u3044\u307e\u3057\u3087\u3046\u3002<br>\u30dd\u30fc\u30c8\u306f10000\u304f\u3089\u3044\u3092\u4f7f\u3063\u3066\u307f\u307e\u3057\u3087\u3046\u3002<br>\u6b21\u306e\u7d44\u307f\u5408\u308f\u305b\u3067\u52d5\u4f5c\u3092\u78ba\u8a8d\u3057\u307e\u3057\u3087\u3046\u3002<br>SimpleServer Windows &lt;==== SimpleClient Windows<br>SimpleServer Linux   &lt;==== SimpleClient Windows<br>\u6587\u5b57\u5217\u306f\u3061\u3083\u3093\u3068\u9001\u4fe1\u53d7\u4fe1\u3067\u304d\u308b\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n\n\n\n<div class=\"wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-1 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-image is-resized\"><a href=\"https:\/\/www.oji-koji.com\/wp-content\/uploads\/2019\/05\/WinSrvA.png\" data-rel=\"lightbox-gallery-yj7LXCP8\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.oji-koji.com\/wp-content\/uploads\/2019\/05\/WinSrvA-1024x749.png\" alt=\"\" class=\"wp-image-824\" width=\"256\" height=\"187\" srcset=\"https:\/\/www.oji-koji.com\/wp-content\/uploads\/2019\/05\/WinSrvA-1024x749.png 1024w, https:\/\/www.oji-koji.com\/wp-content\/uploads\/2019\/05\/WinSrvA-300x219.png 300w, https:\/\/www.oji-koji.com\/wp-content\/uploads\/2019\/05\/WinSrvA-768x562.png 768w, https:\/\/www.oji-koji.com\/wp-content\/uploads\/2019\/05\/WinSrvA.png 1392w\" sizes=\"auto, (max-width: 256px) 100vw, 256px\" \/><\/a><figcaption>SimpleServer for Windows<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image is-resized\"><a href=\"https:\/\/www.oji-koji.com\/wp-content\/uploads\/2019\/05\/LinuxSrvB.png\" data-rel=\"lightbox-gallery-yj7LXCP8\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.oji-koji.com\/wp-content\/uploads\/2019\/05\/LinuxSrvB-1024x772.png\" alt=\"\" class=\"wp-image-828\" width=\"256\" height=\"193\" srcset=\"https:\/\/www.oji-koji.com\/wp-content\/uploads\/2019\/05\/LinuxSrvB-1024x772.png 1024w, https:\/\/www.oji-koji.com\/wp-content\/uploads\/2019\/05\/LinuxSrvB-300x226.png 300w, https:\/\/www.oji-koji.com\/wp-content\/uploads\/2019\/05\/LinuxSrvB-768x579.png 768w, https:\/\/www.oji-koji.com\/wp-content\/uploads\/2019\/05\/LinuxSrvB.png 1396w\" sizes=\"auto, (max-width: 256px) 100vw, 256px\" \/><\/a><figcaption>SimpleServer for Linux<\/figcaption><\/figure>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-image is-resized\"><a href=\"https:\/\/www.oji-koji.com\/wp-content\/uploads\/2019\/05\/WinClA.png\" data-rel=\"lightbox-gallery-yj7LXCP8\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.oji-koji.com\/wp-content\/uploads\/2019\/05\/WinClA-1024x750.png\" alt=\"\" class=\"wp-image-825\" width=\"256\" height=\"188\" srcset=\"https:\/\/www.oji-koji.com\/wp-content\/uploads\/2019\/05\/WinClA-1024x750.png 1024w, https:\/\/www.oji-koji.com\/wp-content\/uploads\/2019\/05\/WinClA-300x220.png 300w, https:\/\/www.oji-koji.com\/wp-content\/uploads\/2019\/05\/WinClA-768x563.png 768w, https:\/\/www.oji-koji.com\/wp-content\/uploads\/2019\/05\/WinClA.png 1389w\" sizes=\"auto, (max-width: 256px) 100vw, 256px\" \/><\/a><figcaption>SimpleClient for Windows<br>\u65e5\u672c\u8a9e\u306e\u9001\u4fe1\u53d7\u4fe1\u3082\u6b63\u3057\u304f\u3067\u304d\u3066\u3044\u307e\u3059<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image is-resized\"><a href=\"https:\/\/www.oji-koji.com\/wp-content\/uploads\/2019\/05\/WinClB.png\" data-rel=\"lightbox-gallery-yj7LXCP8\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.oji-koji.com\/wp-content\/uploads\/2019\/05\/WinClB-1024x775.png\" alt=\"\" class=\"wp-image-829\" width=\"256\" height=\"194\" srcset=\"https:\/\/www.oji-koji.com\/wp-content\/uploads\/2019\/05\/WinClB-1024x775.png 1024w, https:\/\/www.oji-koji.com\/wp-content\/uploads\/2019\/05\/WinClB-300x227.png 300w, https:\/\/www.oji-koji.com\/wp-content\/uploads\/2019\/05\/WinClB-768x581.png 768w, https:\/\/www.oji-koji.com\/wp-content\/uploads\/2019\/05\/WinClB.png 1389w\" sizes=\"auto, (max-width: 256px) 100vw, 256px\" \/><\/a><figcaption>SimpleClient for Windows<br>\u65e5\u672c\u8a9e\u306e\u9001\u53d7\u4fe1\u304c\u305f\u3060\u3057\u304f\u3042\u308a\u307e\u305b\u3093<\/figcaption><\/figure>\n<\/div>\n<\/div>\n\n\n\n<p class=\"program_discription\">\u65e5\u672c\u8a9e\uff08\u5168\u89d2\u6587\u5b57\uff09\u306e\u9001\u53d7\u4fe1\u304c\u3001SimpleServer Linux &gt;==== SimpleClient Windows<br>\u3067\u306f\u3046\u307e\u304f\u3044\u3063\u3066\u3044\u307e\u305b\u3093\u3002<br>\u3053\u308c\u306f\u3001Linux\u3068Windows\u3067\u306f\u6f22\u5b57\u306e\u6271\u3044(\u6587\u5b57\u30b3\u30fc\u30c9)\u304c\u9055\u3046\u305f\u3081\u3067\u3059\u3002<br>  Windows\u306f\u300c\u30de\u30eb\u30c1\u30d0\u30a4\u30c8\u6587\u5b57\u30bb\u30c3\u30c8\u3092\u4f7f\u7528\u3059\u308b\u300d\u3068\u3057\u305f\u306e\u3067Sift-JIS<br>  Linux\u306fUTF-8<br>\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3067\u306f\u3001\u901a\u4fe1\u3059\u308b\u76f8\u624b\u540c\u58eb\u3067\u8272\u3005\u7d04\u675f\u3092\u304d\u3081\u306a\u3051\u308c\u3070<br>\u6b63\u3057\u304f\u3001\u901a\u4fe1(\u4f1a\u8a71)\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u305b\u3093\u3002<br>\u540c\u3058\u30ec\u30a4\u30e4(\u4eca\u306e\u5834\u5408\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u540c\u58eb)\u3067\u306e\u7d04\u675f\u4e8b\u3092\u30d7\u30ed\u30c8\u30b3\u30eb\u3068\u8a00\u3044\u307e\u3059\u3002<br>\u4eca\u56de\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u306e\u6587\u5b57\u5217\u306b\u3064\u3044\u3066\u306f\u3001<br>  \u30fb\u6587\u5b57\u30b3\u30fc\u30c9\u3068\u3057\u3066\u306fUTF-8\u3092\u4f7f\u3046<br>  \u30fb\u6539\u884c\u30b3\u30fc\u30c9\u306fLF(\\n)\u3092\u4f7f\u3046<br>\u3068\u3044\u3046\u7d04\u675f(\u30d7\u30ed\u30c8\u30b3\u30eb)\u3068\u3057\u307e\u3059\u3002<br>\u30b3\u30fc\u30c9\u5909\u63db\u306b\u3064\u3044\u3066\u306f\u3001SimpleClient for Linux\u3092\u4f5c\u3063\u305f\u5f8c\u306b\u5bfe\u5fdc\u3059\u308b\u3053\u3068\u306b\u3057\u307e\u3059\u3002<br>(*)Windows\u3067Unicode\u3068\u6307\u5b9a\u3057\u3066\u3082UTF-16\u3067\u3059\u306e\u3067\u3001\u5909\u63db\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n\n\n\n<p><a href=\"https:\/\/www.oji-koji.com\/pro-files\/SimpleClientWin.zip\">\u30d7\u30ed\u30b8\u30a7\u30af\u30c8SimpleClient for Windows(zip)<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u300c\u30d5\u30a1\u30a4\u30eb\u300d\u2192\u300c\u65b0\u898f\u4f5c\u6210\u300d\u2192\u300cVisualC++\u300d\u2192\u300c\u7a7a\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u300d \u300c\u30bd\u30ea\u30e5\u30fc\u30b7\u30e7\u30f3\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u4f5c\u6210\u3059\u308b\u300d\u306e\u30c1\u30a7\u30c3\u30af\u3092\u5916\u3057\u307e\u3059\u3002 \u300c\u5834\u6240\u300d\u306f\u5404\u81ea\u304c\u8aad\u307f\u66f8\u304d\u3067\u304d\u308b\u30d5\u30a9\u30eb\u30c0\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002 \u300c\u540d\u524d\u300d\u306fSimpleCl [&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=800","footnotes":""},"categories":[6],"tags":[],"class_list":["post-800","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\/800","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=800"}],"version-history":[{"count":29,"href":"https:\/\/www.oji-koji.com\/index.php?rest_route=\/wp\/v2\/posts\/800\/revisions"}],"predecessor-version":[{"id":3095,"href":"https:\/\/www.oji-koji.com\/index.php?rest_route=\/wp\/v2\/posts\/800\/revisions\/3095"}],"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=800"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oji-koji.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=800"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oji-koji.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=800"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}