Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

IdTCPServer and IBO

Posted on 2007-11-28
3
Medium Priority
?
1,113 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1500 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

670 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