分类: LINUX
2013-05-07 10:14:57
#include
#include
#include
#include
#include
#include
#include
#include
void process_client(int s) {
char buff[128];
int rc,maxfd;
while(fgets(buff,sizeof(buff),stdin)!=NULL) {
write(s,buff,strlen(buff));
rc = read(s,buff,sizeof(buff));
if(rc <= 0)
error(1,0,"no data!!\n");
buff[rc]='\0';
write(1,buff,rc);
bzero(buff,sizeof(buff));
}
}
int main(int argc, char **argv) {
struct sockaddr_in server,temp;
char *hname, *sname;
int s, c, len;
if(argc < 2)
error(1,0,"parameters less than 2\n");
else if(argc == 2) {
hname = NULL;
sname = argv[1];
}
else if(argc == 3) {
hname = argv[1];
sname = argv[2];
}
s = client_connect(hname, sname, &server, "udp",1);
printf("%s,%d",inet_ntoa(server.sin_addr),ntohs(server.sin_port));
process_client(s);
close(s);
exit(0);
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/adcxf/archive/2007/11/25/1901888.aspx