i'm triying to connect to socket.io server, but it doesn't work.
server source :
var socketio = require('socket.io');
var port = 3303;
var io = socketio.listen(port);
io.sockets.on('connection',function(socket){
console.log('hi');
io.sockets.on('connection',function(data){
console.log(data);
});
});
client source :
#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
sf::IpAddress ipAddress = sf::IpAddress::LocalHost;
//TCP
sf::TcpSocket socket;
sf::Socket::Status status = socket.connect(ipAddress, 3303);
if(status != sf::Socket::Done)
{
printf("connection error!\n");
}
else{
printf("IP Address : %s\n", ipAddress.toString().c_str());
}
if (socket.send("connection", 11) != sf::Socket::Done)
{
// error...
}
//UDP
/*
sf::UdpSocket socket;
if (socket.bind(3303))
{
printf("connection error!\n");
}
if (socket.send("hi", 3, ipAddress, 3303) != sf::Socket::Done)
{
printf("sending error!\n");
}
*/
shape.setFillColor(sf::Color::Green);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed){
socket.disconnect();
window.close();
}
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
there's no error when running client, but the server doesn't respond.
How can I connect to Node.js socket.io server in SFML client?