🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.internet.socket
14 messages
14 total messages Started by mat Fri, 09 Feb 2007 02:09
socket issue
#1345
Author: mat
Date: Fri, 09 Feb 2007 02:09
32 lines
2078 bytes
hello,im using a socketconnection component to connect to a
datasnap server.i do socketconnection->connected=true; the code is in a
separate thread and i have some application->processmessages in order to get 
some visual
feedback (e.g. a messagebox before it starts connected and a messagebox if 
it connects).
the code is of course in a try catch .

the issue is the following:
when i try to connect to an existing pc it does what its supposed to do 
almost immediately,
if the datasnap server is up it connects ,if its not up (e.g. if im not 
running the scktsrv.exe)it throws an exception.

when i try to connect to an not existing pc (wrong ip) the system freezes 
and waits for a rather
big timeout.

if i try to connect to a firewalled pc (which blocks such incomming) it 
freezes again and waits for
a rather big timeout again.

is this something i can fix?the waiting timeout is very big,and the program 
freezes (although its in its own
thread).

i thought of first pinging the remote pc to see if its up and then try to 
connect to it but that would introduce
another waiting time(the ping waiting time)
what do people usually do to deal with this kind of problems?

thks 
Re: socket issue
#1346
Author: Bob Gonder
Date: Fri, 09 Feb 2007 17:48
13 lines
1357 bytes
mat wrote:

>hello,im using a socketconnection component to connect to a

I would point you to Remy's previous answer:

From: "Remy Lebeau \(TeamB\)" 
Newsgroups: borland.public.cppbuilder.internet.socket
Subject: Re: socketconnection-thread issue
Date: Wed, 10 Jan 2007 00:23:36 -0800
Message-ID: <45a4a254$1@newsgroups.borland.com>

Google it or click the Message-ID
Re: socket issue
#1347
Author: Remy Lebeau (TeamB)
Date: Fri, 09 Feb 2007 18:35
57 lines
2843 bytes
"mat" <mat@hotmail.com> wrote in message
news:45cbd7c8$1@newsgroups.borland.com...

> hello,im using a socketconnection component

Which component specifically?

> the code is in a separate thread and i have some
application->processmessages
> in order to get some visual feedback (e.g. a messagebox before
> it starts connected and a messagebox if it connects).

You should not be calling Application->ProcessMessages() in a worker
thread.  Only call it in the main thread.  Besides, you don't need it
anyway.  You can call the Win32 API MessageBox() directly in a worker
thread without processing any messages at all, as it has its own
message processing internally.

> if its not up (e.g. if im not running the scktsrv.exe)it throws an
exception.

As it should be.

> when i try to connect to an not existing pc (wrong ip) the system
> freezes and waits for a rather big timeout.

Again, as it should be.  If the IP cannot be reached immediately, it
can take a long time for the OS to figure out whether the IP is
actually valid or not.

> if i try to connect to a firewalled pc (which blocks such incomming)
> it freezes again and waits for a rather big timeout again.

See above.  If the firewall is blocking communications, then it is
likely also blocking the packets that the OS needs to determine
whether the machine is present or not at the IP.

> is this something i can fix?

The only thing you can do is implement your own timeout on the
connection manually.  You did not say whether the socket was
asynchronous or synchronous.  It makes a big difference in how to
implement such a timeout.

> the waiting timeout is very big

Such is the nature of sockets, especially on Windows.  Microsoft likes
to use large timeouts that cannot be changed.

> the program freezes (although its in its own thread).

The program cannot be freezing unless you are making your main thread
wait on the socket thread while it is waiting on the socket.


Gambit
Re: socket issue
#1348
Author: Remy Lebeau (TeamB)
Date: Fri, 09 Feb 2007 18:37
10 lines
1344 bytes
"Bob Gonder" <notbg@notmindspring.invalid> wrote in message
news:2ocps2hvm5nhgo61mg0mffnafc1e5uohcl@4ax.com...

> I would point you to Remy's previous answer:

http://groups.google.com/group/borland.public.cppbuilder.internet.socket/msg/e59802701e88334c


