BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TClientSocket usage

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage)
View previous topic :: View next topic  
Author Message
Shon
Guest





PostPosted: Thu Jan 29, 2004 11:01 am    Post subject: TClientSocket usage Reply with quote



Sorry for repeated question but I'm not sure if the previuos one has
been properly delivered.



Hi.

I would like my application to be able to make TCP/IP connection.

If I would have only one thread or if I knew at the design time how
many connections I have to make, then using TClientSocket would be as
simple as putting desired number of them on the form or data module.

But:
1. I dont know the thread number at the design time
2. each thread needs to make one TCPIP connection
3. the threads do not have message queue handling

What are my options then?

1. can I dynamically create TClientSocket objects at the runtime and
make them owned by one of the forms or data modules? If so, how do I
do that (I mean Owner handling - should I put the owner as the
constructor parameter or should I use InsertComponnent method of the
form?)
2. or maybe i should use simple API calls - but I'm used to use
TWinSocketStream Sad I don't like this soultion - I know how to do it
but I would like to use VCL componnents

How TClientSocket componnent fixes it's Handle property, which points
to the form receiving messages? Is it obtained after assigning Owner?

--

([-: May The Force Be With You! :-])
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Shon


Back to top
Hans Galema
Guest





PostPosted: Thu Jan 29, 2004 11:37 am    Post subject: Re: TClientSocket usage Reply with quote



Shon wrote:

Quote:
If I would have only one thread or if I knew at the design time how
many connections I have to make, then using TClientSocket would be as
simple as putting desired number of them on the form or data module.

What is a thread doing ? Is there a connection beteen a thread and a
TCliebtSocket ?

Quote:
1. I dont know the thread number at the design time

Who is spawning threads, at which moment ?

Quote:
2. each thread needs to make one TCPIP connection

Is that only to send send one command and receive once ?

Quote:
3. the threads do not have message queue handling

Are you using the TClientSocket's in blocking mode then ?

Quote:
What are my options then?

1. can I dynamically create TClientSocket objects at the runtime and
make them owned by one of the forms or data modules?

Yes, you can let them be owned by the application or by a form
or by nowbody. In the latter case you are responsible for freeing
resources when done.

Quote:
If so, how do I
do that (I mean Owner handling - should I put the owner as the
constructor parameter or should I use InsertComponnent method of the
form?)

TClientSocket *ClientSocket = new TClientSocket ( Application );
TClientSocket *ClientSocket = new TClientSocket ( Application->MainForm );
TClientSocket *ClientSocket = new TClientSocket ( this );
TClientSocket *ClientSocket = new TClientSocket ( NULL );

In the last one you have to do a

delete ClientSocket;

when done;

Quote:
How TClientSocket componnent fixes it's Handle property, which points
to the form receiving messages? Is it obtained after assigning Owner?

Fixes ? Please explain first about blocking/non blocking and about the
about of work a client should do.

Hans.

Back to top
Shon
Guest





PostPosted: Thu Jan 29, 2004 3:03 pm    Post subject: Re: TClientSocket usage Reply with quote




"Hans Galema" <dontusethis (AT) dontusethis (DOT) nl> wrote

Quote:
Shon wrote:

If I would have only one thread or if I knew at the design time
how
many connections I have to make, then using TClientSocket would
be as
simple as putting desired number of them on the form or data
module.

What is a thread doing ? Is there a connection beteen a thread and a
TCliebtSocket ?

Don't understand. How can thread be connected with a componnent?
I my case I would like to use the TClientSocket in a thread.

Quote:

1. I dont know the thread number at the design time

Who is spawning threads, at which moment ?

I spwan them at certain circumstances. Nevertheless - is this
important in my case?

Quote:

2. each thread needs to make one TCPIP connection

Is that only to send send one command and receive once ?

In particular - yes. The thread is processing, and in certain moment
it neads to send something to network and receive answer, possibly
repeat it several times (but this is not important i guess)

Quote:

3. the threads do not have message queue handling

Are you using the TClientSocket's in blocking mode then ?

I want to use them in blocking mode beacuse it is easier for me to
handle awayting (via TWinSocketStream::WaitForData) in several threads
than supply event handler for that, when there is a lot of
connections. I know, that this componnent needs to receive messages
for that (or maybe for non-blocking-mode?) so it uses ie a form to
receive messages for it - my thread is not able to dispatch Wwindows
messages

Quote:

What are my options then?

1. can I dynamically create TClientSocket objects at the runtime
and
make them owned by one of the forms or data modules?

Yes, you can let them be owned by the application or by a form
or by nowbody. In the latter case you are responsible for freeing
resources when done.

I know about freeing - the only concern is who will be receiving
messages for (hosting) the componnent

Quote:

If so, how do I
do that (I mean Owner handling - should I put the owner as the
constructor parameter or should I use InsertComponnent method of
the
form?)

TClientSocket *ClientSocket = new TClientSocket ( Application );
TClientSocket *ClientSocket = new TClientSocket (
Application->MainForm );
TClientSocket *ClientSocket = new TClientSocket ( this );
TClientSocket *ClientSocket = new TClientSocket ( NULL );

In the last one you have to do a

delete ClientSocket;

when done;


yes, yes

Quote:

How TClientSocket componnent fixes it's Handle property, which
points
to the form receiving messages? Is it obtained after assigning
Owner?

Fixes ? Please explain first about blocking/non blocking and about
the
about of work a client should do.

How and when TClientSocket or TClientWinSocket (which is used by it)
establishes, gets, acquires or qhatever, the Handle property value
which is the handle of the control which willk be receiving messages?

Quote:

Hans.


Back to top
Hans Galema
Guest





PostPosted: Thu Jan 29, 2004 7:34 pm    Post subject: Re: TClientSocket usage Reply with quote

Shon wrote:


Quote:
| What is a thread doing ? Is there a connection beteen a thread and a
| TCliebtSocket ?

Don't understand. How can thread be connected with a componnent?
I my case I would like to use the TClientSocket in a thread.

So the connection is that every thread has a TClientSocket or that every
TClientSocket is in its own thread. I just try to understand what
kind of application you are going to build.

Quote:
I spwan them at certain circumstances. Nevertheless - is this
important in my case?


Maybe. But if you won't tell than we will never know.


Quote:
| Is that only to send send one command and receive once ?

In particular - yes. The thread is processing, and in certain moment
it neads to send something to network and receive answer, possibly
repeat it several times (but this is not important i guess)


Of course it is important, otherwise you would not be asked.
What I like to know is if all what comes in is an answer
to a command that the client first send. If the initiative
is always at the client side you can make a different design then
when a server allowed to suddenly send something.

Quote:
| > 3. the threads do not have message queue handling


You will not need that if you choose for a blocking TClientSocket
where a server will only send if a client requests.

Quote:
| Are you using the TClientSocket's in blocking mode then ?

I want to use them in blocking mode beacuse it is easier for me to
handle awayting (via TWinSocketStream::WaitForData) in several threads
than supply event handler for that, when there is a lot of
connections. I know, that this componnent needs to receive messages
for that (or maybe for non-blocking-mode?)


Yes, non-blocking needs to be able to receive messages.

Quote:
so it uses ie a form to

receive messages for it - my thread is not able to dispatch Wwindows
messages


Then blocking, yes.

Quote:
I know about freeing - the only concern is who will be receiving
messages for (hosting) the componnent


Well that's why I asked how it all goes with commands and
results, and initiating transfers.

Quote:
How and when TClientSocket or TClientWinSocket (which is used by it)
establishes, gets, acquires or qhatever, the Handle property value
which is the handle of the control which willk be receiving messages?


It is unclear to me why you would need that.

Hans.

Back to top
Shon
Guest





PostPosted: Thu Jan 29, 2004 11:11 pm    Post subject: Re: TClientSocket usage Reply with quote

First, thank you for your concern very much. If I suppose that
something is less important even if you asked for that, thisi is only
to correct your path of thinking about my problem to the... right way.
Sory if it was rude but I know pretty well what I need to accomplish
and i try to express that in a understandable manner.

"Hans Galema" <dontusethis (AT) dontusethis (DOT) nl> wrote

Quote:
It is unclear to me why you would need that.

OK, so from the scratch:

Several threads run and process something. The thread at the certain
moment needs to make connection to server, send a message, receive an
answer, maybe send another message, so initiative is always on the
thread side.
I can handle waiting for answer and reading.

My concern is only the way/method of openning a TCPIP connection
inside the Execute method preferably by TClientSocket components
rather than by Windows API calls (which I encapsulated in some class)
because of ability tu use TWinSocketStream.

I just wanted to ask about creating/using TClientSocket inside the
code which doesn't handle Windows messages.

So:
1. I want to use one TClientSocket in a thread because there wil be
only one connection per thread
2. I want to use them along with TWinSocketStream
3. I don't want to put Windows messages dispatching code inside the
thread

I hope that is clear, Hans. I just wanted to know how to use
TClientSocket inside Execute methow of a regular TThread along with
TWinSocketStream...

--
([-: May The Force Be With You! :-])
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Shon, wew 400, GG: gg://1013999


Back to top
Hans Galema
Guest





PostPosted: Fri Jan 30, 2004 9:50 am    Post subject: Re: TClientSocket usage Reply with quote

Shon wrote:

Quote:
I just wanted to ask about creating/using TClientSocket inside the
code which doesn't handle Windows messages.

So:
1. I want to use one TClientSocket in a thread because there wil be
only one connection per thread
2. I want to use them along with TWinSocketStream
3. I don't want to put Windows messages dispatching code inside the
thread

Think that you can just create the TClientSocket at the beginning
of the thread. I never did put a TClientSocket in a thread, but
I don't see that much difficulties. Just the normal loop with
WaitForData and Stream Read. The only thing that would be tricky
is the Open() or Active = true for the ClientSocket.
Then you have to wait until the connection is established, after
wich you enter that loop.

Now you said that you had done most things before, so please
show a little code for the thread, tell as exactly as possible
where the difficulties are and we will be glad to have a look.

Hope you read also mike's thread:
"Some Conceptual Questions on Client Sockets". in the (socket) ng.

Hans.

Back to top
Shon
Guest





PostPosted: Fri Jan 30, 2004 11:47 am    Post subject: Re: TClientSocket usage Reply with quote


"Hans Galema" <dontusethis (AT) dontusethis (DOT) nl> wrote

Quote:
Shon wrote:

I just wanted to ask about creating/using TClientSocket inside
the
code which doesn't handle Windows messages.

So:
1. I want to use one TClientSocket in a thread because there wil
be
only one connection per thread
2. I want to use them along with TWinSocketStream
3. I don't want to put Windows messages dispatching code inside
the
thread

Think that you can just create the TClientSocket at the beginning
of the thread. I never did put a TClientSocket in a thread, but
I don't see that much difficulties. Just the normal loop with
WaitForData and Stream Read. The only thing that would be tricky
is the Open() or Active = true for the ClientSocket.
Then you have to wait until the connection is established, after
wich you enter that loop.

The algorithm and the creation moment is not a problem for me.
Maybe I now write my final question once more:
Do I need ANY form or ANY datamodule to use TClientObject in
blocking-mode? If so, shall I provide those as an Owner for the socket
object? How TClientSocket objects determines its Handle property value
when it needs it?

Quote:

Now you said that you had done most things before, so please
show a little code for the thread, tell as exactly as possible
where the difficulties are and we will be glad to have a look.

Of course, as soon as I implement it Smile Sorry, but the rest of the
code is... less interesting in the aspect of our discussion.

Quote:

Hope you read also mike's thread:
"Some Conceptual Questions on Client Sockets". in the (socket) ng.

Of course.

Quote:

Hans.

Thank youand sory for being so difficult in the conversation.


Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Fri Jan 30, 2004 6:28 pm    Post subject: Re: TClientSocket usage Reply with quote


"Shon" <Sebastian.Choromanski@%N%O%inteligo%S%P%A%M%.pl> wrote


Quote:
Do I need ANY form or ANY datamodule to use
TClientObject in blocking-mode?

No.

Quote:
If so, shall I provide those as an Owner for the socket object?

No. Simply specify NULL instead, and then make sure that you explitically
'delete' the TClientSocket when you are done with it.

Quote:
How TClientSocket objects determines its Handle
property value when it needs it?

There is no Handle used in blocking mode. Even in non-blocking mode, I
assume you are referring to the window Handle that socket events are posted
to? If so, then the client socket creates its own window internally, it
does not use the form's window at all.


Gambit



Back to top
Hans Galema
Guest





PostPosted: Fri Jan 30, 2004 8:09 pm    Post subject: Re: TClientSocket usage Reply with quote

Shon wrote:

Quote:
Do I need ANY form or ANY datamodule to use TClientObject in
blocking-mode? If so, shall I provide those as an Owner for the socket
object?

As I said before: No.

TClientSocket *ClientSocket = new TClientSocket ( NULL );

In the last one you have to do a

delete ClientSocket;

Quote:
How TClientSocket objects determines its Handle property value
when it needs it?

I would not know the case where they need to. I asked you already
code where you showed the need. Well if you don't show than it ends.

Quote:
Thank youand sory for being so difficult in the conversation.

Difficult nah. You were unclear. But then the one who
suffered was you, waiting so long for a final answer. Now you
know who to blame.

Hans.

Back to top
Shon
Guest





PostPosted: Sun Feb 01, 2004 3:06 pm    Post subject: Re: TClientSocket usage Reply with quote


"Hans Galema" <dontusethis (AT) dontusethis (DOT) nl> wrote

Quote:
Shon wrote:

Do I need ANY form or ANY datamodule to use TClientObject in
blocking-mode? If so, shall I provide those as an Owner for the
socket
object?

As I said before: No.

TClientSocket *ClientSocket = new TClientSocket ( NULL );

In the last one you have to do a

delete ClientSocket;

That is clear - I wondered about tha window handle socket API uses for
receiving messages. Remy said it wont need it even in non-blocking
mode - this is new for me and very... strange. The unix API is much
clearer than MS for me...

Quote:

How TClientSocket objects determines its Handle property value
when it needs it?

I would not know the case where they need to. I asked you already
code where you showed the need. Well if you don't show than it ends.

Thank youand sory for being so difficult in the conversation.

Difficult nah. You were unclear. But then the one who
suffered was you, waiting so long for a final answer. Now you
know who to blame.

Yes, I know. You are right but the code I write is... a bit
confidential. Nevertheless I will provide some code describing how the
problem was solved by me according to the hint You gave me (and Remy)
as soon as I implement it.

Quote:

Hans.


Back to top
Shon
Guest





PostPosted: Sun Feb 01, 2004 3:07 pm    Post subject: Re: TClientSocket usage Reply with quote


"Remy Lebeau (TeamB)" <gambit47.no.spam (AT) no (DOT) spam.yahoo.com> wrote in
message news:401aa0b9$1 (AT) newsgroups (DOT) borland.com...
Quote:

"Shon" <Sebastian.Choromanski@%N%O%inteligo%S%P%A%M%.pl> wrote in
message
news:401a446f$1 (AT) newsgroups (DOT) borland.com...

Do I need ANY form or ANY datamodule to use
TClientObject in blocking-mode?

No.

If so, shall I provide those as an Owner for the socket object?

No. Simply specify NULL instead, and then make sure that you
explitically
'delete' the TClientSocket when you are done with it.

How TClientSocket objects determines its Handle
property value when it needs it?

There is no Handle used in blocking mode. Even in non-blocking
mode, I
assume you are referring to the window Handle that socket events are
posted
to? If so, then the client socket creates its own window
internally, it
does not use the form's window at all.

Wow - that is the thing that was a mystery for me. Thanks very much -
I will spend some time to lear more about it...

Quote:


Gambit




Back to top
Hans Galema
Guest





PostPosted: Mon Feb 02, 2004 9:44 am    Post subject: Re: TClientSocket usage Reply with quote

Shon wrote:

Quote:
... but the code I write is... a bit
confidential. Nevertheless I will provide some code describing how the
problem was solved by me according to the hint You gave me (and Remy)
as soon as I implement it.

You don't need to do that if everything works fine for you.

What you could do instead, if you hang around in this ng more often,
to give a helping hand with your code if you realise that it would
solve the problem of a future poster.


Hans.

Back to top
Shon
Guest





PostPosted: Mon Feb 02, 2004 2:47 pm    Post subject: Re: TClientSocket usage Reply with quote

"Hans Galema" <dontusethis (AT) dontusethis (DOT) nl> wrote

Quote:
Shon wrote:

... but the code I write is... a bit
confidential. Nevertheless I will provide some code describing how
the
problem was solved by me according to the hint You gave me (and
Remy)
as soon as I implement it.

You don't need to do that if everything works fine for you.

What you could do instead, if you hang around in this ng more often,
to give a helping hand with your code if you realise that it would
solve the problem of a future poster.


I'll remeber that!

Quote:

Hans.


Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage) All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.