IBM Developer is your one-stop location for getting hands-on training and learning in-demand skills on relevant technologies such as generative AI, data science, AI, and open source.
Section: Linux Programmer's Manual (2) Updated: 2008-07-14 Index JM Home Page roff page åå send, sendto, sendmsg - ã½ã±ããã¸ã¡ãã»ã¼ã¸ãéã æ¸å¼ #include <sys/types.h> #include <sys/socket.h> ssize_t send(int s, const void *buf, size_t len, int flags); ssize_t sendto(int s, const void *buf, size_t len, int flags, const struct sockaddr *to, socklen_t tolen); ssize_t sendmsg(int s, const struct msghdr *msg, int
ãã³ããããã³ã°ã§UDPãã±ããã®åä¿¡ãå¾ ã¤ãµã³ãã« é常è¨å®ã§ã¯ãrecvé¢æ°ã¯ãã¼ã¿ãå±ãã¾ã§ããããã³ã°ãã¾ãã è¤æ°ã®ã½ã±ãããæ±ãããã°ã©ã ãããã®ä»å ¥åã¨ä½µç¨ãããããªããã°ã©ã ã§ã¯ãããã¯ãããã«recvé¢æ°ã使ãããå ´åãããã¾ãã Linuxã§ã¯ãioctlé¢æ°ã«FIONBIOã渡ããã¨ã«ãããããããã³ã°/ãã³ããããã³ã°ã®è¨å®ãè¡ãã¾ãã ãã³ããããã³ã°ç¶æ ã«è¨å®ããã½ã±ããã§ãã¼ã¿ãç¡ãæã«recvï¼ãããã¯read,recvfromï¼ãè¡ãã¨recvé¢æ°ã¯ã¨ã©ã¼ãè¿ãã¾ãã recvãã¨ã©ã¼ãè¿ããæã®errnoã®å¤ãEAGAINã§ããå ´åã«ã¯ããã åã«ãã¼ã¿ãç¡ãã¨ããäºãããããã¦ãã¾ãã errnoã¯ãint errnoã¨ãã¦å®£è¨ããã¦ããã°ãã¼ãã«å¤æ°ã§ãã ã¨ã©ã¼ãçºçããæã«ã¨ã©ã¼å 容ãç¥ãããå¤ãã»ããããã¾ãã ä¸è¨ãµã³ãã«ã§ã¯ããã¼ã¿ãç¡ãã¨ã
[ ECHOãµã¼ã ããã«ãããã»ã¹ã¨ã·ã°ãã«ã ] åä½ç¢ºèªã¯ãã¹ã¦ Linux + gcc ã§è¡ã£ã¦ãã¾ãã >>[ 0x01 ] ãã£ã¨ãã·ã³ãã«ãªechoãµã¼ã http://ruffnex.oc.to/kenji/src/echo.c [kenji@localhost test]$ gcc -Wall echo.c [kenji@localhost test]$ ./a.out 8080 port=8080 ready for accept ããã§telnetã§ãã®ãµã¼ãã«ç¹ãã§ã¿ãã (server) (telnet) accept:127.0.0.1:32812 | [kenji@localhost test]$ telnet localhost 8080 [client] dd | Trying 127.0.0.1... | Connected to localhost.
ç®æ¬¡ ç®æ¬¡ ã¯ããã« ã½ã±ããã®åºç¤ç¥è ç¹å¾´ã¨ç¨é IPã¢ãã¬ã¹ã¨ã³ã³ãã¥ã¼ã¿ã®åå ãã¼ãçªå· TCPã¨UDP ãããã¯ã¼ã¯ãã¤ããªã¼ã ã½ã±ããã®ä½¿ãæ¹ ãµã¼ããã¯ã©ã¤ã¢ã³ãã¨TCPæ¥ç¶ããæé ã½ã±ãããå¾ã ãã¼ãçªå·ãæå®ãã ã½ã±ãããæ¥ç¶è¦æ±ã®ç£è¦ã¢ã¼ãã«ãã accept()ã§æ¥ç¶è¦æ±ãåçããã ã¯ã©ã¤ã¢ã³ãããµã¼ãã¨TCPæ¥ç¶ããæé ã½ã±ãããå¾ã ãµã¼ãã«æ¥ç¶ããã TCPæ¥ç¶å¾ã®ãã¼ã¿ã®åéä¿¡ ãã¼ã¿ã®éä¿¡ ãã¼ã¿ã®åä¿¡ TCPæ¥ç¶ã®åæ UDPã§éä¿¡ããæé ã½ã±ããã確ä¿ãã ãã¼ãçªå·ã®æå® ãã¼ã¿ã®éä¿¡ ãã¼ã¿ã®åä¿¡ ååããIPã¢ãã¬ã¹ãå¾ãæ¹æ³ IPã¢ãã¬ã¹ããååãå¾ãæ¹æ³ select()ã§ããããã³ã°ãåé¿ãã UNIXç³»OSã§ã½ã±ããã使ãå ´åã®æ³¨æ Windowsç³»OSã§ã½ã±ããã
select ã«ãããã«ãã¹ã¬ãããµã¼ã C è¨èªã«ãã㦠select ã®ä½¿ãæ¹ã説æãã¾ãã echo-server-select.c 117: int 118: main(){ 119: fd_set target_fds; 120: fd_set org_target_fds; 121: int sock_optval = 1; 122: int port = 5000; 123: /* ãªã¹ãã³ã°ã½ã±ãããä½æ */ 124: listening_socket = socket(AF_INET, SOCK_STREAM, 0); 125: 126: /* ã½ã±ãããªãã·ã§ã³è¨å® */ 127: if ( setsockopt(listening_socket, SOL_SOCKET, SO_REUSEADDR, 128: &sock_optval, sizeof(sock_opt
æ¥é ãã楽天ã®ãµã¼ãã¹ããå©ç¨ããã ãã¾ãã¦ãããã¨ããããã¾ãã ãµã¼ãã¹ããå©ç¨ããã ãã¦ããã¾ãã¨ãã大å¤ç³ã訳ãããã¾ããããç¾å¨ãç·æ¥ã¡ã³ããã³ã¹ãè¡ããã¦ããã ãã¦ããã¾ãã ã客æ§ã«ã¯ãç·æ¥ã®ã¡ã³ããã³ã¹ã«ããããè¿·æãããããã¦ãããèª ã«ç³ã訳ãããã¾ããã ã¡ã³ããã³ã¹ãçµäºæ¬¡ç¬¬ããµã¼ãã¹ã復æ§ãããã¾ãã®ã§ã ä»ãã°ãããå¾ ã¡ããã ãã¾ãããããé¡ãç³ãä¸ãã¾ãã
ãªãªã¼ã¹ãé害æ å ±ãªã©ã®ãµã¼ãã¹ã®ãç¥ãã
ææ°ã®äººæ°ã¨ã³ããªã¼ã®é ä¿¡
å¦çãå®è¡ä¸ã§ã
j次ã®ããã¯ãã¼ã¯
kåã®ããã¯ãã¼ã¯
lãã¨ã§èªã
eã³ã¡ã³ãä¸è¦§ãéã
oãã¼ã¸ãéã
{{#tags}}- {{label}}
{{/tags}}