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

Author Topic: error with server (SFML 2.0)  (Read 2237 times)

0 Members and 1 Guest are viewing this topic.

whiteonion

  • Newbie
  • *
  • Posts: 1
    • View Profile
error with server (SFML 2.0)
« on: December 20, 2011, 05:30:42 am »
Hi! I'm new to network programming and I'm trying to write a simple server program using a socket selector in visual studio 2010.
When ever I try to build the program I get the following error:

Error   1   error C2248: 'sf::NonCopyable::NonCopyable' : cannot access private member declared in class 'sf::NonCopyable'
File:socket.hpp
line 177

This is the only error I get.
I wonder if there is something obvious that is wrong with the code that I just don't understand.


Code: [Select]


#include "stdafx.h"
#include <iostream>
#include <list>
#include <SFML/System.hpp>
#include <SFML/Network.hpp>

void DoServer(unsigned short Port)
{
sf::TcpListener Listener;
    std::list<sf::TcpSocket*> Clients;
    if (!Listener.Listen(Port))
        return;
sf::SocketSelector Selector;

    Selector.Add(Listener);

    while (true)
    {
if( Selector.Wait() )
{
if( Selector.IsReady( Listener ) )
{
sf::TcpSocket* client = new sf::TcpSocket;
if( Listener.Accept( *client ) == sf::Socket::Done )
{
Clients.push_back( client );
Selector.Add( *client );
client->SetBlocking( false );


}
}
else
{
for( std::list<sf::TcpSocket*>::iterator it = Clients.begin();it != Clients.end(); )
{
sf::TcpSocket client = **it;
if( Selector.IsReady( client ) )
{
sf::Packet packet;
sf::Socket::Status state = client.Receive( packet );
if( state == sf::Socket::Done )
{
//code for sending packet to all clients
continue;

}
else if( state == sf::Socket::Disconnected )
{
Selector.Remove( client );
it = Clients.erase( it );
}
}
else
{
++it;
}
}
}
}
    }
}

int main()
{
DoServer(4567);
return 0;
}


Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
error with server (SFML 2.0)
« Reply #1 on: December 20, 2011, 08:32:22 am »
Code: [Select]
sf::TcpSocket client = **it;
This line makes a copy of the socket, but sockets are not copyable. Use a reference instead (sf::TcpSocket&).
Laurent Gomila - SFML developer