/* fpont 12/99 */
/* pont.net */
/* tcpClient.c */

#include
#include
#include
#include
#include
#include
#include /* close */

int main()
{
int sockfd;
struct sockaddr_in dest;
char buffer[128];

/* create socket */
sockfd = socket(PF_INET, SOCK_STREAM, 0);

/* initialize value in dest */
bzero(&dest, sizeof(dest));
dest.sin_family = PF_INET;
dest.sin_port = htons(8889);
inet_aton("192.168.10.33", &dest.sin_addr);

/* Connecting to server */
connect(sockfd, (struct sockaddr*)&dest, sizeof(dest));

/* Receive message from the server and print to screen */
bzero(buffer, 128);
recv(sockfd, buffer, sizeof(buffer), 0);
printf("%s", buffer);

/* Close connection */
close(sockfd);

return 0;
}



要編釋這個程式,使用指令: gcc sample-client.c -o sample-client
要執行程式可以使用指令: ./sample-client
http://www.linuxhall.org/modules.php?name=News&file=article&sid=79
arrow
arrow
    全站熱搜

    clinno 發表在 痞客邦 留言(0) 人氣()