Fast Inter Machine Communication for Delphi based on TCP/IP. Main features are:

  • Fast inter machine comunication channel
  • Packet oriented messaging.
  • Hides technical implementation from user
  • Client/Server approach. Multiple clients, thread safe…
  • Multithreaded server using thread pool
  • Data packets are versatile data carriers
Cromis IMC download: Version 1.6.0 (20.08.2013)

To demo bellow shows the basic usage of Cromis IMC communication for Delphi. The first sample is for client side and the second for server side. If you have trouble using the code or have any other questions, please contact me directly using the “Contact” page or write a comment bellow the page.

Client side:

procedure TfMain.btnSendClick(Sender: TObject);
var
  Result: IIMCData;
  Request: IIMCData;
  IMCClient: TIMCClient;
  TimeStamp: TDateTime;
begin
  IMCClient := TIMCClient.Create;
  try
    IMCClient.ServerAddress := eServerAddress.Text;
    IMCClient.ConnectClient;
    try
      if IMCClient.IsConnected then
      begin
        Request := AcquireIMCData;
        Request.ID := DateTimeToStr(Now);
        Request.Data.WriteUTF8String('Command', 'Synchronous');
        Result := IMCClient.ExecuteConnectedRequest(Request);
 
        if IMCClient.AnswerValid then
        begin
          TimeStamp := Result.Data.ReadDateTime('TDateTime');
          ListBox1.Items.Add(Format('Synchronous Response with ID: %s', [Result.ID]));
          ListBox1.Items.Add(Format('Response: TDateTime [%s]', [DateTimeToStr(TimeStamp)]));
          ListBox1.Items.Add(Format('Response: Integer [%d]', [Result.Data.ReadInteger('Integer')]));
          ListBox1.Items.Add(Format('Response: Real [%f]', [Result.Data.ReadReal('Real')]));
          ListBox1.Items.Add(Format('Response: String [%s]', [Result.Data.ReadUTF8String('String')]));
          ListBox1.Items.Add('-----------------------------------------------------------');
        end;
      end;
 
      if IMCClient.LastError <> 0 then
        ListBox1.Items.Add(Format('Error: Code %d', [IMCClient.LastError]));
    finally
      IMCClient.DisconnectClient;
    end;
  finally
    IMCClient.Free;
  end;
end;

Server side:

procedure TfMain.OnExecuteRequest(const Context: ICommContext; const Request, Response: IMessageData);
var
  Command: AnsiString;
  LocalCount: Integer;
begin
  Command := Request.Data.ReadUTF8String('Command');
  WriteToListBox(Format('%s request recieved from client %s (Sent at: %s)', [Command,
                                                                             Context.Client.ID,
                                                                             Request.ID]));
  // increase the request count thread safe way
  LocalCount := InterlockedIncrement(FRequestCount);
 
  Response.ID := Format('Response nr. %d', [LocalCount]);
  Response.Data.WriteDateTime('TDateTime', Now);
  Response.Data.WriteInteger('Integer', 5);
  Response.Data.WriteReal('Real', 5.33);
  Response.Data.WriteUTF8String('String', 'to je testni string');
 
  PostMessage(Handle, WM_OnRequestFinished, 0, 0);
end;

Change Log

  • 1.6.0 (Breaking Change)
    • Reorganized context and client classes
  • 1.5.0 (Breaking Change)
    • Exposed Bindings of TCP server with proxy interfaces
    • ServerPort changed to DefaultPort
    • Unit renamed to Cromis.Comm.IMC
  • 1.4.0
    • OnClientConnect, OnClientDisconnect, OnServerError handlers for server
    • Internal list of all connected clients (optional)
    • Pass client context inside OnExecute handler
    • Improved error handling and notifications
  • 1.3.2
    • Do not move ID bytes if ID is not set
  • 1.3.1
    • Catch the Indy EIdNotConnected and not let it through
  • 1.3.0
    • Greatly improved speed by using buffering and eliminating some waits
    • Better handling of internal server errors when executing requests
  • 1.2.0
    • Made INDY9 and BDS 2006 upward compatible
  • 1.1.3
    • Added IsConnected property
  • 1.1.2
    • Same code syntax as in IPC
  • 1.1.1
    • Code optimizations
    • Execute timeout for server
    • ErroDesc for client
  • 1.1.0
    • Optimized the code for speed
    • Restructured some of the code and some of the procedures and properties
    • Added execute timeouts, to both server and client
  • 1.0.2
    • Initial implementation