| View previous topic :: View next topic |
| Author |
Message |
Shon Guest
|
Posted: Thu Jan 29, 2004 10:58 am Post subject: TClientSocket |
|
|
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 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 |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Thu Jan 29, 2004 7:27 pm Post subject: Re: TClientSocket |
|
|
"Shon" <Sebastian.Choromanski@%N%O%inteligo%S%P%A%M%.pl> wrote
| Quote: | What are my options then?
|
Create a new thread class that has a TClientSocket as a member that is
instantiated in the constructor and freed in the destructor. Then simply
set the ClientType property to ctNonBlocking and use a TWinSocketStream
inside the thread'sExecute() method to access the socket. Then you simply
spawn a new thread instance when needed and it will handle its particular
socket connection separately from other connections/threads.
Gambit
|
|
| Back to top |
|
 |
Shon Guest
|
Posted: Thu Jan 29, 2004 11:34 pm Post subject: Re: TClientSocket |
|
|
"Remy Lebeau (TeamB)" <gambit47.no.spam (AT) no (DOT) spam.yahoo.com> wrote in
message news:40195d0e (AT) newsgroups (DOT) borland.com...
| Quote: |
"Shon" <Sebastian.Choromanski@%N%O%inteligo%S%P%A%M%.pl> wrote in
message
news:4018e775$1 (AT) newsgroups (DOT) borland.com...
What are my options then?
Then simply set the ClientType property to ctNonBlocking and use a
TWinSocketStream
|
Now im confused - i use TWinsocketStream with TServerSocket in
stThreadBlocking mode or TClientSocket in ctBlocking mode while you
say that I should use ctNonBlocking instead.
Maybe you ment ctBlocking?
Nevertheless thank you for the answer - the idea of the class member
seams to be perfect for me! I will give it a try!
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Fri Jan 30, 2004 12:32 am Post subject: Re: TClientSocket |
|
|
"Shon" <Sebastian.Choromanski@%N%O%inteligo%S%P%A%M%.pl> wrote
| Quote: | Maybe you ment ctBlocking?
|
Yes, sorry about that.
Gambit
|
|
| Back to top |
|
 |
Shon Guest
|
Posted: Fri Jan 30, 2004 11:27 am Post subject: Re: TClientSocket |
|
|
"Remy Lebeau (TeamB)" <gambit47.no.spam (AT) no (DOT) spam.yahoo.com> wrote in
message news:40195d0e (AT) newsgroups (DOT) borland.com...
| Quote: |
"Shon" <Sebastian.Choromanski@%N%O%inteligo%S%P%A%M%.pl> wrote in
message
news:4018e775$1 (AT) newsgroups (DOT) borland.com...
What are my options then?
Create a new thread class that has a TClientSocket as a member that
is
instantiated in the constructor and freed in the destructor.
|
How exactly?
class MyThread : TThread
{
MyThread(void);
~MyThread(void);
....
TCleintSocket cs;
....
};
MyThread::MyThread(void)
: cs(some_form_pinter or Application)
{ }
MyThread::~MyThread(void)
{
??? cs;
}
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Fri Jan 30, 2004 6:30 pm Post subject: Re: TClientSocket |
|
|
"Shon" <Sebastian.Choromanski@%N%O%inteligo%S%P%A%M%.pl> wrote
class MyThread : public TThread
{
private:
TCleintSocket *cs;
public:
__fastcall MyThread(void);
__fastcall ~MyThread(void);
};
__fastcall MyThread::MyThread(void)
: TThread(true)
{
cs = new TClientSocket(NULL);
Resume();
}
__fastcall MyThread::~MyThread(void)
{
delete cs;
}
Gambit
|
|
| Back to top |
|
 |
Shon Guest
|
Posted: Sun Feb 01, 2004 2:59 pm Post subject: Re: TClientSocket |
|
|
"Remy Lebeau (TeamB)" <gambit47.no.spam (AT) no (DOT) spam.yahoo.com> wrote in
message news:401aa109$1 (AT) newsgroups (DOT) borland.com...
| Quote: |
"Shon" <Sebastian.Choromanski@%N%O%inteligo%S%P%A%M%.pl> wrote in
message
news:401a3fbc (AT) newsgroups (DOT) borland.com...
How exactly?
class MyThread : public TThread
{
private:
TCleintSocket *cs;
public:
__fastcall MyThread(void);
__fastcall ~MyThread(void);
};
__fastcall MyThread::MyThread(void)
: TThread(true)
{
cs = new TClientSocket(NULL);
Resume();
}
__fastcall MyThread::~MyThread(void)
{
delete cs;
}
|
OK, so TClientSocket wont need any form to receive messages when used
in blocking mode. I understand.
Thank you very much.
--
([-: May The Force Be With You! :-])
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Shon
|
|
| Back to top |
|
 |
|