BACKRUSH  À¯´Ð½º¸í·É  ´ÙÀ½  ÀÚ·á½Ç  Ascii Table   ¿ø°ÝÁ¢¼Ó  ´Þ·Â,½Ã°£   ÇÁ·Î¼¼½º   ½©
ÁöÇÏö³ë¼±   RFC¹®¼­   SUN FAQ   SUN FAQ1   C¸Þ´º¾ó   PHP¸Þ´º¾ó   ³Ê±¸¸®   ¾Æ½ºÅ°¿ùµå ¾ÆÀÌÇǼ­Ä¡

±Û¾´ÀÌ: daytime daytime client (Tcp) Á¶È¸¼ö: 8622


/*------------------------------------------------------------------------------------------------------------
ÆÄÀϸí : mydaytime.c
±â ´É : daytime ¼­ºñ½º¸¦ ¿ä±¸ÇÏ´Â TCP(¿¬°áÇü) Ŭ¶óÀ̾ðÆ®
ÄÄÆÄÀÏ : cc -o mydaytime mydaytime.c -lsocket -lnsl
½ÇÇ࿹ : mydaytime 192.203.144.11
-------------------------------------------------------------------------------------------------------------- */
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>

#define BUF_LEN 128

int main(int argc, char *argv[]) {
int s, n;
struct sockaddr_in server_addr;
char *haddr;
char buf[BUF_LEN+1];

if(argc != 2) {
printf("usage: %s ip_address\n", argv[0]);
return -1;
}
haddr = argv[1];

/* ¼ÒÄÏ »ý¼º */
if((s = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
printf("can't create socket\n");
return -1;
}

/* ¼­¹öÀÇ ¼ÒÄÏÁÖ¼Ò ±¸Á¶Ã¼ server_addrÀ» '\0'À¸·Î ÃʱâÈ­ */
bzero((char *)&server_addr, sizeof(server_addr));

/* server_addrÀÇ ÁÖ¼Ò ÁöÁ¤ */
server_addr.sin_family = AF_INET;
server_addr.sin_addr.s_addr = inet_addr(haddr);
server_addr.sin_port = htonl(13);

/* ¿¬°á¿äû */
if(connect(s, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) {
printf("can't connect.\n");
return -1;
}

/* ¼­¹ö°¡ º¸³»¿À´Â daytime ¸Þ¼¼ÁöÀÇ ¼ö½Å ¹× È­¸éÃâ·Â */
while((n = read(s, buf, BUF_LEN)) > 0) {
buf[n] = '\0';
printf("%s", buf);
}

close(s);
}

°ü·Ã±Û : 1 °Ç ±Û¾´½Ã°£ : 2002/11/14 16:53 from 218.154.16.35

 

Á¦ ¸ñ

Á¶È¸

³¯Â¥

±Û¾´ÀÌ

daytime client (Tcp)

8622

2002.01.19

daytime


  echo client [tcp] ¸ñ·Ïº¸±â »õ±Û ¾²±â Áö¿ì±â ÀÀ´ä±Û ¾²±â ±Û ¼öÁ¤ hostent ±¸Á¶Ã¼ Ãâ·ÂÇÁ·Î±×·¥  
BACKRUSH  À¯´Ð½º¸í·É  ´ÙÀ½  ÀÚ·á½Ç  Ascii Table   ¿ø°ÝÁ¢¼Ó  ´Þ·Â,½Ã°£   ÇÁ·Î¼¼½º   ½©
ÁöÇÏö³ë¼±   RFC¹®¼­   SUN FAQ   SUN FAQ1   C¸Þ´º¾ó   PHP¸Þ´º¾ó   ³Ê±¸¸®   ¾Æ½ºÅ°¿ùµå ¾ÆÀÌÇǼ­Ä¡