Sending a custom object through TSockets

dear all,
I have a problem trying to send an object through TSockets… and I do not understand what’s wrong in my code… I hope someone can help me.

what I do is like this (interactively) :

TServerSocket server(10001);
TSocket client(“localhost”, 10001);
TSocket *socket = server->Accept();
TRObject robj(“ROBY”);
client->SendObject(&robj);

and here I got a segmentation violation

root [6] client.SendObject(&robj)

*** Break *** segmentation violation
(no debugging symbols found)
Using host libthread_db library “/lib/tls/libthread_db.so.1”.
Attaching to program: /proc/14086/exe, process 14086
(no debugging symbols found)…done.
(no debugging symbols found)…done.
(no debugging symbols found)…done.
[Thread debugging using libthread_db enabled]
[New Thread -1208219968 (LWP 14086)]
(no debugging symbols found)…done.
(no debugging symbols found)…done.
(no debugging symbols found)…done.
(no debugging symbols found)…done.
(no debugging symbols found)…done.
(no debugging symbols found)…done.
(no debugging symbols found)…done.
(no debugging symbols found)…done.
(no debugging symbols found)…done.
(no debugging symbols found)…done.
(no debugging symbols found)…done.
(no debugging symbols found)…done.
(no debugging symbols found)…done.
(no debugging symbols found)…done.
(no debugging symbols found)…done.

0x00b477a2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2
#1 0x0092e5fe in do_system () from /lib/tls/libc.so.6
#2 0x008148bd in system () from /lib/tls/libpthread.so.0
#3 0x002c11ff in TUnixSystem::Exec ()
from /home/preghenella/SOFT/root/lib/libCore.so
#4 0x002c6991 in TUnixSystem::StackTrace ()
from /home/preghenella/SOFT/root/lib/libCore.so
#5 0x002c35f1 in TUnixSystem::DispatchSignals ()
from /home/preghenella/SOFT/root/lib/libCore.so
#6 0x002c36f8 in SigHandler () from /home/preghenella/SOFT/root/lib/libCore.so
#7 0x002c28d1 in sighandler () from /home/preghenella/SOFT/root/lib/libCore.so
#8
#9 0x01d83d63 in vtable for TAxis ()
from /home/preghenella/SOFT/root/lib/libHist.so
#10 0x01d24165 in TInstrumentedIsAProxy::operator() ()
from /home/preghenella/SOFT/root/lib/libHist.so
#11 0x0029ef40 in TClass::GetActualClass ()
from /home/preghenella/SOFT/root/lib/libCore.so
#12 0x00a50a5d in TBufferFile::WriteObjectAny ()
from /home/preghenella/SOFT/root/lib/libRIO.so
#13 0x00a5020c in TBufferFile::WriteFastArray ()
from /home/preghenella/SOFT/root/lib/libRIO.so
#14 0x00ac021b in TStreamerInfo::WriteBufferAux<char**> ()
from /home/preghenella/SOFT/root/lib/libRIO.so
#15 0x00a52609 in TBufferFile::WriteClassBuffer ()
from /home/preghenella/SOFT/root/lib/libRIO.so
#16 0x0083afc4 in RObject::Streamer ()
from /home/preghenella/TEST/./libRObject.so
#17 0x002a21e0 in TClass::Streamer ()
from /home/preghenella/SOFT/root/lib/libCore.so
#18 0x002a21b9 in TClass::Streamer ()
from /home/preghenella/SOFT/root/lib/libCore.so
#19 0x00a5095c in TBufferFile::WriteObject ()
from /home/preghenella/SOFT/root/lib/libRIO.so
#20 0x00a50a8a in TBufferFile::WriteObjectAny ()
from /home/preghenella/SOFT/root/lib/libRIO.so
#21 0x00a5086d in TBufferFile::WriteObject ()
from /home/preghenella/SOFT/root/lib/libRIO.so
#22 0x031c3349 in TSocket::SendObject ()
from /home/preghenella/SOFT/root/lib/libNet.so
#23 0x031e6ae3 in G__G__Net_123_0_41 ()
from /home/preghenella/SOFT/root/lib/libNet.so
#24 0x00b9b4b7 in Cint::G__ExceptionWrapper ()
from /home/preghenella/SOFT/root/lib/libCint.so
#25 0x00c4fff1 in G__call_cppfunc ()
from /home/preghenella/SOFT/root/lib/libCint.so
#26 0x00c3723e in G__interpret_func ()
from /home/preghenella/SOFT/root/lib/libCint.so
#27 0x00c262e6 in G__getfunction ()
from /home/preghenella/SOFT/root/lib/libCint.so
#28 0x00cd32e9 in G__getstructmem ()
from /home/preghenella/SOFT/root/lib/libCint.so
#29 0x00ccbe14 in G__getvariable ()
from /home/preghenella/SOFT/root/lib/libCint.so
#30 0x00c0c132 in G__getitem () from /home/preghenella/SOFT/root/lib/libCint.so
#31 0x00c0ee47 in G__getexpr () from /home/preghenella/SOFT/root/lib/libCint.so
#32 0x00c71b7b in G__exec_function ()
from /home/preghenella/SOFT/root/lib/libCint.so
#33 0x00c772c5 in G__exec_statement ()
from /home/preghenella/SOFT/root/lib/libCint.so
#34 0x00bf97b0 in G__exec_tempfile_core ()
from /home/preghenella/SOFT/root/lib/libCint.so
#35 0x00bf99f4 in G__exec_tempfile_fp ()
from /home/preghenella/SOFT/root/lib/libCint.so
#36 0x00c7ec78 in G__process_cmd ()
from /home/preghenella/SOFT/root/lib/libCint.so
#37 0x00296140 in TCint::ProcessLine ()
from /home/preghenella/SOFT/root/lib/libCore.so
#38 0x0020f0f6 in TApplication::ProcessLine ()
from /home/preghenella/SOFT/root/lib/libCore.so
#39 0x008def71 in TRint::HandleTermInput ()
from /home/preghenella/SOFT/root/lib/libRint.so
#40 0x008dd6f8 in TTermInputHandler::Notify ()
from /home/preghenella/SOFT/root/lib/libRint.so
#41 0x008df79a in TTermInputHandler::ReadNotify ()
from /home/preghenella/SOFT/root/lib/libRint.so
#42 0x002bfb8a in TUnixSystem::CheckDescriptors ()
from /home/preghenella/SOFT/root/lib/libCore.so
#43 0x002c3b48 in TUnixSystem::DispatchOneEvent ()
from /home/preghenella/SOFT/root/lib/libCore.so
#44 0x002601bc in TSystem::InnerLoop ()
from /home/preghenella/SOFT/root/lib/libCore.so
#45 0x0026015b in TSystem::Run ()
from /home/preghenella/SOFT/root/lib/libCore.so
#46 0x0020f1e2 in TApplication::Run ()
from /home/preghenella/SOFT/root/lib/libCore.so
#47 0x008dde86 in TRint::Run () from /home/preghenella/SOFT/root/lib/libRint.so
#48 0x08048d36 in main ()

