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

Author Topic: Sending Over Sockets  (Read 2294 times)

0 Members and 1 Guest are viewing this topic.

Walta69

  • Newbie
  • *
  • Posts: 30
    • View Profile
Sending Over Sockets
« on: April 29, 2014, 07:23:41 pm »
I know this may seem like a very stupid and beginner question but here goes nothing  :P :

The sf::TcpSocket has the send() method. This method takes as arguments the message as a
string.

My problem is how do i send an integer across? or some other data type?

Any help would be appreciated :)

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Sending Over Sockets
« Reply #1 on: April 29, 2014, 07:44:31 pm »
SFML / OS X developer

Walta69

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Sending Over Sockets
« Reply #2 on: April 29, 2014, 07:52:15 pm »
Nice :D thanks :D

But then on the other end, how would I then convert a number (say 100) back to integer?

I have spent countless hours tying to find a nice way :/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Sending Over Sockets
« Reply #3 on: April 29, 2014, 07:53:57 pm »
Binary data is often prefered to text data (because it requires no conversion, and uses less bytes).

Have a look at the tutorial, there are examples for exactly what you're looking for (hint: sf::Packet).
Laurent Gomila - SFML developer

Walta69

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Sending Over Sockets
« Reply #4 on: April 29, 2014, 07:58:24 pm »
Alright ill have a look at the tutorial on packets :)

Walta69

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Sending Over Sockets
« Reply #5 on: April 29, 2014, 08:08:45 pm »
Packets make it soo nice :D thanks alot man!

 

anything