Gambit
Re: socket issue
#1349
Author: mat
Date: Sat, 10 Feb 2007 17:41
31 lines
1967 bytes
im using the tscoketconnection component from the datasnap tool categorie to 
connect to
a datasnap server(builder 2006).

> You should not be calling Application->ProcessMessages() in a worker
> thread.

but if i dont call this in the thread when i want to show something in a 
label in the main
thread(form) then it doesnt show up,eg:(all this in my separate thread):
MainForm->Label1->Caption="connecting...";
Application->ProcessMessages();
DataModule->SocketConnection1->Connected=true;

if i dont put the processmessages it doesnt show the label.

concerning the sychronous-asychronous mode,i dont know how to change this in 
the
component im using.

maybe im using the thread in a wrong way in the first place.i have created a 
thread to do
the connecting but this new thread accesses a component(socket 
connection)from
a datamodule.is this the reason that it forces the program to freeze?
eg:

Mythread::Connect()
{
DataModule->SocketConnection->Connected=true;
}
Re: socket issue
#1351
Author: Remy Lebeau (TeamB)
Date: Sun, 11 Feb 2007 21:36
41 lines
2272 bytes
"mat" <mat@hotmail.com> wrote in message
news:45ce03ae$1@newsgroups.borland.com...

> if i dont call this in the thread when i want to show something in
> a label in the main thread(form) then it doesnt show up

You are not supposed to be updating the controls of the main thread
from within the context of a worker thread to begin with.  For a
worker thread to safely access the UI, it should be using the
TThread::Synchronize() method for that.  This is clearly stated at the
top of every unit that the IDE generates when you choose the "File |
New | Thread" wizard.  For example:

    void __fastcall TWorkerThread::Execute()
    {
        //...
        Synchronize(UpdateUI);
        //...
    }

    void __fastcall TWorkerThread::UpdateUI()
    {
        MainForm->Label1->Caption = "connecting...";
        DataModule->SocketConnection1->Connected = true;
    }

> concerning the sychronous-asychronous mode,i dont know how
> to change this in the component im using.

You still haven't said which component you are actually using.  I
asked you that question in my last reply.

> i have created a thread to do the connecting but this new thread
> accesses a component(socket connection)from a datamodule.is
> this the reason that it forces the program to freeze?

No.


Gambit
Re: socket issue
#1353
Author: mat
Date: Mon, 12 Feb 2007 00:44
7 lines
1179 bytes
Thks about the answers,i said that im using
 the tscoketconnection component from the datasnap tool categorie

this tool categories has:
tdcomconnection
tsocketconnection
tsimpleobjectbroker etc.. 
Re: socket issue
#1354
Author: mat
Date: Mon, 12 Feb 2007 01:09
16 lines
1400 bytes
void __fastcall TAuthThread::Connect()
{
 AuthDataModule->SocketConnection1->Connected=true;
}

 void __fastcall TAuthThread::MyFUNCTION()
{
//do something
 Synchronize(Connect);
}

this produces error:could not find a match for
tthread:synchronize(void)

i guess i wrote it wrong,how must i fix this?
i checked this->connect() but creates the same error 
Re: socket issue
#1355
Author: Remy Lebeau (TeamB)
Date: Mon, 12 Feb 2007 02:50
17 lines
1456 bytes
"mat" <mat@hotmail.com> wrote in message
news:45cfbe36$1@newsgroups.borland.com...

> this produces error:could not find a match for
> tthread:synchronize(void)

I assume, then, that you are using BDS 2006?  Always say the version
you are using when asking for help.

You will have to prefix the method name with '&' when calling
Synchronize(), ie:

    Synchronize(&Connect);


Gambit
Re: socket issue
#1356
Author: mat
Date: Mon, 12 Feb 2007 04:02
6 lines
1384 bytes
i tryed that but again when i try to connect to a non existing ip the 
program freezes
concerning the aychronous-sychronous mode is there anything that i can do?
im using the tscoketconnection component from the datasnap tool categorie
borland 2006
 thks 
Re: socket issue
#1358
Author: Remy Lebeau (TeamB)
Date: Mon, 12 Feb 2007 04:40
17 lines
1629 bytes
"mat" <mat@hotmail.com> wrote in message
news:45cfe6b7@newsgroups.borland.com...

