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

Author Topic: Sending own object from client to server  (Read 3314 times)

0 Members and 1 Guest are viewing this topic.

samppaa

  • Newbie
  • *
  • Posts: 9
    • View Profile
Sending own object from client to server
« on: June 29, 2010, 01:48:27 am »
As I was reading the networking tutorial, here we send text to server

Code: [Select]
// Create the UDP socket
sf::SocketUDP Socket;

// Create bytes to send
char Buffer[] = "Hi guys !";

// Send data to "192.168.0.2" on port 4567
if (Socket.Send(Buffer, sizeof(Buffer), "192.168.0.2", 4567) != sf::Socket::Done)
{
    // Error...
}

So could I send object of my own to there like

// Create the UDP socket
sf::SocketUDP Socket;

// Create bytes to send
player * test;

// Send data to "192.168.0.2" on port 4567
if (Socket.Send(test, sizeof(Buffer), "192.168.0.2", 4567) != sf::Socket::Done)
{
    // Error...
}

So could I do like that?

Svenstaro

  • Full Member
  • ***
  • Posts: 222
    • View Profile
Sending own object from client to server
« Reply #1 on: June 29, 2010, 04:22:18 am »
You need to serialize an object to send it. You can use Laurent's other library for that: http://dev.tegesoft.com/projects/camp

Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
Sending own object from client to server
« Reply #2 on: June 29, 2010, 09:03:22 am »
Actually, your code is just sending a memory address to an other computer ;)

You might use Packet in order to do that, no need for CAMP lib.
Mindiell
----

samppaa

  • Newbie
  • *
  • Posts: 9
    • View Profile
Sending own object from client to server
« Reply #3 on: June 29, 2010, 12:13:49 pm »
Sorry meant to put player test; but anyways is there tutorial for making it a packet?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Sending own object from client to server
« Reply #4 on: June 29, 2010, 12:23:00 pm »
Quote
but anyways is there tutorial for making it a packet?

Yes... the tutorial about packets.
http://www.sfml-dev.org/tutorials/1.6/network-packets.php
Laurent Gomila - SFML developer