#include "SFML/Network.hpp"
#include "SFML/Graphics.hpp"
#include<iostream>
#include<string>
using namespace sf;
using namespace std;
static bool port_is_open(const std::string& address, int port)
{
return (sf::TcpSocket().connect(address, port) == sf::Socket::Done);
}
int main()
{
string machine;
string serverIp = "93.171.161.201";
if (serverIp == IpAddress::getPublicAddress())
machine = "server";
else machine = "client";
if (machine == "client")
{
Packet packet;
cout << "Ya client" << endl;
TcpSocket socket;
if (socket.connect(serverIp, 5007) == Socket::Done)
cout << "You are connected now" << endl;
else cout << "none" << endl;
while (true)
{
if(socket.receive(packet) == Socket::Done)
{
Vector2i coords;
packet >> coords.x >> coords.y;
Mouse::setPosition(coords);
}
}
}
else
{
cout << "Ya server" << endl;
TcpListener listener;
listener.listen(5007);
TcpSocket client;
if (listener.accept(client) == Socket::Done)
cout << "All Done" << endl;
Packet packet;
while (true)
{
packet.clear();
packet << Mouse::getPosition().x << Mouse::getPosition().y;
client.send(packet);
}
}
return 0;
}
Компьютер находится за NAT
Коннект работает только в локальной сети. Вот мой проброс порта :
До сих пор не работает. Буду благодарен за помощь
telnet <ip> <port>