Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

IdTCPServer and IBO

Posted on 2007-11-28
3
Medium Priority
?
1,114 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 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Screencast - Getting to Know the Pipeline
Suggested Courses

783 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