Hello! I am having an error with my UdpSocket when I try to send a packet from the server to the client. When the packet is supposed to be sent, it triggers my if loop and prints out "I AM SAD":
#include "ServerCore.hpp"
#include "Packet.hpp"
#include <SFML/Network/IpAddress.hpp>
#include <iostream>
ServerCore::ServerCore(int port)
: mSocket()
{
mPort = port;
}
void ServerCore::enterServerLoop()
{
if(mSocket.bind(mPort) != sf::Socket::Done)
{
std::cout << "SOMETHING DIDNT WORK" << std::endl;
}
std::cout << "Initialized Server" << std::endl;
unsigned short port;
sf::IpAddress ip;
while(true)
{
std::cout << ":D" << std::endl;
sf::Packet packet;
std::size_t recieved;
if(mSocket.receive(packet, ip, port) != sf::Socket::Done)
{
}
int x;
if(packet >> x)
{
if(x == ClientPacket::PlayerConnect)
{
std::cout << "Player Connected!" << std::endl;
sf::Packet packet;
packet << ServerPacket::ServerStop;
if(mSocket.send(packet, mSender, 54000) != sf::Socket::Done)
{
std::cout << "I AM SAD" << std::endl;
}
}
if(x == ClientPacket::PlayerDisconnect)
std::cout << "Player Disconnected!" << std::endl;
if(x == ClientPacket::PlayerQuit)
std::cout << "Player Quit!" << std::endl;
if(x == ClientPacket::PlayerJoin)
std::cout << "Player Join!" << std::endl;
}
std::cout << "Recieved " << recieved << " bytes from " << ip << " on port " << port << std::endl;
}
sf::Packet packet2;
packet2 << ServerPacket::ServerStop;
/*if(mSocket.send(packet2, mSender, 54000) != sf::Socket::Done)
{
std::cout << "I AM SAD" << std::endl;
}*/
}
Everything else works except for the mSocket.send if loop inside of if(x == ClientPacket::PlayerConnect). I was thinking of doing an error check to see what the actual error is but I couldn't figure out how to do this. Any suggestions on how to fix this or check the error?
EDIT: I managed to fix the problem: I was referencing the wrong IP var.