12 #include <sys/types.h> 13 #include <sys/socket.h> 14 #include <netinet/in.h> 28 #define MAX_BUF_LEN 4096 58 error(
"Error closing socket");
85 port = host.
after(
":");
92 port = host.
after(
"/");
98 struct addrinfo hints;
99 memset(&hints, 0,
sizeof hints);
100 hints.ai_family = AF_INET;
101 hints.ai_socktype = SOCK_STREAM;
103 struct addrinfo *res;
107 error(gai_strerror(failed));
112 struct addrinfo *server_info = res;
116 socket(server_info->ai_family, server_info->ai_socktype, server_info->ai_protocol);
119 server_info = server_info->ai_next;
123 error(
"Error opening socket");
128 struct sockaddr_in* serv_addr = (sockaddr_in*) server_info->ai_addr;
129 serv_addr->sin_family = AF_INET;
130 if (connect(
m_svrsockfd,(
struct sockaddr*) serv_addr, server_info->ai_addrlen) < 0)
132 error(
"ERROR connecting");
148 if (command_spec == NULL)
152 if (
_DEBUG_) cout<<
"ossimToolClient:"<<__LINE__<<
" sending <"<<command_spec<<
">..."<<endl;
153 int n = send(
m_svrsockfd, command_spec, strlen(command_spec), 0);
156 error(
"ERROR writing to socket");
159 while (
n < (
int) strlen(command_spec))
162 if (
_DEBUG_) cout<<
"ossimToolClient:"<<__LINE__<<
" sending <"<<&(command_spec[
n])<<
">..."<<endl;
163 int r = send(
m_svrsockfd, &(command_spec[
n]), strlen(command_spec)-
n, 0);
166 error(
"ERROR writing to socket");
178 bool success =
false;
180 if (
_DEBUG_) cout<<
"ossimToolClient:"<<__LINE__<<
" Waiting to recv"<<endl;
182 if (
_DEBUG_) cout<<
"ossimToolClient:"<<__LINE__<<
" Received <"<<
m_buffer<<
">"<<endl;
185 error(
"ERROR reading from socket");
193 else if (response.
contains(
"MIXED"))
195 else if (response.
contains(
"ERROR"))
197 else if (response.
contains(
"ADIOS"))
198 error(
"Received unexpected disconnect message from server.");
200 error(
"Unknown type in response header");
213 if (
_DEBUG_) cout<<
"ossimToolClient:"<<__LINE__<<
" Waiting to recv"<<endl;
215 if (
_DEBUG_) cout<<
"ossimToolClient:"<<__LINE__<<
" Received <"<<
m_buffer<<
">"<<endl;
218 error(
"ERROR reading from socket");
226 printf(
"Text response:\n-----------------\n%s\n-----------------\n",
m_textResponse.
c_str());
234 cout <<
"Server requesting file send. " <<endl;
240 cout <<
"File size = " <<filesize<<endl;
254 error(xmsg.str().c_str());
266 error(
"ERROR reading from socket");
272 error(
"ERROR on file write().");
281 cout<<
"\nossim-client: Received and wrote "<<numBytes<<
" bytes to: <"<<
m_prodFilePath<<
">."<<endl;;
290 if (
_DEBUG_) cout<<
"ossimToolClient:"<<__LINE__<<
" sending \"ok_to_send\"..."<<endl;
294 error(
"ERROR writing to socket");
297 if (
_DEBUG_) cout <<
"Receive acknowledged."<<endl;
304 if (filepath == NULL)
312 xmsg <<
"ERROR creating output directory: <"<<
m_prodFilePath<<
">"<<ends;
313 error(xmsg.str().c_str());
317 xmsg <<
"ERROR output directory: <"<<
m_prodFilePath<<
"> is not writable."<<ends;
318 error(xmsg.str().c_str());
void clear()
Erases the entire container.
ossimString before(const ossimString &str, std::string::size_type pos=0) const
METHOD: before(str, pos) Returns string beginning at pos and ending one before the token str If strin...
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
bool contains(char aChar) const
const ossimString & append(const ossimString &s)
os2<< "> n<< " > nendobj n
const char * chars() const
For backward compatibility.
ossimFilename dirCat(const ossimFilename &file) const
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string's contents...
std::basic_ofstream< char > ofstream
Class for char output file streams.
ossimString after(const ossimString &str, std::string::size_type pos=0) const
METHOD: after(str, pos) Returns string immediately after the token str.
bool createDirectory(bool recurseFlag=true, int perm=0775) const
ossimFilename path() const