When I tried to compile my game; and it says like
Networking/Sockets/Socket.hpp:18:81: error: expected identifier before ')' token
so if you want to see the source code I've in github here the link:
https://github.com/suky637/ServerPlusPlus
for peaple that do not want to go to github I will send you the Socket.hpp (this is the main error source) the code:
#ifndef Socket_hpp
#define Socket_hpp
#include <stdio.h>
#include <WinSock2.h>
#include <winsock.h>
#include <iostream>
namespace spp
{
class Socket {
private:
struct sockaddr_in address;
int sock;
int connection;
public:
// Constructor
Socket(int domain, int service, int protocol, int port, u_long interface_parameter);
// Virtual function to confirm to connect to the network
virtual int connect_to_network(int sock, struct sockaddr_in address) = 0;
// Function to test sockets and connection
void test_connection(int);
// Getter function
struct sockaddr_in get_address();
int get_sock();
int get_connection();
// Setter function
void set_connection(int connection_);
};
}
#endif
oh and this is the output:
// command : g++ Server.cpp -o ServerPlusPlus
In file included from Networking/Sockets/_ServerPlusPlus-sockets.hpp:6:0,
from Networking/ServerPlusPlus-Networking.hpp:6,
from ServerPlusPlus.hpp:6,
from Server.cpp:1:
Networking/Sockets/Socket.hpp:19:81: error: expected identifier before ')' token
Socket.cpp
#include "Socket.hpp"
// Default constructor
spp::Socket::Socket(int domain,
int service,
int protocol,
int port,u_long interface_parameter,
)
{
// Define address structure
address.sin_family = domain;
address.sin_port = port;
address.sin_addr.s_addr = htonl(interface_parameter);
// Establish socket
sock = socket(domain,service,protocol);
test_connection(sock);
// Establish Connection
connection = connect_to_network(sock, address);
test_connection(connect_to_network);
}
// Test Connection virtual function
void spp::Socket::test_connection(int item_to_test)
{
// Comfirm that the socket or connection has bin properly established
if (item_to_test < 0)
{
perror("Failed To Connect...");
exit(EXIT_FAILURE);
}
}
// Getter functions
struct sockaddr_in spp::Socket::get_address()
{
return address;
}
int spp::Socket::get_sock()
{
return sock;
}
int spp::Socket::get_connection()
{
return connection;
}
// Setter functions
void spp::Socket::set_connection(int connection_)
{
connection = connection_;
}
the main funtion where I compile is
#include "ServerPlusPlus.hpp"
using namespace std;
int main()
{
cout << "*--------- Starting ---------*" << endl;
cout << "* Binding Socket... ";
spp::BindingSocket bs = spp::BindingSocket(AF_INET,SOCK_STREAM,0,80,INADDR_ANY);
cout << "Complete\n* Listening Socket... ";
spp::ListeningSocket ls = spp::ListeningSocket(AF_INET, SOCK_STREAM, 0, 80, INADDR_ANY, 10);
cout << "Complete\n\n\n* Sucess!" << endl;
system("pause");
}
probably it is the file I copile and ServerPlusPlus.hpp is
#ifndef ServerPlusPlus
#define ServerPlusPlus
#include <stdio.h>
#include "Networking/ServerPlusPlus-Networking.hpp"
#endif
and ServerPlusPlus-Networking.hpp
#ifndef ServerPlusPlus_Networking_hpp
#define ServerPlusPlus_Networking_hpp
#include <stdio.h>
#include "Sockets/_ServerPlusPlus-sockets.hpp"
#endif
and ServerPlusPlus_Sockets_hpp
#ifndef ServerPlusPlus_Sockets_hpp
#define ServerPlusPlus_Sockets_hpp
#include <stdio.h>
#include "Socket.hpp"
#include "BindingSocket.hpp"
#include "ListeningSocket.hpp"
#include "ConnectingSocket.hpp"
#endif
You seem to have missed that actual answer.
interface is used as a typedef in some windows headers
see What is the "interface" keyword in MSVC?
change the name to iface or something like that
Related
I am trying to create a TCP server in a function int create_server(int port_number, char ip_addr_string[IPV4_ADDR_SIZE]) which is called in main.
When I run the c++ code given below: Assertion failed: (w->fd >= 0), function uv__io_poll, file kqueue.c, line 149.
#include <iostream>
#include <vector>
#include <algorithm>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <future>
#include <sys/types.h>
#include <uv.h>
#define IPV4_ADDR_SIZE 15
uv_loop_t* loop;
struct sockaddr_in addr;
std::map <int, uv_tcp_t * > pool;
int create_tunnel(int port_number, char ip_addr_string[IPV4_ADDR_SIZE]){
uv_tcp_t global_server;
uv_tcp_init(loop, &global_server);
uv_ip4_addr("0.0.0.0", port_number, &addr);
uv_tcp_bind(&global_server, (const struct sockaddr *)&addr, 0);
int r = uv_listen((uv_stream_t *)&global_server, 128, NULL);
if(r){
fprintf(stderr, "Listen error: %s \n", uv_strerror(r));
}
else{
fprintf(stdout, "Listening on: %d \n", port_number);
}
pool[rand()] = &global_server;
return r;
}
int main(int argc, const char *argv[]){
int status = 1;
loop = uv_default_loop();
uv_loop_init(loop);
loop->data = &pool;
status = create_tunnel(7011, (char*)"0.0.0.0");
std::cout<< "status: " << status << std::endl;
uv_run(loop, UV_RUN_DEFAULT);
return 0;
I think this error is because the servers created are not tracked by the event_loop when the create_server function ends, but I am not sure.
Any help, please?
I create a TCP server, I always get following error when I was run. How I get rid of this error, I do not understand where wrong?
Also it say data received while connection refused, I do not run client. Why?
Error:
Socket Created
Error connect to server: Connection refused
Error to accept: Invalid argument
Data received
Server
#include <iostream>
#include "serverh.hpp"
#include "glimpsepackages.h"
#include "soupbintcppackages.h"
int main() {
//soupBinTCP structures
DebugPacket D; //"+"
LoginAcceptedPacket A;
LoginRejectPacket J;
SequencedDataPacket S;
ServerHeartBeatPacket H;
EndOfSessionPacket Z;
//glimpse structures
SecondsMessage T;
CombinationOrderBookDelivery M;
TickSizeTableEntryPackage L;
OrderBookDirectoryPackage R;
OrderBookStatePackage O;
AddOrderMessageNoMPIDPackage A1;
AddOrderMessageMPIDPackage F;
std::string ip="127.0.0.1";
int port=7888;
ssize_t size=1024;
void *data={};
TcpServer server(ip, port);
server.connectToClient();
server.accept();
for (;;) {
server.receivingData(size);
switch (server.pop()) {
case '+':
// D.length=server.pop();
D.code = server.pop8();
D.text = server.pop();
break;
case 'A' :
A.to_little_endian();
A.code = server.pop8();
A.sequence_number = server.pop32();
for (int i = 0; i < 10; i++) {
A.session[i] = server.pop();
}
break;
case 'J':
J.code = server.pop8();
J.rejectreasoncode = server.pop();
break;
case 'S':
S.code = server.pop8();
S.message = server.pop();
break;
case 'H':
H.code = server.pop8();
case 'Z':
Z.code = server.pop8();
default:
return 0;
}
}
serverh.cpp
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <string>
#include "serverh.hpp"
#include "util.h"
#include <iostream>
TcpServer::TcpServer(std::string ip, int port):_ip(ip),
_port(port), _addrSize(sizeof _serverAddress)
{
_sockFd=-1;
};
bool TcpServer::connectToClient(){
_sockFd=socket(AF_INET,SOCK_STREAM,0);
if(_sockFd==-1)
perror("Error creating socket");
else
std::cerr<<"Socket Created\n";
_serverAddress.sin_addr.s_addr=inet_addr(_ip.c_str());
_serverAddress.sin_family=AF_INET;
_serverAddress.sin_port=htons(_port);
if(::connect(_sockFd,(struct sockaddr *)&_serverAddress, sizeof(_serverAddress))<0) {
perror("Error connect to server");
return false;
}
else
std::cerr<<"Connected\n";
if(::bind(_sockFd,(struct sockaddr *)&_serverAddress,_addrSize)<0)
perror("Error bind to server");
else
std::cerr<<"Socket bind\n";
if(::listen(_sockFd,5)==0)
std::cerr<<"Listining\n";
else
perror("Error on Listening");
return true;
}
bool TcpServer::accept(){
if(::accept(_sockFd,(struct sockaddr *) &_serverAddress, &_addrSize)<0)
perror("Error to accept");
else
std::cerr<<"Accepted\n";
return true;
}
void *TcpServer::receivingData(ssize_t size){
char *buffer=new char[size];
if(::recv(_sockFd,buffer, size,0)>0);
std::cerr<<"Data received\n";
return buffer;
}
void TcpServer::incOffset(int rest_length) {
void *restbuff = alloca(rest_length);
if (::recv(_sockFd, restbuff, rest_length, 0) < 0)
std::cerr << "Data received\n";
}
char TcpServer::pop(){
char ch;
if(::recv(_sockFd, &ch, 1, 0)>0)
return ch;
}
int8_t TcpServer::pop8() {
int8_t ch;
if (::recv(_sockFd, &ch, 8, 0) > 0)
return getLeValue(ch); // func include endian functions
}
int16_t TcpServer::pop16(){
int16_t ch;
if(::recv(_sockFd, &ch, 16, 0)>0)
return getLeValue(ch);
}
int32_t TcpServer::pop32(){
int32_t ch;
if(::recv(_sockFd, &ch, 32, 0)>0)
return getLeValue(ch);
}
int64_t TcpServer::pop64() {
int64_t ch;
if (::recv(_sockFd, &ch, 64, 0) > 0)
return getLeValue(ch);
}
Serverh.hpp
#ifndef SERVERH_H
#define SERVERH_H
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <string>
class TcpServer{
public:
TcpServer(const std::string _ip,int _port);
bool connectToClient();
bool accept();
void *receivingData(ssize_t size);
bool sendToClient();
char pop();
int8_t pop8();
int16_t pop16();
int32_t pop32();
int64_t pop64();
void incOffset(int rest_length);
private:
std::string _ip;
int _port;
int _sockFd;
sockaddr_in _serverAddress;
socklen_t _addrSize;
};
#endif
The problem
Error: Socket Created Error connect to server: Connection refused Error to accept: Invalid argument Data received
Two errors here, a failure to connect because the other address is not accepting connections and a failure to accept because one or more of the input parameters are bad.
The failure to connect is understandable. Clients are rarely listening on a port for connections. Clients usually initiate the connection.
The failure to accept is caused by connectToClient exiting after failing to connect. It never binds and listens, so the socket has not been set up for accept.
Fixing this
A server should not attempt to connect. It should listen for attempts to connect to it. This makes connectToClient bizarre. It tries to connect to a client and then, on the same socket, bind and listen. You can't do both, so I'd discard
if(::connect(_sockFd,(struct sockaddr *)&_serverAddress, sizeof(_serverAddress))<0) {
perror("Error connect to server");
return false;
}
else
std::cerr<<"Connected\n";
and
reconsider
_serverAddress.sin_addr.s_addr=inet_addr(_ip.c_str());
as this will only listen to one incoming address which might be what you want, but isn't usually. I would also rename the function to reflect the change in purpose.
Note:
if(::accept(_sockFd,(struct sockaddr *) &_serverAddress, &_addrSize)<0)
passes in a pointer to the server address. This location will be overwritten with the address of the client. It's harmless, but you probably don't want to do this. You aren't using the returned address as far as I can see, so you might as well just pass in NULLs and pass on it.
if(::accept(_sockFd, NULL, NULL)<0)
I am new to multi threading. I am trying to make a program that will listen to incoming connections, while being able to send data at the same time.
Here is the code so far. It is not finished yet, because I am stuck trying to figure out why I get this error:
__beginthreadex was not declared in this scope
Same goes for __endthreadex.
#include <winsock2.h>
#include <ws2tcpip.h>
#include <iostream>
#include <windows.h>
#include <process.h>
#pragma comment (lib,"Ws2_32.lib")
#define PORT "27015"
#define BUFLEN 512
using namespace std;
char recvbuf[BUFLEN];
int ires;
int recvbuflen=BUFLEN;
void Thread(void* data, SOCKET *x[2]) {
listen(*x[0],128);
*x[1]=accept(*x[0],NULL,NULL);
}
int main(int argc, char **argv){
SOCKET *SOKETI[2];
HANDLE H;
string X="Ping.";
string Y;
int i;
WSADATA wsa;
i=WSAStartup(MAKEWORD(2,0),&wsa);
struct addrinfo *result=NULL, *ptr=NULL, hints;
ZeroMemory(&hints,sizeof(hints));
hints.ai_family=AF_INET;
hints.ai_socktype=SOCK_STREAM;
hints.ai_protocol=IPPROTO_TCP;
hints.ai_flags=AI_PASSIVE;
i=getaddrinfo(NULL,PORT,&hints,&result);
SOCKET LSock;
LSock=socket(result->ai_family, result->ai_socktype, result->ai_protocol);
i=bind(LSock,result->ai_addr, result->ai_addrlen);
SOCKET CSock=INVALID_SOCKET;
SOKETI[0]=&LSock;
SOKETI[1]=&CSock;
H=(HANDLE)__beginthreadx(&Thread,0,&SOKETI,0,0,0);
while(1) {
//RECIEVER
i=recv(CSock,recvbuf,recvbuflen,0);
Y.append(recvbuf, recvbuf + i);
if (i=sizeof(X)){
H=(HANDLE)__endthreadx(&Thread,0,&SOKETI,0,0,0);
CloseHandle(H);
cout<<"Recieved "<<Y<<endl;
getchar();
return 0;
}
//RECIEVER
}
}
EDIT
I realized that I misspelled the function. Other mistakes done here are another topic.
I'm trying to improve my knowledge of OOP and decided to create a simple class to simplify sockets programming.
This is a learning experiment so I do not want to use boost, or other libraries.
I want to implement an event-driven recv(). Meaning, everytime there is new data coming in, it should call my function.
I think I need to create a thread to run a recv() loop and then call my function everytime there is new data. Is there other way around using threads? I want my code to be portable.
Here is my simple Class and example code:
class.h:
#ifndef _SOCKETSCLASS_H
#define _SOCKETSCLASS_H
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
#define W32
#include <WinSock2.h>
#pragma comment(lib, "ws2_32.lib")
#else
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netdb.h>
#define SOCKET int
#endif
#include <string>
#include<ctime>
#include <stdio.h>
#include <stdarg.h>
#include <varargs.h>
#include <tchar.h>
using namespace std;
#ifdef _DEBUG
#define DEBUG(msg) XTrace(msg)
#else
#define DEBUG(msg, params)
#endif
struct TCP_Client_opts
{
BOOL UseSCprotocol;
BOOL UseEncryption;
BOOL UseCompression;
int CompressionLevel;
void *Callback;
BOOL async;
};
struct TCP_Stats
{
unsigned long int upload; //bytes
unsigned long int download;//bytes
time_t uptime; //seconds
};
class TCP_Client
{
public:
TCP_Client();
TCP_Client(TCP_Client_opts opts_set);
~TCP_Client();
SOCKET GetSocket();
void SetOptions(TCP_Client_opts opts_set);
TCP_Client_opts GetOptions();
BOOL Connect(string server, int port);
int Send(string data);
int Recv(string *data);
BOOL IsConnected();
int Disconnect();
TCP_Stats GetStats();
private:
SOCKET s = SOCKET_ERROR;
TCP_Client_opts opts;
TCP_Stats stats;
BOOL connected = FALSE;
time_t starttime;
};
#endif
class.cpp:
#include "SocketsClass.h"
void XTrace(LPCTSTR lpszFormat, ...)
{
va_list args;
va_start(args, lpszFormat);
int nBuf;
TCHAR szBuffer[512]; // get rid of this hard-coded buffer
nBuf = _vsnwprintf_s(szBuffer, 511, lpszFormat, args);
::OutputDebugString(szBuffer);
va_end(args);
}
TCP_Client::TCP_Client(TCP_Client_opts opts_set)
{
SetOptions(opts_set);
}
TCP_Client::~TCP_Client()
{
Disconnect();
}
TCP_Client::TCP_Client()
{
}
void TCP_Client::SetOptions(TCP_Client_opts opts_set)
{
opts = opts_set;
}
TCP_Client_opts TCP_Client::GetOptions()
{
return opts;
}
SOCKET TCP_Client::GetSocket()
{
return s;
}
BOOL TCP_Client::IsConnected()
{
return connected;
}
int TCP_Client::Disconnect()
{
connected = FALSE;
stats.uptime = time(0) - starttime;
return shutdown(s, 2);
}
BOOL TCP_Client::Connect(string server, int port)
{
struct sockaddr_in RemoteHost;
#ifdef W32
WSADATA wsd;
if (WSAStartup(MAKEWORD(2, 2), &wsd) != 0)
{
DEBUG(L"Failed to load Winsock!\n");
return FALSE;
}
#endif
//create socket if it is not already created
if (s == SOCKET_ERROR)
{
//Create socket
s = socket(AF_INET, SOCK_STREAM, 0);
if (s == SOCKET_ERROR)
{
DEBUG(L"Could not create socket");
return FALSE;
}
}
//setup address structure
if (inet_addr(server.c_str()) == INADDR_NONE)
{
struct hostent *he;
//resolve the hostname, its not an ip address
if ((he = gethostbyname(server.c_str())) == NULL)
{
//gethostbyname failed
DEBUG(L"gethostbyname() - Failed to resolve hostname\n");
return FALSE;
}
}
else//plain ip address
{
RemoteHost.sin_addr.s_addr = inet_addr(server.c_str());
}
RemoteHost.sin_family = AF_INET;
RemoteHost.sin_port = htons(port);
//Connect to remote server
if (connect(s, (struct sockaddr *)&RemoteHost, sizeof(RemoteHost)) < 0)
{
DEBUG(L"connect() failed");
return FALSE;
}
connected = TRUE;
starttime = time(0);
stats.download = 0;
stats.upload = 0;
return TRUE;
}
TCP_Stats TCP_Client::GetStats()
{
if (connected==TRUE)
stats.uptime = time(0)-starttime;
return stats;
}
int TCP_Client::Send(string data)
{
stats.upload += data.length();
return send(s, data.c_str(), data.length(), 0);
}
int TCP_Client::Recv(string *data)
{
int ret = 0;
char buffer[512];
ret = recv(s, buffer, sizeof(buffer), 0);
data->assign(buffer);
data->resize(ret);
stats.download += data->length();
return ret;
}
main.cpp:
#include <stdio.h>
#include <string.h>
#include "SocketsClass.h"
using namespace std;
int main(int argc, char *argv)
{
TCP_Client tc;
tc.Connect("127.0.0.1", 9999);
tc.Send("HEllo");
string data;
tc.Recv(&data);
puts(data.c_str());
tc.Disconnect();
printf("\n\nDL: %i\nUP: %i\nUptime: %u\n", tc.GetStats().download, tc.GetStats().upload, tc.GetStats().uptime);
return 0;
}
Some extra questions:
Imagine I'm sending a file. How would my function know that the current data is related to the previous message?
How is my class design and implementation? SHould I change anything?
Thank you
If by "portable" you mean runs on other platforms besides Windows then a recv() loop in a worker thread is your only portable option. On Windows specifically, you have some additional choices:
Allocate a hidden window and then use WSAAsyncSelect() to receive FD_READ notifications. This requires a message loop, which you can put in a worker thread.
Use WSAEventSelect() to register a waitable event for FD_READ notifications and then wait for those events via WSAWaitForMultipleEvents() in a thread.
use WSARecv() with an I/O Completion Port. Poll the IOCP via GetQueuedCompletionResult() in a thread.
As for your question regarding messaging, TCP is a byte stream, it has no concept of messages. You have to frame your messages yourself. You can either:
give each message a fixed header that contains the message length. Read the header first, then read however many bytes it says, then read the next header, and so on.
separate each message with a unique delimiter that does not appear in the message data. Read until you encounter that delimiter, then read until the next delimiter, and so on.
Have your event loop call either poll or select to determine if there is data that can be read on the socket(s). Then read it, and call the appropriate callback function.
I was thinking of making use of Boost Asio to read data from a Socket CAN.
There's nothing fancy going on in linux/can.h , and the device should
behave like the loopback interface, and be used with a raw socket.
Looking at the basic_raw_socket interface it seems that I can make use of
basic_raw_socket::assign to assign the native socket created with
socket( PF_CAN, SOCK_RAW, CAN_RAW );
This is what I have so far
namespace can {
class CanSocket {
public:
typedef boost::asio::ip::basic_endpoint<CanSocket> endpoint;
typedef boost::asio::ip::basic_resolver_query<CanSocket> resolver_query;
typedef boost::asio::ip::basic_resolver_iterator<CanSocket> resolver_iterator;
typedef boost::asio::basic_raw_socket<CanSocket> socket;
typedef boost::asio::ip::basic_resolver<CanSocket> resolver;
CanSocket()
: _protocol( CAN_RAW )
, _family( PF_CAN )
{
}
static CanSocket v4()
{
return CanSocket();
}
static CanSocket v6();
int type() const;
int protocol() const;
int family() const;
friend bool operator==(const CanSocket& p1, const CanSocket& p2)
{
return p1._protocol != p2._protocol || p1._family != p2._family;
}
friend bool operator!=(const CanSocket& p1, const CanSocket& p2)
{
return p1._protocol == p2._protocol || p1._family == p2._family;
}
private:
int _protocol;
int _family;
};
}
And this is how I use it in my application
boost::asio::io_service ioserv;
CanSocket::socket s( ioserv );
int sock = socket( PF_CAN, SOCK_RAW, CAN_RAW );
s.assign(CanSocket::v4(), sock);
struct ifreq ifr;
strcpy(ifr.ifr_name, "vcan0");
ioctl(sock, SIOCGIFINDEX, &ifr); /* ifr.ifr_ifindex gets filled
* with that device's index */
/* Select that CAN interface, and bind the socket to it. */
/* this should be the endpoint */
struct sockaddr_can addr;
addr.can_family = AF_CAN;
addr.can_ifindex = ifr.ifr_ifindex;
/* s.bind (....) */
bind( sock, (struct sockaddr*)&addr, sizeof(addr) );
What I don't quite get is how do I bind s to the local endpoint? There are no IPs or ports involved.
Is there anything else that should be implemented besides the endpoint to get it going?
Here is working example, assembled with help of this thread
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <iostream>
#include <net/if.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <linux/can.h>
#include <linux/can/raw.h>
#include <boost/asio.hpp>
#include <boost/bind.hpp>
void data_send(void) {
std::cout << "omg sent" << std::endl;
}
void data_rec(struct can_frame &rec_frame,
boost::asio::posix::basic_stream_descriptor<> &stream) {
std::cout << std::hex << rec_frame.can_id << " ";
for (int i = 0; i < rec_frame.can_dlc; i++) {
std::cout << std::hex << int(rec_frame.data[i]) << " ";
}
std::cout << std::dec << std::endl;
stream.async_read_some(
boost::asio::buffer(&rec_frame, sizeof(rec_frame)),
boost::bind(data_rec, boost::ref(rec_frame), boost::ref(stream)));
}
int main(void) {
struct sockaddr_can addr;
struct can_frame frame;
struct can_frame rec_frame;
struct ifreq ifr;
int natsock = socket(PF_CAN, SOCK_RAW, CAN_RAW);
strcpy(ifr.ifr_name, "vcan0");
ioctl(natsock, SIOCGIFINDEX, &ifr);
addr.can_family = AF_CAN;
addr.can_ifindex = ifr.ifr_ifindex;
if (bind(natsock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
perror("Error in socket bind");
return -2;
}
frame.can_id = 0x123;
frame.can_dlc = 2;
frame.data[0] = 0x11;
frame.data[1] = 0x23;
boost::asio::io_service ios;
boost::asio::posix::basic_stream_descriptor<> stream(ios);
stream.assign(natsock);
stream.async_write_some(boost::asio::buffer(&frame, sizeof(frame)),
boost::bind(data_send));
stream.async_read_some(
boost::asio::buffer(&rec_frame, sizeof(rec_frame)),
boost::bind(data_rec, boost::ref(rec_frame), boost::ref(stream)));
ios.run();
}
The solution is to use posix::stream_descriptor.
Just open the native socket, bind and then use posix::basic_stream_descriptor::assign.