🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #3144

Re: i need ideas/comments with tclientsocket

#3144
From: Remy Lebeau (TeamB)
Date: Fri, 04 Nov 2005 19:46
73 lines
3053 bytes
"Alfred" <alf@no.spam.not.valid.email> wrote in message
news:436b445c$1@newsgroups.borland.com...

> I need to use both TMemoryStream and a simple int.
> I think I need a struct for it ?

Yes, you do.

> onconnect :
>    DataSocket *Data=new DataSocket;
>    Socket->Data = Data;

Don't forget to instantiate the TMemoryStream as well:

    DataSocket *Data = new DataSocket;
    Data->Proxy = 0;
    Data->MemoryStream = new TMemoryStream;
    Socket->Data = Data;

And then free everything in the OnDisconnect event:

    DataSocket *Data = (DataSocket*) Socket->Data;
    Socket->Data = NULL;
    delete Data->MemoryStream;
    delete Data;

I would suggest taking it a step further by adding a constructor and
destructor to the struct:

    struct DataSocket
    {
        int Proxy;
        TMemoryStream *MemoryStream;

        DataSocket()
        {
            Proxy = 0;
            MemoryStream = new TMemoryStream;
        }

        ~DataSocket()
        {
            delete MemoryStream;
        }
    };


    OnConnect:
        Socket->Data = new DataSocket;

    OnDisconnect:
        delete (DataSocket*) Socket->Data;
        Socket->Data = NULL;

> and to use it ?
>    Data->Proxy = 1;
>    Data->MemoryStream = ....
>
> It is correct ?

Yes.  In other events, you'll have to cast the Socket's Data property in
order to access the struct:

    DataSocket *Data = (DataSocket *) Socket->Data;
    Data->...

> ondisconnect only a Socket->Data=NULL or i have to free something ?

You have to free everything you allocated in the OnConnect event.


Gambit
Technical Details
Message-ID: <436bba6e$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!atl-c02.usenetserver.com!news.usenetserver.com!atl-c07.usenetserver.com!news.usenetserver.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <43662baf$1@newsgroups.borland.com> <43667112$1@newsgroups.borland.com> <4366ccd3$1@newsgroups.borland.com> <4366d53d$1@newsgroups.borland.com> <4366deb1$1@newsgroups.borland.com> <43670f39@newsgroups.borland.com> <4367f9ea$1@newsgroups.borland.com> <4369a04d$1@newsgroups.borland.com> <436a4574$1@newsgroups.borland.com> <436a50c9@newsgroups.borland.com> <436b445c$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,5c33b8c6a9ca7fdb
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.internet.socket
References: <43662baf$1@newsgroups.borland.com> <43667112$1@newsgroups.borland.com> <4366ccd3$1@newsgroups.borland.com> <4366d53d$1@newsgroups.borland.com> <4366deb1$1@newsgroups.borland.com> <43670f39@newsgroups.borland.com> <4367f9ea$1@newsgroups.borland.com> <4369a04d$1@newsgroups.borland.com> <436a4574$1@newsgroups.borland.com> <436a50c9@newsgroups.borland.com> <436b445c$1@newsgroups.borland.com>
Subject: Re: i need ideas/comments  with tclientsocket
Date: Fri, 4 Nov 2005 11:46:11 -0800
Lines: 75
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 68.69.17.41
Message-ID: <436bba6e$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1131133550 68.69.17.41 (4 Nov 2005 11:45:50 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!atl-c02.usenetserver.com!news.usenetserver.com!atl-c07.usenetserver.com!news.usenetserver.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail