Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Need help retrieving remote file

2 views
Skip to first unread message

mybrokengnome

unread,
Jan 7, 2009, 12:11:02 PM1/7/09
to
As far as I can tell everything is working up until NetLibReceive,
where it just hangs after receiving 1 byte back (a -1). Any help
would be appreciated, thanks. BTW, I've changed the URL to something
else, but the concept is the same, going to a base url and then
getting trying to get a file from a subdirectory. If anyone knows how
to go straight to the file instead of the way i'm doing that would be
awesome too, but I could never get that to work, only connect to a
domain name(like www.google.com).

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);


0 new messages