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

Author Topic: SFML 2.0 Help?  (Read 2383 times)

0 Members and 1 Guest are viewing this topic.

Christopher Jozwiak

  • Newbie
  • *
  • Posts: 48
    • View Profile
    • Blog
    • Email
SFML 2.0 Help?
« on: November 15, 2012, 05:41:12 am »
Sorry noob here.  Heard 1.6 had bugs and kinda turned me away from downgrading to it just to learn the ropes.  But i tried using the network example in the docs.  Copied the server code into a new project. Here is the code: 

 // Create a listener to wait for incoming connections on port 55001
#include <SFML\Network.hpp>
#include <SFML\Graphics.hpp>
#include <SFML\System.hpp>
#include <iostream>

using namespace std;

sf::UdpSocket listener;
 listener.listen(55001);

 // Wait for a connection
 sf::UdpSocket socket;
 listener.accept(socket);
 cout << "New client connected: " << socket.getRemoteAddress() << std::endl;

 // Receive a message from the client
 char buffer[1024];
 std::size_t received = 0;
 socket.receive(buffer, sizeof(buffer), received);
 std::cout << "The client said: " << buffer << std::endl;

 // Send an answer
 std::string message = "Welcome, client";
 socket.send(message.c_str(), message.size() + 1);
 

I'm getting a whole bunch of weird errors... errors with cout even though I have iostream included.  Confused help anyone?

EDIT:: Both socket.recieve and socket.send give me an error of this specifier has no storage class or type specifier  listener. listen same thing.  cout same thing and it the "<<" giver error expected a declaration.  This is the only file in the project. main.cpp.
« Last Edit: November 15, 2012, 06:22:27 pm by Sianide »
Noob C++ Programmer.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SFML 2.0 Help?
« Reply #1 on: November 15, 2012, 07:57:11 am »
Quote
I'm getting a whole bunch of weird errors...
Show them...

And is your code really outside any function? If not, please provide the real code.
Laurent Gomila - SFML developer

Christopher Jozwiak

  • Newbie
  • *
  • Posts: 48
    • View Profile
    • Blog
    • Email
Re: SFML 2.0 Help?
« Reply #2 on: November 15, 2012, 05:57:01 pm »
Edited topic.
Noob C++ Programmer.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SFML 2.0 Help?
« Reply #3 on: November 15, 2012, 07:08:41 pm »
Your code must be inside function(s).
Laurent Gomila - SFML developer

Christopher Jozwiak

  • Newbie
  • *
  • Posts: 48
    • View Profile
    • Blog
    • Email
Re: SFML 2.0 Help?
« Reply #4 on: November 15, 2012, 07:34:44 pm »
 :-[ Woops.... cant believe i missed that!!! Wow i should prob just quit now.  I have programmed before I just completely missed that o_o.......
Noob C++ Programmer.

 

anything