Socket for UDP?


I would like to receive UDP/IP ethernet packets.
I tried the following macro :

TServerSocket *ss = new TServerSocket(1025, kTRUE,1000,1000); // use port 1025
TSocket *s = ss->Accept(); // listen, and get a socket
Char_t buffer[80]; // buffer with some length to excercise
Int_t result;
result = s->RecvRaw(buffer,80);
cout << " (" << result << "): " << buffer << endl;

However, this code only reacts to TCP and does not react to UDP packets !
Is it possible to use UDP ? And how ?
A similar question was discussed in
and I could not find a positive answer.

I am using ROOT Version 4.00/03 on SuSE 9.0 Linux 2.4.21-215-athlon


currently we’ve no support for UDP sockets in ROOT via TSystem and TSocket. We will provide support in the near future.

Cheers, Fons.


thanks… I’ll eagerly await UDP support then.
I, really would like to use the convenience of
ROOT classes for this acquisition project.


Just use the standard C socket libraries for UDP communication:

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
#include <arpa/inet.h>

int s_source;
struct sockaddr_in local;
int len;
s_source = socket(AF_INET, SOCK_DGRAM, 0);
if (s_source < 0)
pexit(“stream socket”);
memset(&local, 0, sizeof(local));
local.sin_family = AF_INET;
local.sin_len = sizeof(local);
local.sin_port = htons(SOURCE_PORT);
local.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
if ( (len= sendto(s_source,data_buf_write,sizeof(data_buf_write),
0,(struct sockaddr *)&local,sizeof(local))) < 0 )
fprintf(stderr, “Error writting to socket.”);

-Jason Thomas.