Solved

IdTCPServer and IBO

Posted on 2007-11-28
3
1,101 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

747 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

10 Experts available now in Live!

Get 1:1 Help Now