comm = new Communications("www.google.com", 80, "GET /images/arrow.bmp
HTTP/1.0", &NetProc);
first parameter is the url, then the port, then the header(i think
this is the problem), and then a pointer to a call back function that
will handle whatever we get back from the server.
Here's the communications class, taken from various sources. A little
messy, need to clean it up.
//Most of these are left over and not used from debugging
and other attempts
Err error;
UInt16 AppNetRefnum;
UInt16 ifErrs;
NetSocketRef socket;
Int16 result;
int x, y;
NetSocketAddrINType destAddr;
char* buffer;
int offset = 0;
int max_read_len = 1;
int bytes = 1;
int failed = 0;
char* buf = headerType;
const UInt16 bufLen = StrLen(buf);
UInt16 sentBytes = 0;
char* host = address;
NetHostInfoBufType hostinfo;
// Find the network library
error = SysLibFind("Net.lib", &AppNetRefnum);
//This sends the data 1 byte at a time
for(int i = 0; i < StrLen(headerType) + 1; i++){
result = NetLibSend(AppNetRefnum, socket, &headerType[i], 1,
0,0,0, -1, &error);
}
//Should receive the data, but currently just hangs
for(int i = 0; bytes > 0; i++){
bytes = NetLibReceive(AppNetRefnum, socket, &buffer[i], 1, 0, 0,
0, -1, &error);
}
//call to the callback function
method(buffer);
// Close the socket
CloseSocket:
result = NetLibSocketClose (AppNetRefnum, // Network Library
socket, // Socket reference
-1, // Timeout
&error // Error result
);
if (result == -1) {
} else {
}
// Close the network library
CloseNetLib:
error = NetLibClose(AppNetRefnum, false);