Raydium 3D Game Engine

Official forum for everything about Raydium, ManiaDrive, MeMak, ...
It is currently Thu Mar 28, 2024 6:11 pm

All times are UTC




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: client and server doubt
PostPosted: Wed May 20, 2009 10:01 am 
Offline
User avatar

Joined: Thu Sep 29, 2005 2:59 pm
Posts: 828
My client send a text in this way:



Code:
void send_test(void)
{
   char cadena[RAYDIUM_NETWORK_PACKET_SIZE];
   strcpy(cadena,"prueba de conexion");
   raydium_network_write(NULL,raydium_network_uid,254,cadena);
}

And the server receive the data like this:

Code:
void loop(void)
{
signed char type;
int id;

if(raydium_network_read(&id, &type, str)==RAYDIUM_NETWORK_DATA_OK)
    {
    raydium_network_broadcast(type,str);
   raydium_log("datos: %d, %d, %s",id,type,str);
    }
raydium_timecall_callback();
raydium_web_callback();
}

But it's not working as I expected... This is the full output of the server :
Code:
Raydium: timecall: method accuracy = 0.001 ms (999999.94 Hz)
Raydium: timecall: Using basic gettimeofday() method
Raydium: timecall: OK (999999 Hz)
Raydium: timecall: softcall 0: 1 Hz (1000000 clocks interval)
Raydium: PHP R3S Scripts: rayphp
Raydium: PHP support: OK
Raydium: network: OK
Raydium: network: server socket created
Raydium: network: linux broadcast interface(s): eth0
Raydium: network: server OK: waiting for clients (8 max) at udp port 29104
Raydium: webserver: OK
Raydium: web: starting Raydium HTTP server on port 29104
Raydium: network: now broadcasting : 'ManiaDrive Server. Use --title to change :)' (ManiaDrive) version 10
Raydium: timecall: softcall 1: 1 Hz (1000000 clocks interval)
Raydium: network: client 0 connected as vicente
Raydium: datos: 0, -2, t
Raydium: datos: 0, -2, t
Raydium: datos: 0, -2, t
Raydium: timecall: warning: time modulo detected: workarounding
Raydium: datos: 0, -2, t
Raydium: network: TIMEOUT for client 0 (10 sec): vicente deleted !
Terminated


What I'm doing wrong? Concept problem?


Top
 Profile  
 
PostPosted: Wed May 20, 2009 3:14 pm 
Offline

Joined: Sun Oct 09, 2005 10:46 pm
Posts: 759
Hello,

Difficult to see something with just this par of code.

What are you trying to do ?

Look at tests.c it seem to be quite simple for server problem.

Else try to discribe more precisely your app please.

have a nice day.

Ouille.


Top
 Profile  
 
PostPosted: Wed May 20, 2009 8:37 pm 
Offline
User avatar

Joined: Thu Sep 29, 2005 2:59 pm
Posts: 828
I'm creating a client-server system. But in this exact case I just want to send, from the client, an string to the server. The server has to print it in its output.


Top
 Profile  
 
PostPosted: Wed May 20, 2009 11:55 pm 
Offline
User avatar

Joined: Sun Mar 16, 2003 2:53 am
Posts: 2591
Location: gnniiiii (Scrat)
When reading/writing packets with Raydium network, you must shift your load/data to API RAYDIUM_NETWORK_PACKET_OFFSET on the packet. The beginning of the packet is used for headers (and using this offset system, the user can read/write headers if needed)
Have a look to mania_drive.c, you'll see a few usages of all this.

Code:
strcpy(cadena+RAYDIUM_NETWORK_PACKET_OFFSET,"prueba de conexion");
// same will apply when reading the packet ...

A small warning : "type" is a signed char. You should preferably use RAYDIUM_NETWORK_PACKET_BASE+xxx.

Other point: why not using "netcalls" ? You can then make things a bit easier , and it's way more reliable (timeouts, ACK, resending, ...)


Top
 Profile  
 
PostPosted: Thu May 21, 2009 9:27 am 
Offline
User avatar

Joined: Thu Sep 29, 2005 2:59 pm
Posts: 828
Thanks, I go to try in that way and after that I'll try with netcalls.
Currently I'm just doing test, not too much experience with net code. :oops:


Top
 Profile  
 
PostPosted: Fri May 22, 2009 7:50 am 
Offline
User avatar

Joined: Thu Sep 29, 2005 2:59 pm
Posts: 828
Men.... we need to add quite more doc about net code. I'm doing this with trial and error method... but not a good way really. :(

updated: Ok, finally I got it working... but it was completely trial+error.


Top
 Profile  
 
PostPosted: Tue May 26, 2009 7:59 am 
Offline
User avatar

