SFML community forums

Help => General => Topic started by: MarcuzPwnz on February 17, 2013, 05:00:36 am

Title: Networking and Code::Blocks
Post by: MarcuzPwnz on February 17, 2013, 05:00:36 am
Hello there! I have been trying to compile the following code in Code::Blocks

#include <iostream>
#include <SFML/Network.hpp>

using namespace sf;
using namespace std;

int main(){
    cout << "Would you like to be a server or client? (s/c)" << endl;
    char choice;
    cin >> choice;
    if(choice == 's'){
        TcpListener listener;
        listener.listen(1337);
        std::string message = "";
        Packet serverPacket;
        while(true){
            TcpSocket client;
            if(listener.accept(client) == Socket::Done){
                cout << "Client has connected from " << client.getRemoteAddress() << endl;
                cout << "Send message to client: ";
                cin >> message;
                serverPacket << message;
                client.send(serverPacket);
            }
        }
    }else{
        Packet clientPacket;
        std::string messageSent;
        TcpSocket socket;
        if(socket.connect("localhost", 1337)){
            cout << "Unable to find server." << endl;
        }else{
            cout << "Connected to server!" << endl;
        }
        while(true){
            socket.receive(clientPacket);
            if(clientPacket >> messageSent){
                cout << "[Server] " << messageSent << endl;
            }
        }
    }
    return 0;
}

I have followed the tutorial for SFML 2.0 on Windows using Code::Blocks and can run most applications I make fine.

I have only added sfml-graphics-s, sfml-window-s and sfml-system-s and their debugging equivalents to my linker options, am I suppose to add sfml-network-s to make this code compile and run correctly? :)

The reason I have not tried this myself already is because I'm not sure if sfml-network-s even exists and if it does what order I would add it into the linker options.

Thanks for reading. :)

Title: Re: Networking and Code::Blocks
Post by: Weeve on February 17, 2013, 05:06:03 am
Sfml/Network is dependent only on Sfml/System :)

whether there is or is not a sfml-network-s I'm not sure.. have never used it, buy try including it anyway, and ittl yell at you if it dosn't exist, knowing the way sfml works, however, I'm pretty sure it exists
Title: Re: Networking and Code::Blocks
Post by: MarcuzPwnz on February 17, 2013, 05:13:04 am
Well then if it's dependent of sfml-system then i'm sure that's not the reason I'm getting errors, I have always had trouble compiling my code I write on Mac on Windows, I guess I'll just mess around until I get it to work.
Title: Re: Networking and Code::Blocks
Post by: Rosme on February 17, 2013, 05:16:47 am
You mean you didn't even took a look into the files to see that there is a sfml-network[-d-s].lib? And all your answer are on the website. I'll give you the link so you know the order, but do a little ressearch next time. Linking tutorial (http://www.sfml-dev.org/tutorials/2.0/start-cb.php)
Title: Re: Networking and Code::Blocks
Post by: MarcuzPwnz on February 17, 2013, 05:21:55 am
I knew the order on that tutorial. I just didn't see an sfml-network or anything on there so I wouldn't have known where to put that.

I have tried compiling and running the following code:
#include <SFML/Network.hpp>

using namespace sf;

int main(){
sf::TcpListener listener;
return 0;
}
 

And I get the errors:
-------------- Build: Debug in SFML Networtk (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -Wall  -g    -I..\..\..\Downloads\SFML-2.0-rc\include -I"C:\Program Files\CodeBlocks\include"  -c "C:\Users\newowner\Desktop\C++\SFML Networtk\main.cpp" -o obj\Debug\main.o
mingw32-g++.exe -L..\..\..\Downloads\SFML-2.0-rc\lib -L"C:\Program Files\CodeBlocks\lib"  -o "bin\Debug\SFML Networtk.exe" obj\Debug\main.o    -lsfml-graphics-d -lsfml-window-d -lsfml-system-d -lmingw32
obj\Debug\main.o: In function `main':
C:/Users/newowner/Desktop/C++/SFML Networtk/main.cpp:6: undefined reference to `_imp___ZN2sf11TcpListenerC1Ev'
obj\Debug\main.o: In function `~TcpListener':
C:\Users\newowner\Desktop\C++\SFML Networtk/../../../Downloads/SFML-2.0-rc/include/SFML/Network/TcpListener.hpp:43: undefined reference to `_imp___ZTVN2sf11TcpListenerE'
C:\Users\newowner\Desktop\C++\SFML Networtk/../../../Downloads/SFML-2.0-rc/include/SFML/Network/TcpListener.hpp:43: undefined reference to `_imp___ZN2sf6SocketD2Ev'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 3 seconds)
3 errors, 0 warnings (0 minutes, 3 seconds)

It works fine before I add a TcpListener, any ideas?
Title: Re: Networking and Code::Blocks
Post by: Rosme on February 17, 2013, 06:12:26 am
You are not linking to sfml-network.
Title: Re: Networking and Code::Blocks
Post by: MarcuzPwnz on February 17, 2013, 06:23:04 am
What order would I add them in then?

sfml-graphics
sfml-window
sfml-system


where does sfml-network go?
Title: AW: Networking and Code::Blocks
Post by: eXpl0it3r on February 17, 2013, 08:27:36 am
Infront of the sfml-system.
Title: Re: Networking and Code::Blocks
Post by: MarcuzPwnz on February 17, 2013, 08:22:40 pm
Thanks :) and for future reference where would sfml-audio be placed?
Title: AW: Networking and Code::Blocks
Post by: eXpl0it3r on February 17, 2013, 08:43:53 pm
Also infront of sfml-system.
Title: Re: Networking and Code::Blocks
Post by: MarcuzPwnz on February 17, 2013, 09:11:39 pm
So the following would be correct? :)

sfml-graphics
sfml-window
sfml-network
sfml-audio
sfml-system
Title: AW: Networking and Code::Blocks
Post by: eXpl0it3r on February 17, 2013, 09:50:31 pm
Yes.

You can think about it the way: graphics depend on window, which depends on system. Audio and neteork both depend on system aswell. Thus you put libraries that depend on other libraries infront of the other library.