boost asio socket connecting problem

the following code
1
2
tcp::endpoint end_point(boost::asio::ip::address::from_string("192.168.1.100"), 80);
_html_socket->connect(end_point, err);

works perfectly on Windows. An equivalent Python code also works on Linux.

What I was doing is to connect the computer to an ad hoc host at 192.168.1.100.
Error returned : system:22, from what I learned, is "invalid arguments"

I have no idea how to solve this, and need your help.

Thanks in advance,
Hai
could you please show full example ?
sure, here you go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
char	read_buffer[2048];	// temporary receive buffer
size_t len;					// length of bytes sent/received
boost::system::error_code err;	// error code

// bind host & port
tcp::endpoint end_point(boost::asio::ip::address::from_string("192.168.1.100"), 80);

// Http posting
_html_socket->connect(end_point, err);
if(err)
{
	slog("HTML socket unable to connect");
	start_error(err);
	return false;
}
	
// set socket to blocking. send/receive will block until error/finish
_html_socket->non_blocking(false);
		
// HTTP message
std::string str("GET /check_user.cgi?user=AC13&pwd=AC13 HTTP/1.1\r\nHost: 192.168.1.100:80\r\nUser-Agent: WifiCar/1.0 CFNetwork/485.12.7 Darwin/10.4.0\r\nAccept: */*\r\nAccept-Language: en-us\r\nAccept-Encoding: gzip, deflate\r\nConnection: keep-alive\r\n\r\n");
// send
len = boost::asio::write(*_html_socket, boost::asio::buffer(str), boost::asio::transfer_all(), err);
if(err)
{
	slog("HTTP socket failed to send data");
	start_error(err);
	return false;
}
// receive		
memset(read_buffer, 0, sizeof(read_buffer));
len = _html_socket->receive(boost::asio::buffer(read_buffer, sizeof(read_buffer)),
boost::asio::socket_base::message_end_of_record, err);
if(err)
{
	slog("HTTP socket failed to receive data");
	start_error(err);
	return false;
}
	
		
// close the HTTP socket
_html_socket->shutdown(tcp::socket::shutdown_both);
_html_socket->close();
		
/////////////////////////////////////////////////////////////////////
// command socket
_cmd_socket->connect(end_point, err);
if(err)
{
	slog("Command socket unable to connect");
	start_error(err);
	return false;
}

_cmd_socket->non_blocking(false);

// init sequence
RoverCommandMsg msg;
		
// message 1
msg = RoverCommandMsg(RoverCommandMsg::CMD_INIT1);
// send message 1
len = boost::asio::write(*_cmd_socket, boost::asio::buffer(msg.data(), msg.msg_length()), boost::asio::transfer_all(), err);
if(err)
{
	slog("unable to send msg 1");
	start_error(err);
	return false;
}

// receive response
memset(read_buffer, 0, sizeof(read_buffer));
len = _cmd_socket->receive(boost::asio::buffer(read_buffer, 2048), boost::asio::socket_base::message_end_of_record, err);
if(err)
{
	slog("unable to receive res 1");
	start_error(err);
	return false;
}

// message 2
msg = RoverCommandMsg(RoverCommandMsg::CMD_INIT2);
// send message 2
len = boost::asio::write(*_cmd_socket, boost::asio::buffer(msg.data(), msg.msg_length()), boost::asio::transfer_all(), err);
if(err)
{
	slog("unable to send msg 2");
	start_error(err);
	return false;
}
// receive response
memset(read_buffer, 0, sizeof(read_buffer));
len = _cmd_socket->receive(boost::asio::buffer(read_buffer, 2048), boost::asio::socket_base::message_end_of_record, err);
if(err)
{
	slog("unable to receive res 2");
	start_error(err);
	return false;
}
		
// message 3
msg = RoverCommandMsg(RoverCommandMsg::CMD_INIT3);
// send message 3
len = boost::asio::write(*_cmd_socket, boost::asio::buffer(msg.data(), msg.msg_length()), boost::asio::transfer_all(), err);
if(err)
{
	slog("unable to send msg 3");
	start_error(err);
	return false;
}
// receive response
memset(read_buffer, 0, sizeof(read_buffer));
len = _cmd_socket->receive(boost::asio::buffer(read_buffer, 2048), boost::asio::socket_base::message_end_of_record, err);
if(err)
{
	slog("unable to receive res 3");
	start_error(err);
	return false;
}
		
//////////////////////////////////////////////////
// video socket
_vid_socket->connect(end_point, err);
if(err)
{
	slog("video socket unable to connect");
	start_error(err);
	return false;
}
		
// init video message
memcpy(_vid_cmd, read_buffer + 25, 4);	// copy info returned by INIT3 message
		
msg = RoverCommandMsg(RoverCommandMsg::CMD_INIT_VID, _vid_cmd, 4);
boost::asio::write(*_vid_socket, boost::asio::buffer(msg.data(), msg.msg_length()), boost::asio::transfer_all(), err);
if(err)
{
	slog("unable to send msg VID");
	start_error(err);
	return false;
}


It's a sequence of initialization to control a device via ad hoc. Sorry I couldn't post the full source, it includes several files and lots of code.
I faced the error right at the first connecting command with _html_socket.
It works flawlessly on Windows, and so does the equivalent Python version on both Win & Linux.
No ideas what caused the error 22. I guess there's something to do with the kernel regarding stack management, but what is it?
Last edited on
Topic archived. No new replies allowed.