// Copyright (c) 2001 David Muse
// See the file COPYING for more information
#include <rudiments/inetclientsocket.h>
#include <rudiments/error.h>
#include <stdio.h>
#ifdef RUDIMENTS_NAMESPACE
using namespace rudiments;
#endif
int main(int argc, const char **argv) {
// create an inet socket client
inetclientsocket clnt;
// connect to a server on localhost, listening on port 8000
if (clnt.connect("localhost",8000,-1,-1,1,1)<0) {
printf("connect failed: %s\n",error::getErrorString());
exit(1);
}
// write "hello" to the server
clnt.write("hello",5);
// read 10 bytes from the server and display them
char buffer[11];
int sizeread=clnt.read(buffer,10);
buffer[sizeread]=(char)NULL;
printf("%s\n",buffer);
// close the connection to the server
clnt.close();
}
syntax highlighted by Code2HTML, v. 0.9.1