我正在尝试使用websocket
库在C ++中实现poco
客户端。
根据我的理解,首先是创建到目标服务器的套接字连接,并发送http请求和升级连接到websocket。
在poco库中,Poco::Net:::HTTPClientSession
有方法:
setProxy
setProxyCredentials
setProxyHost
setProxyPort
等
我使用这些方法来渗透代理,相对于客户端控制台,它显示它已连接并将请求发送到服务器,而在服务器控制台没有收到任何信息。当我从客户端捕获数据包跟踪时,观察到与代理服务器而不是目标服务器建立的连接。
Git hub项目https://github.com/hannon235/socket.io-poco/tree/master/socket.io-poco
提供的示例代码小队(清除操作系统)代理正在使用中。
我在论坛中阅读代理设置需要更改或openssl / https需要使用。 当我尝试使用安全连接时,数据包跟踪显示与目标服务器建立的连接但消息未到达服务器。我不确定连接消息的安全性如何发送到服务器。
我想知道websocket如何与代理安全连接。
示例代码如下。
int main()
{
//create a c++ Poco logger to use and set its channel to the windows console
//this is the same logger instance that the library will hook into
Logger *logger = &(Logger::get("SIOClientLog"));
logger->setChannel(new WindowsConsoleChannel());
//Establish the socket.io connection
//JS: var socket = io.connect("localhost:3000")
//SIOClient *sio = SIOClient::connect("https://myserver:8004"); this also not working
SIOClient *sio = SIOClient::connect("http://myserver:8004");
//Create a target and register object its method onUpdate for the Update event
TestTarget *target = new TestTarget();
sio->on("Update", target, callback(&TestTarget::onUpdate));
//setup is now complete, messages and events can be send and received
logger->information("sio setup complete\n");
logger->information("emitting test event\n");
sio->emit("hello", "[{\"name\":\"myname\",\"type\":\"mytype\"}]");
//wait for user input to move to next section of code
//socket receiving occurs in another thread and will not be halted
logger->information("Press ENTER to continue...");
std::cin.get();
//disconnecting the default socket with no endpoint will also disconnect all endpoints
sio->disconnect();
logger->information("Press ENTER to quit...");
std::cin.get();
return 0;
}
修改握手功能如下:
bool SIOClientImpl::handshake() {
UInt16 aport = _port;
_session = new HTTPClientSession(_host, aport);
_session->setProxy("192.168.60.2",8080);
_session->setProxyCredentials("user1","user1");
_session->setKeepAlive(TRUE);
HTTPRequest req(HTTPRequest::HTTP_GET,"/socket.io/1",HTTPMessage::HTTP_1_1);
req.setKeepAlive(TRUE);
HTTPResponse res;
try {
_session->sendRequest(req);
} catch (std::exception &e) {
return false;
}
std::istream& rs = _session->receiveResponse(res);
std::cout << res.getStatus() << " " << res.getReason() << std::endl;
....
}