TSocket issue when trying to get root files

Hello,

I’m trying to get a root file from amazon s3 but currently the behavior for TSocket it somewhat strange when I try to fetch a root file. Assume that TAS3Msg generates the proper HTTP GET request.

int testTSocket(){
	TUrl fServer = TUrl("s3-eu-west-1.amazonaws.com");
	TAS3Msg s3get = TAS3Msg(GET, "/hsimple.root", "roots3", fServer.GetHost());
	TString msg = s3get.toTString();
	TSocket * fSocket = new TSocket(fServer.GetHost(), fServer.GetPort());
	
	if(!fSocket || !fSocket->IsValid()){
		Error("TAS3File SysRead","cannot connect to host %s",fServer.GetHost());
		return -1;
	}

	printf("%s",msg.Data());

	if(fSocket->SendRaw(msg.Data(), msg.Length()) == -1) {
    	Error("TAS3File SysRead", "error sending command to host %s", fServer.GetHost());
    	return -1;
   	}

	char msgRaw[1024];

	fSocket->SetOption(kNoBlock, 1);
	fSocket->Select();

	Int_t recvBytes = fSocket->RecvRaw(msgRaw, 1024);

	if(recvBytes == -1){
		Error("TAS3File SysRead", "error receiving data from host %s", fServer.GetHost());
		return -1;
	}

	printf("%s\n",msgRaw);

	return 1;
}

Somehow the body of the response is only the first 4 bytes “root”.

root [1] testTSocket()
GET /hsimple.root HTTP/1.1
Host: roots3.s3-eu-west-1.amazonaws.com
Date: Tue Aug  2 14:13:30 2011 GMT
Authorization: AWS id:secret

HTTP/1.1 200 OK
x-amz-id-2: KUHwrvjwKPvowSBlIoJD9qqAqRDniqKBDcgc3AGXpTbEpkK66G6dz23HNQqMF5Y6
x-amz-request-id: 47C8A70A6FF286DE
Date: Tue, 02 Aug 2011 14:13:29 GMT
Last-Modified: Tue, 02 Aug 2011 13:43:56 GMT
ETag: "10deacea19b436e4e0938dd4623ea6de"
Accept-Ranges: bytes
Content-Type: application/octet-stream
Content-Length: 326
Server: AmazonS3

root
(int)1
root [2] 

The problem seems to be related to TSocket because everything works as expected with telnet.
Does someone has any idea of the what the problem could be?
What is exactly the different between RecvRaw and Recv. If I use Recv it (seems to) halt.

Cheers!

Hi,

TSocket::Recv expects to be connection to another TSocket and follows the internal communication protocol.
TSocket::RecvRaw ‘just’ receives the incoming bytes as is.

After receiving the ‘root’ which indicates the file type, you routine need to issue more Get request to get the rest of the file.

Note that the class TWebFile implements exactly this pattern for usual web server and might be also appropriate for the Amazon server ; If not, in order to properly hook it up to the rest of the ROOT library, I recommend that you adapt/extend TWebFile as appropriate/needed.

Cheers,
Philippe.