August 13th, 2003, 12:35 PM
Creating a buffer to receive data from a server
I am trying to send a file from a server I have written.
From the server I am reading the file into a buffer and then sending the data.
Client Receive Code
for(int i=0; i < NO_ITERATIONS; i++)
int byte_count = 0;
if((byte_count = client_stream_.recv_n(data_buf_, ACE_OS::strlen(data_buf_) +1, 0)) == -1)
std::cout << "Data Not Received";
data_buf_[byte_count] = 0;
ACE_DEBUG((LM_DEBUG, "Server received" "%s \n", data_buf_));
When I receive the data on the client end however the data is truncated, and is getting mixed together.
Send Code from Server
I have never wrote a network app like this, so I may be sending the data wrong from the server. I have been able to succesfully send data correctly ("Hello Server"), by assigning it to data_buf_ in my Server constructor.
std::fstream diag_file_("diagnostics.txt", ios::in);
while(!diag_file_.eof() && !diag_file_.fail())
data_buf_ = data_.c_str();
if(new_stream_.send_n(data_buf_, ACE_OS::strlen(data_buf_)+1, 0) == -1)
ACE_ERROR((LM_ERROR, "%p\n", "Data Sent"));
if(new_stream_.close() == -1)
ACE_ERROR((LM_ERROR, "%p\n", "close"));
I am using ACE ( Adaptive Communication Environment).
Any suggestions or resources would be very helpful. If more information is needed please let me know.