passing socket descriptor to a function

Hi, i have the code below, i want to separate the open socket code from the
writting fucntions, i want to call a escribir() function from the main but
i¡m not clear the value i have to pass the function, inthe way i have below
it has not work.
thanks
#include <ctime>
#include <iostream>
#include <string>
#include

hi for the fast answer, i have other question respect to this, what about if
i wanna a function return the socket descriptor value? what must be the type
of value retuned? an int value?
thanks
2010/1/27 Igor R
void escribir( tcp::socket socket)
should be:
void escribir( tcp::socket &socket) _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Ing Pedro Alonso Chaparro Valero Ciudad Politecnica de la Innovación iTEAM - Mobile Communications Group Polytechnic University of Valencia C\ Camino de Vera S/N, Edificio 8G 46022 Valencia, Spain

hi for the fast answer, i have other question respect to this, what about if i wanna a function return the socket descriptor value? what must be the type of value retuned? an int value?
You mean the low-level socket descriptor, which can be used in recv/send etc.? asio::ip::tcp::socket::native_type socketDescriptor(asio::ip::tcp::socket &socket) { return socket.native(); }

from the main code i call a function to start a server on a port X, already
this server started , i back to main fucntion, make some calculus and after
that i have to write some data through the socket, so i call a writing
fuction, but to this fuction i have to pass to it the data i want transmit
and something to indicate it what's the socket i'm using. I'm not an expert
in programming so i dont know if this is the best way to do it. I just want
to access to the variable socket from anywhere.
thanks
2010/1/27 Igor R
hi for the fast answer, i have other question respect to this, what about if i wanna a function return the socket descriptor value? what must be the type of value retuned? an int value?
You mean the low-level socket descriptor, which can be used in recv/send etc.?
asio::ip::tcp::socket::native_type socketDescriptor(asio::ip::tcp::socket &socket) { return socket.native(); } _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Ing Pedro Alonso Chaparro Valero Ciudad Politecnica de la Innovación iTEAM - Mobile Communications Group Polytechnic University of Valencia C\ Camino de Vera S/N, Edificio 8G 46022 Valencia, Spain

I'm not an expert in programming so i dont know if this is the best way to do it. I just want to access to the variable socket from anywhere.
Then study the examples coming with asio: http://www.boost.org/doc/libs/1_41_0/doc/html/boost_asio/examples.html You will find there good design proposal to use with synchronous and asynchronous approaches.
participants (2)
-
Igor R
-
pedro chaparro