> i tryed that but again when i try to connect to a non existing
> ip the program freezes

This time I would expect it to, as you are now connecting in the
context of the main thread.  You weren't doing that before.

> concerning the aychronous-sychronous mode is there anything
> that i can do?

No.  TSocketConnection is a synchronous component.


Gambit
Re: socket issue
#1357
Author: mat
Date: Mon, 12 Feb 2007 04:51
25 lines
1881 bytes
so i guess nothing can be done?any suggestion?
:)

thks
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message 
news:45cfefd8$1@newsgroups.borland.com...
>
> "mat" <mat@hotmail.com> wrote in message
> news:45cfe6b7@newsgroups.borland.com...
>
>> i tryed that but again when i try to connect to a non existing
>> ip the program freezes
>
> This time I would expect it to, as you are now connecting in the
> context of the main thread.  You weren't doing that before.
>
>> concerning the aychronous-sychronous mode is there anything
>> that i can do?
>
> No.  TSocketConnection is a synchronous component.
>
>
> Gambit
>
> 
Re: socket issue
#1359
Author: mat
Date: Mon, 12 Feb 2007 06:03
56 lines
2948 bytes
if i try to ping the pc before connecting will it be a good idea?
i put an IdIcmpClient component i write simple:
AnsiString buffer;
unsigned short a;
IdIcmpClient1->Ping(buffer,a);
Application->ProcessMessages();

and in its onreply even i have
Memo1->Lines->Add(AnsiString(AReplyStatus.MsRoundTripTime) +" from 
"+AReplyStatus.FromIpAddress);
i noticed that if i try ping an ip that possible doesnt exist i get a 1000+ 
from 0.0.0.0
or if i write a url that doesnt exist i get an exception in the timeout that 
i have declared.
is this a good (i mean programming way good) way to understand if an ip 
exists before
making the socketconnection->connected=true?

thks


"mat" <mat@hotmail.com> wrote in message 
news:45cbd7c8$1@newsgroups.borland.com...
> hello,im using a socketconnection component to connect to a
> datasnap server.i do socketconnection->connected=true; the code is in a
> separate thread and i have some application->processmessages in order to 
> get some visual
> feedback (e.g. a messagebox before it starts connected and a messagebox if 
> it connects).
> the code is of course in a try catch .
>
> the issue is the following:
> when i try to connect to an existing pc it does what its supposed to do 
> almost immediately,
> if the datasnap server is up it connects ,if its not up (e.g. if im not 
> running the scktsrv.exe)it throws an exception.
>
> when i try to connect to an not existing pc (wrong ip) the system freezes 
> and waits for a rather
> big timeout.
>
> if i try to connect to a firewalled pc (which blocks such incomming) it 
> freezes again and waits for
> a rather big timeout again.
>
> is this something i can fix?the waiting timeout is very big,and the 
> program freezes (although its in its own
> thread).
>
> i thought of first pinging the remote pc to see if its up and then try to 
> connect to it but that would introduce
> another waiting time(the ping waiting time)
> what do people usually do to deal with this kind of problems?
>
> thks
> 
Re: socket issue
#1360
Author: Remy Lebeau (TeamB)
Date: Mon, 12 Feb 2007 08:56
23 lines
1690 bytes
"mat" <mat@hotmail.com> wrote in message
news:45d00321@newsgroups.borland.com...

> if i try to ping the pc before connecting will it be a good idea?

No.  Asside from the added overhead of the ping itself, that still
won't tell you whether the server can actually be connected to or not.

> in its onreply even i have
> Memo1->Lines->Add(AnsiString(AReplyStatus.MsRoundTripTime) +" from
> "+AReplyStatus.FromIpAddress);
> i noticed that if i try ping an ip that possible doesnt exist i get
a 1000+
> from 0.0.0.0

The correct thing to do is to first look at the
AReplyStatus.ReplyStatusType member, as that tells you whether the
ping was successful or not.  The rest of the members may or may not be
valid, depending on the type of reply received.


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