#include<sys/stat.h>//没有.h9 A- S/ Q" a; v) f! p. h" Q
#include<fcntl.h>
% k1 f7 f5 s4 U6 i4 o#include<unistd.h>; \3 l* @9 I2 q3 d4 ]
#include<sys/types.h>
6 q# i/ z6 v: [2 b( Q5 v#include<netinet/in.h>//netinet/in.h) X9 r+ E% Y# _' {/ X" c4 ~
#define PORT 12343 t" h* Z" }) _( T8 l" O
#define SER "127.0.0.1"9 W& }, M# O, \1 X U4 X
main(): q' s1 H# {8 [' S
{
5 j4 [9 K$ y1 {6 x9 t3 Z4 bint s;
* h" u( r) M S6 `2 ~$ f$ Zstract sockaddr_in addr;6 ?$ Q% J0 L# L+ T6 M' }
char buf[256]
% O" T2 h/ W) `& y; Xif ((s=socket(AF_INET, SOCK_STREAM, 0 ))<0){
0 r2 \+ K( y: fperror("socket");8 j& _( S- N; s4 `
exit(1);}
% d9 _! ~ H: V% A* h4 Obzero (&addr,size of (addr));
! V2 Z& V5 ]7 caddr.sin_family=AF_INET;; _! @! F: \$ \' _: ?* z; Z
addr.sin_sport=htons ( PORT );7 Z: t' V2 ?4 Y
addr.sin_addr.s_addr=inet_addr ( SER );" y+ _" p, h- i7 G, t6 P
if (connect ( s, ()&addr, sizeof () )<0){+ J7 ^/ B8 Z- S
perror("connect");
$ {8 r( k4 k4 c: y, p1 n% Nexit(1);}
f6 v y. o' ]5 I: c( X* J1 Srecr(s, buf, 256, 0 );
) W) M; v8 R* tprint("%s\n",buf);
5 V& H8 v) e, n; O% kwhile (1){
9 v2 N H1 V: U! kbzero (buf,sizeof (buf));/ o/ Y4 @! k# C' ?" e( l/ K
numread = read( file, buf, 256 );//这里缺少要往网上发的内容,是从文件读,还是其他设备
: D) c( z7 q" S1 N//前面还要加上int file;char filename[] = "hello.c"; if ( ( file = open ( filename, O_RDONLY ) ) < 0 ) {perror ( "open:" ); exit (1); }$ @5 v6 z" ^0 u1 V) c& t4 d! `
if (send(s, buf, numread, 0)<0){
0 Y% J2 P" A2 G$ e# c. E# L9 Cperror("send");/ Z$ z9 I9 F% K6 s5 h* t% y* L a
exit (1);}
- ~" D1 x+ o' m4 x# b" o) Z, I/ t}
6 N8 t- f6 k: C1 n8 A. f3 W}