Welcome,
Guest
. Please
login
or
register
. Did you miss your
activation email?
French forum
Home
Help
Search
Login
Register
SFML community forums
»
Help
»
Network
»
Sending Over Sockets
Print
Pages: [
1
]
Author
Topic: Sending Over Sockets (Read 2295 times)
0 Members and 1 Guest are viewing this topic.
Walta69
Newbie
Posts: 30
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
:
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
Logged
Hiura
SFML Team
Hero Member
Posts: 4321
Re: Sending Over Sockets
«
Reply #1 on:
April 29, 2014, 07:44:31 pm »
You will love std::to_string (C++11):
http://en.cppreference.com/w/cpp/string/basic_string/to_string
Logged
SFML / OS X developer
Walta69
Newbie
Posts: 30
Re: Sending Over Sockets
«
Reply #2 on:
April 29, 2014, 07:52:15 pm »
Nice
thanks
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 :/
Logged
Laurent
Administrator
Hero Member
Posts: 32498
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).
Logged
Laurent Gomila - SFML developer
Walta69
Newbie
Posts: 30
Re: Sending Over Sockets
«
Reply #4 on:
April 29, 2014, 07:58:24 pm »
Alright ill have a look at the tutorial on packets
Logged
Walta69
Newbie
Posts: 30
Re: Sending Over Sockets
«
Reply #5 on:
April 29, 2014, 08:08:45 pm »
Packets make it soo nice
thanks alot man!
Logged
Print
Pages: [
1
]
SFML community forums
»
Help
»
Network
»
Sending Over Sockets