Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Cannot read data from a Packet  (Read 2424 times)

0 Members and 1 Guest are viewing this topic.

Charsmud

  • Newbie
  • *
  • Posts: 30
    • View Profile
Cannot read data from a Packet
« on: January 26, 2014, 05:10:14 am »
Hello.  I was reading this (http://www.sfml-dev.org/tutorials/2.1/network-packet.php) and am trying to extract data from my packet.  However, for some reason, this error appears:  "No operator "<<" matches these operands".  Here is my file:

Code: [Select]
#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 << "SOEMTHING 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)
{

}

ClientPacket::Type packetType;

if(packet >> packetType)
{
std::cout << "Player Quit!" << std::endl;
}


std::cout << "Recieved " << recieved << " bytes from " << mSender << " on port " << port << std::endl;
}

sf::Packet packet;

packet << ServerPacket::ServerStop;

if(mSocket.send(packet, mSender, port) != sf::Socket::Done)
{
std::cout << "I AM SAD" << std::endl;
}
}

and here is the affected line:

Code: [Select]
ClientPacket::Type packetType;

if(packet >> packetType)
{
std::cout << "Player Quit!" << std::endl;
}
Any ideas?

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Cannot read data from a Packet
« Reply #1 on: January 26, 2014, 08:13:25 am »
Apparently you don't read very far... How do you expect SFML to understand your custom type without defining any operators for working with your type?   ???

http://www.sfml-dev.org/tutorials/2.1/network-packet.php#extending-packets-to-handle-user-types
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor