🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.internet.socket
6 messages
6 total messages Started by mike Tue, 20 Jul 2004 19:47
Confusion on Blocking Sockets
#5598
Author: mike
Date: Tue, 20 Jul 2004 19:47
28 lines
1468 bytes
Hello, could someone assist me on this, I am confused as to how it should
work.

If I create a blocking socket thread and within the socket thread under
"public" I define a variable, how would I retreive the value of the variable
from outside the class. This would be a partial defintion of the code;

class PACKAGE TMyServerThread : public Scktcomp::TServerClientThread
{
public:
AnsiString      SomeVariable  ;

void __fastcall SomeFunction( void )  ;
.
.
.
......

}

Also on the same note how would I execute the above SomeFunction() from
outside the class declaration.

A sample code snippit of how to do this would sure help me out.

Thanks

Mike
Re: Confusion on Blocking Sockets
#5599
Author: Remy Lebeau (TeamB)
Date: Tue, 20 Jul 2004 21:12
26 lines
1793 bytes
"mike" <mfbrowne@earthlink.net> wrote in message
news:40fd7549$1@newsgroups.borland.com...

> If I create a blocking socket thread and within the socket thread
> under "public" I define a variable, how would I retreive the value
> of the variable from outside the class.

The same way you access public members for any class in general.  You create
an instance of the thread when needed, and then later on you use a pointer
to that thread to access the member, ie:

    TMyServerThread *thread = new TMyServerThread(Socket);
    //...
    // use thread->SomeVariable as needed....

If that does not help you, then you need to explain, in detail, exactly what
you are having a problem with.

> Also on the same note how would I execute the
> above SomeFunction() from outside the class declaration.

The same way as executing a method of any other class instance.


Gabit
Re: Confusion on Blocking Sockets
#5600
Author: mike
Date: Tue, 20 Jul 2004 21:46
59 lines
2578 bytes
Remy

Thank you for answering my post.

Here is how I am creating the Socket thread.

void __fastcall TForm1::ServerSocket2GetThread(TObject *Sender,
      TServerClientWinSocket *ClientSocket,
      TServerClientThread *&SocketThread)
{
     SocketThread = new TMyServerThread( false, ClientSocket )
;
}

And now if I go through the connections like the following I'm not sure how
to get the value of the variable;

 for( i=0;i<ServerSocket2->Socket->ActiveConnections;i++)
 {
thread->SomeVariable <<<<<-------------- This is the piece I don't
understand how to do
 }

Hope you can assist me

Mike

"Remy Lebeau (TeamB)" <gambit47.no.spam@no.spam.yahoo.com> wrote in message
news:40fd8a86$1@newsgroups.borland.com...
>
> "mike" <mfbrowne@earthlink.net> wrote in message
> news:40fd7549$1@newsgroups.borland.com...
>
> > If I create a blocking socket thread and within the socket thread
> > under "public" I define a variable, how would I retreive the value
> > of the variable from outside the class.
>
> The same way you access public members for any class in general.  You
create
> an instance of the thread when needed, and then later on you use a pointer
> to that thread to access the member, ie:
>
>     TMyServerThread *thread = new TMyServerThread(Socket);
>     //...
>     // use thread->SomeVariable as needed....
>
> If that does not help you, then you need to explain, in detail, exactly
what
> you are having a problem with.
>
> > Also on the same note how would I execute the
> > above SomeFunction() from outside the class declaration.
>
> The same way as executing a method of any other class instance.
>
>
> Gabit
>
>
Re: Confusion on Blocking Sockets
#5601
Author: Remy Lebeau (TeamB)
Date: Tue, 20 Jul 2004 23:57
23 lines
1616 bytes
"mike" <mfbrowne@earthlink.net> wrote in message
news:40fd9118$2@newsgroups.borland.com...

> And now if I go through the connections like the following
> I'm not sure how to get the value of the variable;

    for(i = 0; i < ServerSocket2->Socket->ActiveConnections; ++i)
    {
        TServerClientWinSocket *ClientSocket =
static_cast<TServerClientWinSocket*>(ServerSocket2->Socket->Connections[i]);

        TMyServerThread *Thread =
static_cast<TMyServerThread*>(ServerSocket2->Socket->GetClientThread(ClientS
ocket));
        if( Thread )
        {
            // use Thread->SomeVariable as needed...
        }
    }


Gambit
Re: Confusion on Blocking Sockets
#5602
Author: mike
Date: Wed, 21 Jul 2004 14:04
16 lines
1566 bytes
Remy,

Thank you very much. I tried this in another form and it did not work, but
your solution works perfect.

Can I ask you another question, what is the best way to have a solid
connected socket between the client and the server at all times. I am
working on an application that really needs to have the socket connection
available and connected at all times because information has to flow very
quickly between the server and the client.

It seems to me sockets can be hard to keep a constant connection.

Again thanks for the info, I really appreciate it very much.

Mike
Re: Confusion on Blocking Sockets
#5603
Author: Remy Lebeau (TeamB)
Date: Wed, 21 Jul 2004 16:33
13 lines
1466 bytes
"mike" <mfbrowne@earthlink.net> wrote in message
news:40fe7636$1@newsgroups.borland.com...

> It seems to me sockets can be hard to keep a constant connection.

That depends on the quality of your network connection and system load more
than the actual application coding.  If you have a solid network connection,
and the machine is reasonably responsive, then it is not hard at all to
maintain a solid socket connection.


Gambit
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads