/* Objective-C Network Client Class Implementation Author: Jacob I. Torrey Email: discipleofranok@gmail.com Date: 2/16/07 */ @implementation Client { int sid; struct sockaddr_in sinfo; } - init: (char *) ip : (int) port { [super init]; sid = socket(PF_INET, SOCK_STREAM, 0); sinfo.sin_family = AF_INET; sinfo.sin_port = htons(port); sinfo.sin_addr.s_addr = inet_addr(ip); memset(&(sinfo.sin_zero), '\0', 8); connect(sid, (struct sockaddr *) & sinfo, sizeof(struct sockaddr)); return self; } - close { close(sid); } - send: (char *) toSend { int sent = 0; int sendsize = strlen(toSend)*sizeof(char); while(sent <= sendsize) { sent += send(sid, (toSend + sent/sizeof(char)), strlen(toSend + sent/sizeof(char)), 0); } } - (char *) getLine { int recvl; char * outChar = (char *) malloc(1024*sizeof(char)); recvl = recv(sid, outChar, 1024, 0); return outChar; } - (char *) get : (int) length { int recvl; char * outChar = (char *) malloc(length*sizeof(char)); recvl = recv(sid, outChar, length, 0); return outChar; } @end