Solved

IdTCPServer and IBO

Posted on 2007-11-28
3
1,103 Views
Last Modified: 2009-07-29
Hi,

I am using: delphi7/IBO/IdTCPServer (indy 10.2.3)

I need do some think like this:

1- Receive a command with the username and a message from client and insert into a table in firebird
2- Continuously server read this table with TTimer and send new messages to specific client

For example:

1- Client User1 send a message to user2 -> "user2:Hi, thanks"
2- The server insert in a table the username (user2) and the message (Hi, thanks)
3- Server read the table with TTimer and send the messages to specific client (user2 in this case)
4- Client user2 receives the message: "Hi, thanks"

I dont know do this with thread-safe

I have to use this way, because i have another program that will save in this table too

Please guys help me

Alexandre
Brazil


0
Comment
Question by:alpires
  • 2
3 Comments
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 20370439
First off, firebird I beleive has "triggers" that can fire "events"
so a better method would be to have an "Insert" trigger on your table that would alert your "server" and it could send the new data out to client2

Other than that. the indy code is relatively simple

you'd be doing something like

WriteLn('RECORD');
WriteLn(FormatDateTime('dd"-"mmm"-"yyyy" hh":"nn":"ss', qSomeTable_DateEntered.AsDateTime));
WriteLn(qSomeTable_Notes.AsString);

I have some demos of indy client-server comms here
http://sourceforge.net/projects/internetdemos

0
 

Author Comment

by:alpires
ID: 20371023
ok I understand but my question is:

1- When event is fired and server read the table, how to know what connection to send the message, there is some information that identifies the connection ?
2- How insert lines in the table with IBO and this be thread-safe (because two clients can send  informations in same time)
0
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 500 total points
ID: 20371345
1.
  the indy tcp server has a "LockList" that you can iterate through to find the connections.
  or you could have the connection do a thread safe call to the main vcl (or simlpy a TCriticalSection as below) to get the latest adta.
2.
If you want to use IBObjects on your form (main vcl thread) then the easiest way to make it thread safe is by using a TCriticalSection. Make sure you keep the code as fast as possible, and always use try..finally as in
var
 mylock: tcriticalsection;
implementation

uses SyncObjs;
...

mylock.Enter
try
..
finally
  mylock.Leave;
end;


Alternatively, if you don't want to use the main thread at all (a good idea if your ibobject work takes a while) then create the ibObjects inside each thread (server's OnExecute event), and only use them there.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi OLE Error 8 95
Magic Software info 18 125
tvirtualstringtree freeze when load too manny images 10 52
Multi-layered image in FireMonkey 9 16
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now