|
|
|
|
|
|
|
|
|
|
Re: FileTransferAgent - strange behaviour [message #116896 is a reply to message #116883] |
Thu, 01 November 2007 09:52 |
Jiri Bjalek Messages: 12 Registered: July 2009 |
Junior Member |
|
|
Hi again,
I have yet another sample code which works bad for me. This sample is
based on code I've found in
http://www.eclipse.org/tptp/home/documents/resources/AC_Assi sted_File_Transfer.html
in chapter '3.2 Sample file transfer code'.
This time I experimented with C++ code instead of Java.
/*********************************************************** ********************
* Copyright (c) 2005 Intel Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
* Contributors:
*
* Kevin P O'Leary, Intel - Sample of FileTransfer Client
*
* $Id: MyFileTransferClient.cpp,v 1.8 2005/11/07 18:51:18 koleary Exp $
*
*
************************************************************ *******************/
#include <iostream>
using namespace std;
#include "tptp/client/NodeFactory.h"
#include "tptp/client/FileTransfer.h"
using namespace TPTP::Client;
int main(int argc, char* argv[])
{
char* hostName = "localhost";
int portNum = 10006;
INode* TargetNode = 0;
AgentController* ACProxy = 0;
// Create a Node object for the target system of choice.
TargetNode = NodeFactory::createNode(hostName);
if (!TargetNode)
{
cout<<"ERROR: Failed to create the Node object."<<endl;
cout<<"Press any key to exit..."<<endl;
getchar();
return -1;
}
// Establish a connection with an Agent Controller on the
// target system. The port number specified must match
// that defined in the configuration file for the desired
// Agent Controller.
ACProxy = TargetNode->connect(portNum);
if (!ACProxy)
{
cout<<"ERROR: Unable to connect to the Agent Controller running on
"<<hostName<<" at port number "<<portNum<<endl;
cout<<"Press any key to exit..."<<endl;
getchar();
return -1;
}
cout<<endl<<"Connected to the Agent Controller on \""<<hostName<<"\" at
port number "<<portNum<<endl;
//End of generic connect to AgentController code.
//Start of FileTransferAgent specific code.
// Create a client-side representative of a FileTransfer object from which
// a MyFileTransferAgent is derived, specifying the name of the desired
agent
// as it has been installed in the agents directory.
FileTransfer* MyFileTransferAgent = new
FileTransfer("org.eclipse.tptp.FileTransferAgent");
// Get a handle to the actual FileTransferAgent, storing it in the
MyFileTransferAgent
// object. If the call is successful, the FileTransferAgent is running
and
// ready to respond to requests.
// Note that the Agent Controller manages the life of an agent, so it
will start
// one running if needed.
// We request controller access to the agent since we want to perform
// actions like getFile and putFile. However, the FileTransferAgent is
not checking
// access levels on incoming requests at this time (TBD).
if (-1 == ACProxy->getAgent(MyFileTransferAgent, TPTP_CONTROLLER_ACCESS))
{
cout<<"ERROR: Unable to get agent
org.eclipse.tptp.FileTransferAgent"<<endl;
cout<<"Press any key to exit..."<<endl;
getchar();
return -1;
}
cout<<endl<<"The FileTransferAgent Agent ID:
"<<MyFileTransferAgent->getAgentID()<<endl;
//These next variables encode the file paths for the transfered files.
#ifdef _WIN32
char *remoteFile = "C:\\tmp\\oi\\big_simple.txt"; //This is the
source file for getFile and putFile.
//char *localFile = "C:\\tmp\\big_local.txt"; //This is the
destination file for getFile and putFile.
char *localFile = "C:\\tmp\\oi1.txt"; //This is the
destination file for getFile and putFile.
char *remoteFile2 = "C:\\tmp\\oi\\big_simple2.txt"; //This is
the source file for getFile and putFile.
//char *localFile2 = "C:\\tmp\\big_local2.txt"; //This is the
destination file for getFile and putFile.
char *localFile2 = "C:\\tmp\\oi2.txt"; //This is the
destination file for getFile and putFile.
//Deleted by deleteFile operation.
#else
//other platform than win32 not used
#endif
tptp_int32 res;
for (int iter=0; iter<100000; iter++) {
cout << "Kolo: " << iter << endl;
cout << "putFile1 " << endl;
res = MyFileTransferAgent->putFile(localFile, remoteFile);
cout << "putFile2? " << res << endl;
cout << "putFile3 " << endl;
res = MyFileTransferAgent->putFile(localFile2, remoteFile2);
cout << "putFile4? " << res << endl;
cout << "deleteFile1 " << endl;
res = MyFileTransferAgent->deleteFile(remoteFile);
cout << "deleteFile2? " << res << endl;
cout << "deleteFile3 " << endl;
res = MyFileTransferAgent->deleteFile(remoteFile2);
cout << "deleteFile4? " << res << endl;
}
//Put the file specified in remoteFile to localFile.
//MyFileTransferAgent->putFile(remoteFile, localFile);
// Wait for data to finish coming over channel.
// Note: A protocol for recognizing end of data is TBD.
Sleep(2000);
// Release resources allocated by the Agent Controller
MyFileTransferAgent->destroyDataConnection();
MyFileTransferAgent->releaseAgent();
ACProxy->disconnect();
// Release client side resources
delete MyFileTransferAgent;
ACProxy->destroy();
NodeFactory::deleteNode(TargetNode);
cout << "This is the end :)" << endl;
return 0;
}
------------------------------------------------------------ --------------
Both files localFile and localFile2 have 16B in my case and after about
50000 iterations remote files are not replaced but the content is
appended. Transfered file has several kB instead of just 16B and the
content repeats several times.
Regards,
Jiri
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03839 seconds