Solved

IdTCPServer and IBO

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi XE10 Round Image 2 226
Controlled Assessment GCSE - desperate help needed 4 121
Create a path if not exists 7 125
firemonkey keyboard covers the controls 1 83
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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

739 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