Joined: Thu Sep 29, 2005 2:59 pm
Posts: 828
Well, Officially I'm not able to manage raydium network code. I need help with:
-Creating a game-only (not web) server. (I guess tests.c could works but I would need comments in most lines)
-Send and receiving random lenght data from client-server and server-client.
-When to use propags? and netcalls? and broadcast? and sockets?...
-Why bother with packet_base offset and such things...? And how are they used? Are there incompatibilities?
-I'm looking at grapple(http://opensource.linuxgamepublishing.com/grapple/). It's an LGPL network library done by LinuxGamePublishing for networking game. In this document
http://opensource.linuxgamepublishing.c ... ple/README you can search for "SIMPLEST USAGE" chapter.
Quote:
A client process may run the following command

Code:
grapple_client_intvar_set(client1,"test_variable",17);


for example.

All connected clients, and the server, will then receive the number 17 by doing

Code:
grapple_client_intvar_get(client2,"test_variable");


There you can see EXACTLY what I want to get from raydium... but I can't. Is there a way?


Top
 Profile  
 
PostPosted: Wed Jun 03, 2009 9:08 pm 
Offline
User avatar

Joined: Sun Mar 16, 2003 2:53 am
Posts: 2591
Location: gnniiiii (Scrat)
We should create proper demo(s) for all this, and some tutorials, ... As a lot of other things :)

To make it simple, here's a short explanation about Raydium network API:

- You want to send an event ? Use a netcall. Basically, it's a simple RPC (remote procedure call), allowing you to call, from a client, a function on the server. This function can pass a buffer of data, with whatever-you-want-until-it's-too-big in it. You can then use the server to broadcast this packet over all clients, if you want, or send it to a particular client.

- You want to have a "state" synchronized over all clients ? Use propags. It allows you to have some local data, and to make sure that every client on the network have the same. Each time a client is modifying this data, he must call raydium_network_propag_refresh() to update this data on all other clients.

If you look carefully at tests.c, it's a very simple program. Here's how it works:

A function, broad(), is defined to send a packet to all other clients. In facts, this function does nothing else than calling raydium_network_broadcast(). It has even the same signature ...

Then, tests creates it's main loop, where the only thing it did is reading the network. Every packet received is given to broad() ... so every client receive it (including the sender itself, note it). In almost every cases, the ONLY data here is ODENet data : element positions, creation, ... Nothing else: Raydium deals with netcalls and propags internally.

Speaking of which ... you can see netcalls registering in the main() of tests. Again, the idea is simple: if the server receive a netcall from a client ... it does nothing else that spreading it to all clients. And that's it.

So, to create a very basic "chat" with Raydium, here's a guideline: (it's not some real code, but close)

On the clients:
Code:
// 10, or 11, or 30 ... anything you want over 0 and under 127
#define NETCALL_CHAT (RAYDIUM_NETWORK_PACKET_BASE+10)

// we'll call this when we want to send some text to other clients ...
void chat_send(char *txt)
{
char buff[RAYDIUM_NETWORK_PACKET_SIZE];

// let's create the packet ... we only have offset our data so
// the header can be created by network_write() ...
strcpy(buff+RAYDIUM_NETWORK_PACKET_OFFSET],txt); // strNcpy is needed here ! Don't mess with network ...
raydium_network_write(NULL,raydium_network_uid,NETCALL_CHAT,buff);
}

// we do want we want with received text ...
void chat_get(char *txt)
{
printf("message: %s\n");
}

// will be called "by the network"
void netcall_chat_get(int type, char *buff)
{
// just get rid of the packet header:
chat_get(buff+RAYDIUM_NETWORK_PACKET_OFFSET);
}

int main(...)
{
...
// let's register our "network function" (netcall)
raydium_network_netcall_add(netcall_chat_get,NETCALL_CHAT,1);

// connect to the server ...
if(!raydium_network_client_connect_to("foobar.org"))
// ...
}


... that's it. The server will look like:

Code:
#define RAYDIUM_NETWORK_ONLY
#include "raydium/index.c"

// an C header could be better ... :)
#define NETCALL_CHAT (RAYDIUM_NETWORK_PACKET_BASE+10)

char str[RAYDIUM_NETWORK_PACKET_SIZE];

void loop(void)
{
signed char type;
int id;

if(raydium_network_read_flushed(&id, &type, str)==RAYDIUM_NETWORK_DATA_OK)
    {
    // will never be called until using ODENet ...
    raydium_network_broadcast(type,str);
    }
}

int main(int argc, char **argv)
{
raydium_network_only_init(argc,argv);

raydium_network_netcall_add(raydium_network_broadcast,NETCALL_CHAT,1);
do{
loop();
// a small delay (like usleep(1) for Linux) is needed here,
// or you'll overburn CPU and make network stack turn crazy
}while(1);
}



I write this "from" head, so I didn't check anything, but you've a quite complete view of this API here. Let me know what's not crystal clear here :)

Warning: if the client only do "chatting", you'll quickly end up with timeouts (see RAYDIUM_NETWORK_TIMEOUT)


Top
 Profile  
 
PostPosted: Thu Jun 04, 2009 10:03 pm 
Offline
User avatar

Joined: Thu Sep 29, 2005 2:59 pm
Posts: 828
Thanks a lot. This will be quite usefull ;)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 25 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group