here is the object code:

[RObject.h]

#include “TObject.h”
#include “TH1I.h”

class RObject :
public TObject
{
public:
RObject();
RObject(Char_t *Name);
RObject(RObject &source);
RObject &operator =(RObject &source);
~RObject();
private:
Char_t *fName;
TH1I **fObject;

ClassDef(RObject, 1);
};

[RObject.cxx]

#include “RObject.h”

ClassImp(RObject);

RObject::RObject() :
TObject(),
fName(new Char_t [128]),
fObject(new TH1I *[10])
{
printf(“default constructor\n”);
strcpy(fName, “R+”);
}

RObject::RObject(Char_t *Name) :
TObject(),
fName(new Char_t [128]),
fObject(new TH1I *[10])
{
printf(“constructor\n”);
strcpy(fName, Name);
Char_t n[128];
for (Int_t i = 0; i < 10; i++){
sprintf(n, “h%d”, i);
fObject[i] = new TH1I(n, n, 10, 0, 10);
}
}

RObject::RObject(RObject &source) :
TObject(source),
fName(new Char_t [128]),
fObject(new TH1I *[10])
{
printf(“copy constructor\n”);
strcpy(fName, source.fName);
for (Int_t i = 0; i < 10; i++)
fObject[i] = new TH1I(*source.fObject[i]);
}

RObject &
RObject::operator =(RObject &source)
{
printf(“operator assignment\n”);
TObject::operator =(source);
strcpy(fName, source.fName);
for (Int_t i = 0; i < 10; i++)
*fObject[i] = *source.fObject[i];
}

RObject::~RObject()
{
delete [] fObject;
delete [] fName;
}

thanks
roberto

Hi,

Your classes is not described enough for the I/O to work properly. In particular with TH1I **fObject; , the I/O has no clue what is the size of the underlying array (or even whether it is meant to be an array).

I strongly recommend that you use a container (TList, TObjArray, std::vector<TH1I*>, etc) instead of a C style array.

Cheers,
Philippe.

PS. You code might work if you use: TH1I **fObject; //[10] where the I/O is now being told you mean an array of 10.