Hi, I have made a server using netty and a java client (it works).
Now I’d like to make a connection with SocketIO copying from ccp tests (cocos 3.8.1) but I have this result:
SIOClientImpl::handshake() failed
error buffer: The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.
SocketIOTest::onError received: The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.
Does the server support wss? If you want to use wss to access the server, the server is required to configure with SSL support.
Does the client support wss? I don’t know whether the ssl is support by SocketIO in cocos2d-x, as I know, libwebsockets in cocos2d-x isn’t compiled with ssl support, please check this issue.
thanks for response. I have tryed with supporting ssl and not.
It is a game server that listen for connection
I can connect with this code in plain c without problems and I receive the message from server “Hello!”:
int sockfd, portno, n;
struct sockaddr_in serv_addr;
struct hostent *server;
char buffer[1024];
portno = 8992;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
perror("ERROR opening socket");
server = gethostbyname("localhost");
if (server == NULL) {
fprintf(stderr,"ERROR, no such host\n");
exit(0);
}
bzero((char *) &serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
bcopy((char *)server->h_addr,
(char *)&serv_addr.sin_addr.s_addr,
server->h_length);
serv_addr.sin_port = htons(portno);
if (connect(sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0)
perror("ERROR connecting");
/*
printf("Please enter the message: ");
bzero(buffer,256);
fgets(buffer,255,stdin);
n = write(sockfd,buffer,strlen(buffer));
if (n < 0)
perror("ERROR writing to socket");
*/
while (true) {
bzero(buffer,1024);
n = read(sockfd,buffer,1024);
if (n < 0)
perror("ERROR reading from socket");
printf("leggo: %s\n",buffer);
if (buffer[0]=='{') {
rapidjson::Document document;
document.Parse<0>(buffer);
const char *tipo = document["type"].GetString();
printf("**** %s *****",tipo);
}
}
close(sockfd);
<key>NSAppTransportSecurity</key>
<dict>
<!--Include to allow all connections (DANGER)-->
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
but I have received this error now:
In the constructor of HttpClient!
2015-12-18 19:58:03.531 PPA-mobile[3356:105281] Starting to load http://localhost:8992/socket.io/1/?EIO=2&transport=polling&b64=true
SIOClientImpl::handshake() failed
error buffer: The network connection was lost.
SocketIOTest::onError received: The network connection was lost.
So I can not use SocketIO for now right?
Can I use some other library?
Or where should I modify SocketIO to reflect iOS9 ATS?
thanks
The SocketIO client is using WebSockets internally only. You cannot use a transport other than that.
Beats me. I don’t use SocketIO so I don’t know of any except Socket.IO C++ | Socket.IO.
It’s based on Boost and WebSocket++(which supports TLS).
You would have to adopt the SocketIO client and the WebSocket client, as it is used internally. cocos2d-x uses libwebsocket, which is not compiled with TLS support. There are third party WebSocket libs out there, which can be used on it’s own or have to be integrated into the client implementations of cocos2d-x.