Page 1 of 1

Errata in article "Network Coms with BCB Part 2".

PostPosted: Sat Aug 26, 2006 8:25 am
by gtokas
The rule says "In every 10 lines of code there ARE at least one error".
The above proved true at almost any program.
So...
If any of you tried the updated server program you will notice that when a client disconnects server project reports a "Stack Overflow".
And that is because at the user class we use Socket->Close() at 2 sections:
1.
void __fastcall User::SocketEvent(
TObject *Sender,
TCustomWinSocket *Socket,
TSocketEvent Event)
{
//Code Here
if(Event == seDisconnect) {
Socket->Close();
Socket = NULL;
Handle = 0;
}
}
2.
void __fastcall User::ErrorEvent(
TObject *Sender,
TCustomWinSocket *Socket,
TErrorEvent Error, int &ErrorCode)
{
ErrorCode = 0;
Socket->Close();
Socket = NULL;
Handle = 0;
}

So every time we call Socket->Close() the seDisconnect event triggered and we are in a never ending loop results to the Stack Overflow...
Just comment those 2 lines and everything will work fine again.

George Tokas.

P.S. I would like a bit of feedback about this.

Network Comms

PostPosted: Thu Mar 22, 2007 9:23 am
by tonus
George,

I've copied your net comms program and meet problems in the server part:
1. The compiler complains about:
class TForm1 : public TForm
{
__published: // IDE-managed Components
TServerSocket *Server;

Form1->Server does not have a corresponding component. Remove the declaration.

2. If I ignore that message and run this program it crashes, me doing nothing, exception class EAccessViolation. The CPU-window is at:
Scktcomp::TAbstractSocket::SetActive:

I'm using BCB5Prof, and really don't have a clue, a working sample would be so welcome ...

Regards,
Anton.

P.S.
Your footer looks to me as a decimal to hex conversion.
That may explain my age....

PostPosted: Thu Mar 22, 2007 9:44 am
by gtokas
Hi there,
Open the form of the server part.
Delete the server socket, if exists, drop a new TServerSocket and rename it to "Server" for compliance with the code.
That errors are very often when copying code to a new project.
Inform me about the result.

George Tokas.

PostPosted: Thu Mar 22, 2007 9:49 am
by gtokas
>>Your footer looks to me as a decimal to hex conversion.
Zilog Z80 code dated from 1982.
Incrementing a decimal value till reach 80.
Z80 has a very handy decimal adjust command (DAA).

Compiler satisfied.

PostPosted: Fri Mar 23, 2007 2:45 am
by tonus
George, thanks for your prompt reply!
You pointed exactly to the problem: the naming of component.

Regards,
Anton.

P.S.
Mixed up your footer with this piece of code that prints nibbles (half bytes) as hex characters: (the only use I had for DAA in those days ...)
Nibble
push af
daa
add a,F0h
adc a,40h

PRINT_CHAR ; prints ASCII character in A

pop af

It WORKS!

PostPosted: Fri Mar 23, 2007 8:13 am
by tonus
Something that gives no clues is: that if you type in the code directly you NEED TO click on the corresponding events in the object inspector once. So they get 'attached' to their objects.
I compiled the server without this and it just sat there, just doing nothing.
As it should be ....

And slowly, step by step, I'm getting understanding of what is happening.
My thanks to George Tokas.


Anton.