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

Author Topic: Trying to write a Network server...error C2280  (Read 2054 times)

0 Members and 1 Guest are viewing this topic.

vdrenzo

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Trying to write a Network server...error C2280
« on: May 23, 2017, 02:15:55 pm »
Trying to write a Network server that waits 60 sec for incoming connections.

I am doing something wrong but I cant figure it out!
#include <iostream>
#include <SFML/Network.hpp>

int main()
{
        sf::TcpListener listener;

        // bind the listener to a port
        if (listener.listen(54345) != sf::Socket::Done)
        {
                std::cout << "error listener" << std::endl;
        }

        sf::SocketSelector selector;
        selector.add(listener);

        std::vector<sf::TcpSocket> clients;


        if (selector.wait(sf::seconds(60)))
        {
                if (selector.isReady(listener))//test listener for new connections
                {
                        sf::TcpSocket client;
                        if (listener.accept(client) != sf::Socket::Done)
                        {
                                std::cout << "error accepter" << std::endl;
                        }
                        else
                        {
                                std::cout << "Client accepted" << std::endl;
                                clients.push_back(client);
                                selector.add(clients[clients.size()-1]);
                        }
                }
                else // listener not ready, so check all the other clients
                {
                        if (clients.size() > 0)
                        {
                                for (int i = 0; i < clients.size(); i++)
                                {
                                        if (selector.isReady(clients[i]))//test clients for recv datas
                                        {
                                                std::cout << "client sent data" << std::endl;
                                        }
                                }
                        }
                }      
        }

        return 0;
}
 

