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

Author Topic: Networking and Code::Blocks  (Read 5437 times)

0 Members and 1 Guest are viewing this topic.

MarcuzPwnz

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Networking and Code::Blocks
« 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. :)


Weeve

  • Jr. Member
  • **
  • Posts: 87
  • C++ Programmer (Intermediate), 3D Artist (Skilled)
    • View Profile
    • Email
Re: Networking and Code::Blocks
« Reply #1 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
Long live rapid project development! -- Kestrel3D Game-Engine nearing completion

MarcuzPwnz

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Re: Networking and Code::Blocks
« Reply #2 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.

Rosme

  • Full Member
  • ***
  • Posts: 169
  • Proud member of the shoe club
    • View Profile
    • Code-Concept
Re: Networking and Code::Blocks
« Reply #3 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
GitHub
Code Concept
Twitter
Rosme on IRC/Discord

MarcuzPwnz

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Re: Networking and Code::Blocks
« Reply #4 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?

Rosme

  • Full Member
  • ***
  • Posts: 169
  • Proud member of the shoe club
    • View Profile
    • Code-Concept
Re: Networking and Code::Blocks
« Reply #5 on: February 17, 2013, 06:12:26 am »
You are not linking to sfml-network.
GitHub
Code Concept
Twitter
Rosme on IRC/Discord

MarcuzPwnz

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Re: Networking and Code::Blocks
« Reply #6 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?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
AW: Networking and Code::Blocks
« Reply #7 on: February 17, 2013, 08:27:36 am »
Infront of the sfml-system.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

MarcuzPwnz

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Re: Networking and Code::Blocks
« Reply #8 on: February 17, 2013, 08:22:40 pm »
Thanks :) and for future reference where would sfml-audio be placed?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
AW: Networking and Code::Blocks
« Reply #9 on: February 17, 2013, 08:43:53 pm »
Also infront of sfml-system.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

MarcuzPwnz

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Re: Networking and Code::Blocks
« Reply #10 on: February 17, 2013, 09:11:39 pm »
So the following would be correct? :)

sfml-graphics
sfml-window
sfml-network
sfml-audio
sfml-system

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
AW: Networking and Code::Blocks
« Reply #11 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything