UNIX网络编程1.1概述 1.2时间获取客户函数

 

GZNJ(%T5L]_$5TOC$W78LBM

 

TE`ELS}JO]GOH0{R5FQF6L8

 

H0QCUMS5)K$ACA$ZICR)76P

 

K0P6)`36APCLNRY3]9[7]$Q

 

)NJFX8CHQ]73WCU~ECZVYCH

 

~(K{M2T_C)6P$81G52]4GCE

 

7M84686K%2T7C4E$NCQBYBT

 

#include <iostream>

#include "../lib/unpsunyj.h"

int main(int argc, char** argv)
{
    int sockfd;
    int n;
    char recvline[MAXLINE + 1];
    sockaddr_in servaddr;

    if (argc != 2)
    {
        err_quit("usage: a.out <IPaddress>");
    }

    if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
    {
        err_sys("socket error");
    }

    bzero(&servaddr, sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_port   = htons(13); // daytime server
    if (inet_pton(AF_INET, argv[1], &servaddr.sin_addr) <= 0)
    {
        err_quit("inet_pton error for %s", argv[1]);
    }

    if (connect(sockfd, (sockaddr*)&servaddr, sizeof(servaddr)) < 0)
    {
        err_sys("connect error");
    }

    while ( (n = read(sockfd, recvline, MAXLINE)) > 0)
    {
        recvline[n] = 0; // null terminate
        if (fputs(recvline, stdout) == EOF)
        {
            err_sys("fputs error");
        }
    }
    if (n < 0)
    {
        err_sys("read error");
    }

    return 0;
}

 

@H@JVQSHSTJD}[M%Q$G5W(D

 

CN58O%OH(7HI]MCHD$8$FXB

 

ET~_E[I)HVXJEGJGCC0TPXV

 

L7R}TL0OESQ1X1{GJW1D@ND

 

GPWT{0ZQ@I%D$FI54(65K61

 

5(1FLV}`H%`J@J1LY@1F(OO

 

I_{@%OVEWXU6P~M9INSRA1X

 

 

 

 

逻辑上socket处于应用层与传输层之间。

ip,端口,协议,一起决定了网络的一个端点。

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

c2b6ad04cae193bb7125b44aea036cff

 

IMG_1312

IMG_1313

IMG_1314

IMG_1315

IMG_1316

IMG_1317

IMG_1318

IMG_1320

IMG_1321

IMG_1322IMG_1323IMG_1324IMG_1325IMG_1326IMG_1327IMG_1328IMG_1329IMG_1333IMG_1334IMG_1337

posted @ 2015-01-30 21:08  孙永杰  阅读(479)  评论(0编辑  收藏  举报