分类:
2010-06-23 11:27:01
#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);
}