|
|
当サイトは、玄箱PRO (KURO-BOX/Pro)を中心とした組み込み、Linuxと電子工作を扱っています。
会社案内
情報セキュリティおよび個人情報の取り扱いについて コメントとトラックバックは、spamを予防するために、編集担当が公開の作業をするまで非公開になっています。コメントはそれぞれ投稿した人のものです。 |
int
connect_to_lcdd(char *host, int port)
{
int sock;
struct sockaddr_in s;
struct hostent *hinfo;
sock = socket(PF_INET, SOCK_STREAM, 0); ← (1)
if (sock<0) {
fprintf(stderr, "Could not create socket\n");
exit(1);
}
s.sin_family = AF_INET; ← (2)
s.sin_port = htons(port); ← (3)
if ((hinfo = gethostbyname(host)) == NULL) { ← (4)
fprintf(stderr, "Unknown host %s.\n", host);
exit(1);
}
s.sin_addr = *(struct in_addr *)hinfo->h_addr; ← (5)
if (connect(sock, (struct sockaddr *)&s, sizeof(s)) < 0) { ← (6)
fprintf(stderr, "Could not connect to %s port %d.\n", host, port);
exit(1);
}
return sock;
}
write(sock, "hello\n", 6);
if (mygets(sock, buf, sizeof(buf))>0) {
printf("%s", buf);
}
for (i=0; i<(len-1); i ++) {
if (read(sock, rbuf, 1) == 1) {
if (*rbuf == '\n')
break;
rbuf ++;
continue;
}
usleep(200*1000);
}
shutdown(sock, SHUT_RDWR);
close(sock);
このブログ記事を参照しているブログ一覧: 簡単ソケット・プログラミング
このブログ記事に対するトラックバックURL: http://www.eleki-jack.com/mt/mt-tb.cgi/784
おすすめ書籍 |
![]() |
コメントする