[Cppcms-users] socket communication example
Brought to you by:
artyom-beilis
|
From: adi.fatol <adi...@ar...> - 2013-01-11 13:51:35
|
Hello all, I am a PHP developer and I want make a few tests using the cppcms framework. I know C/C++ but I have little experience using it. I use an "echo server" written in PHP, you can find it here: http://php.net/manual/en/sockets.examples.php. I want to send a message to the server. For this I use this function I have implemented: void send_msg(const char *msg) { booster::aio::stream_socket socket_; booster::system::error_code err; int w_bytes, r_bytes; booster::aio::endpoint ep("127.0.0.1", 10000); std::cout << "connecting..." << std::endl; socket_.open(booster::aio::family_type::pf_inet, err); std::cout << "open error: " << err.value() << std::endl; socket_.connect(ep, err); std::cout << "connection error: " << err.value() << std::endl; try { w_bytes = socket_.write(booster::aio::buffer(msg, sizeof(msg)), err); std::cout << "written bytes: " << w_bytes << std::endl; } catch (booster::system::system_error write_err) { std::cout << "Exception raised: " << write_err.code() << '\n'; } socket_.shutdown(booster::aio::stream_socket::how_type::shut_rdwr); socket_.close(); } I get no error on socket connect, but the problem is that I always get returned that 4 bytes were written and the php server crashes with the error: "Connection reset by peer". The server works ok in other instances, as I am able to connect to it using telnet and I get the messages echoed. I think the issue is that I don't understand very well how to use the sockets from booster library and I would kindly ask you for an link where I can see a simple example or if you can provide some tips. Also, I have looked at the echo_server example but it's quite complicated and I want to test a simple client initially. Thank you, -- Fatol Sergiu Adrian Team Leader & Senior PHP Developer Arobs Transilvania Software *adi...@ar...* |