1
Network / Re: Bytes sent is greater than MaxDatagramSize
« on: March 11, 2017, 04:02:59 am »
Ignore this, I figured out my issue... I mistyped and was writing to p instead of p2.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
NetworkHandler::NetworkHandler(IpAddress server, int serverPort, int myPort) : mThread(&NetworkHandler::handleNetworking, this)
{
mServerIp = server;
mServerPort = serverPort;
mMyPort = myPort;
mSocket.bind(myPort);
mThread.launch();
}
void NetworkHandler::handleNetworking()
{
cout << sf::UdpSocket::MaxDatagramSize << endl;
Packet p;
p << "newclient" << "charsmud";
Socket::Status s = mSocket.send(p, mServerIp, mServerPort);
while (true)
{
for (int i = 0; i < 10; i++)
{
if (i == 9)
{
Packet p2;
p << "pinger";
Socket::Status l = mSocket.send(p, mServerIp, mServerPort);
}
}
}
}
That line should create the heartbeat objectBut it does not store it in the unique pointer. I wonder why this even compiles, maybe an overloaded operator() in the standard library?The container will not accept the unique pointer, so could I pass a memory address to it?No... But you have to tell me what you want to do (semantically), not vice versa. Either you want to store it in the container, and then you make it work, or you don't...
That line should create the heartbeat object and the object initialization should start the thread. The container will not accept the unique pointer, so could I pass a memory address to it?mBeat(new Heartbeat(player.getIp()));What should this line do? Did you mean to call reset()?
And I thought you want to add the heartbeat object to a container, not store it as single member, don't you?
It would create a new instance every time, and lead to a memory leak.
Avoid raw new and delete and use RAII (here std::unique_ptr) instead. Or consider the alternative in my last post: move semantics.