error message:
1>------ Erstellen gestartet: Projekt: Snake Server, Konfiguration: Debug Win32 ------
1>main.cpp
1>c:\users\vinc\documents\visual studio 2017\projects\snake server\snake server\main.cpp(40): warning C4018: "<": Konflikt zwischen "signed" und "unsigned"
1>d:\programme\visualstudio 2017\vc\tools\msvc\14.10.25017\include\xmemory0(840): error C2280: "sf::TcpSocket::TcpSocket(const sf::TcpSocket &)" : Es wurde versucht, auf eine gelöschte Funktion zu verweisen
1>d:\programme\visualstudio 2017\sfml-2.4.2 32bit\include\sfml\network\tcpsocket.hpp(231): note: Compiler hat hier "sf::TcpSocket::TcpSocket" generiert
1>d:\programme\visualstudio 2017\vc\tools\msvc\14.10.25017\include\xmemory0(959): note: Siehe Verweis auf die Instanziierung der gerade kompilierten Funktions-Vorlage "void std::allocator<_Ty>::construct<_Objty,const _Ty&>(_Objty *,const _Ty &)".
1>        with
1>        [
1>            _Ty=sf::TcpSocket,
1>            _Objty=sf::TcpSocket
1>        ]
1>d:\programme\visualstudio 2017\vc\tools\msvc\14.10.25017\include\xmemory0(959): note: Siehe Verweis auf die Instanziierung der gerade kompilierten Funktions-Vorlage "void std::allocator<_Ty>::construct<_Objty,const _Ty&>(_Objty *,const _Ty &)".
1>        with
1>        [
1>            _Ty=sf::TcpSocket,
1>            _Objty=sf::TcpSocket
1>        ]
1>d:\programme\visualstudio 2017\vc\tools\msvc\14.10.25017\include\xmemory0(1097): note: Siehe Verweis auf die Instanziierung der gerade kompilierten Funktions-Vorlage "void std::allocator_traits<_Alloc>::construct<_Ty,const _Ty&>(std::allocator<_Ty> &,_Objty *,const _Ty &)".
1>        with
1>        [
1>            _Alloc=std::allocator<sf::TcpSocket>,
1>            _Ty=sf::TcpSocket,
1>            _Objty=sf::TcpSocket
1>        ]
1>d:\programme\visualstudio 2017\vc\tools\msvc\14.10.25017\include\xmemory0(1096): note: Siehe Verweis auf die Instanziierung der gerade kompilierten Funktions-Vorlage "void std::allocator_traits<_Alloc>::construct<_Ty,const _Ty&>(std::allocator<_Ty> &,_Objty *,const _Ty &)".
1>        with
1>        [
1>            _Alloc=std::allocator<sf::TcpSocket>,
1>            _Ty=sf::TcpSocket,
1>            _Objty=sf::TcpSocket
1>        ]
1>d:\programme\visualstudio 2017\vc\tools\msvc\14.10.25017\include\vector(928): note: Siehe Verweis auf die Instanziierung der gerade kompilierten Funktions-Vorlage "void std::_Wrap_alloc<std::allocator<_Ty>>::construct<_Ty,const _Ty&>(_Ty *,const _Ty &)".
1>        with
1>        [
1>            _Ty=sf::TcpSocket
1>        ]
1>d:\programme\visualstudio 2017\vc\tools\msvc\14.10.25017\include\vector(928): note: Siehe Verweis auf die Instanziierung der gerade kompilierten Funktions-Vorlage "void std::_Wrap_alloc<std::allocator<_Ty>>::construct<_Ty,const _Ty&>(_Ty *,const _Ty &)".
1>        with
1>        [
1>            _Ty=sf::TcpSocket
1>        ]
1>d:\programme\visualstudio 2017\vc\tools\msvc\14.10.25017\include\vector(947): note: Siehe Verweis auf die Instanziierung der gerade kompilierten Funktions-Vorlage "void std::vector<sf::TcpSocket,std::allocator<_Ty>>::emplace_back<const _Ty&>(const _Ty &)".
1>        with
1>        [
1>            _Ty=sf::TcpSocket
1>        ]
1>d:\programme\visualstudio 2017\vc\tools\msvc\14.10.25017\include\vector(947): note: Siehe Verweis auf die Instanziierung der gerade kompilierten Funktions-Vorlage "void std::vector<sf::TcpSocket,std::allocator<_Ty>>::emplace_back<const _Ty&>(const _Ty &)".
1>        with
1>        [
1>            _Ty=sf::TcpSocket
1>        ]
1>d:\programme\visualstudio 2017\vc\tools\msvc\14.10.25017\include\vector(946): note: Bei der Kompilierung von Klasse Vorlage der void std::vector<sf::TcpSocket,std::allocator<_Ty>>::push_back(const _Ty &)-Memberfunktion
1>        with
1>        [
1>            _Ty=sf::TcpSocket
1>        ]
1>c:\users\vinc\documents\visual studio 2017\projects\snake server\snake server\main.cpp(32): note: Siehe Verweis auf die Instanziierung der gerade kompilierten Funktions-Vorlage "void std::vector<sf::TcpSocket,std::allocator<_Ty>>::push_back(const _Ty &)".
1>        with
1>        [
1>            _Ty=sf::TcpSocket
1>        ]
1>c:\users\vinc\documents\visual studio 2017\projects\snake server\snake server\main.cpp(17): note: Siehe Verweis auf die Klasse Vorlage-Instanziierung "std::vector<sf::TcpSocket,std::allocator<_Ty>>", die kompiliert wird.
1>        with
1>        [
1>            _Ty=sf::TcpSocket
1>        ]
1>d:\programme\visualstudio 2017\sfml-2.4.2 32bit\include\sfml\network\tcpsocket.hpp(231): note: "sf::TcpSocket::TcpSocket(const sf::TcpSocket &)": Die Funktion wurde implizit gelöscht, weil eine Basisklasse eine Funktion "sf::Socket::Socket(const sf::Socket &)" aufruft, die gelöscht wurde oder auf die nicht zugegriffen werden kann.
1>d:\programme\visualstudio 2017\sfml-2.4.2 32bit\include\sfml\network\socket.hpp(179): note: "sf::Socket::Socket(const sf::Socket &)": Die Funktion wurde implizit gelöscht, weil eine Basisklasse eine Funktion "sf::NonCopyable::NonCopyable(const sf::NonCopyable &)" aufruft, die gelöscht wurde oder auf die nicht zugegriffen werden kann.
1>Die Erstellung des Projekts "Snake Server.vcxproj" ist abgeschlossen -- FEHLER.
========== Erstellen: 0 erfolgreich, 1 fehlerhaft, 0 aktuell, 0 übersprungen ==========

Can someone help?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Trying to write a Network server...error C2280
« Reply #1 on: May 23, 2017, 02:44:15 pm »
SFML socket classes are not copyable, you can't store them in a std::vector. The most common solution is to store (smart) pointers to sockets instead.
Laurent Gomila - SFML developer

vdrenzo

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Trying to write a Network server...error C2280
« Reply #2 on: May 23, 2017, 02:53:45 pm »
Ok, thank you. I managed to do it with pointers now!
Also i found an example at the bottom of the page:

https://www.sfml-dev.org/documentation/2.0/classsf_1_1SocketSelector.php

 

anything