Go to the Index page
Main page Products News Software Support Where to Buy SiteMap

Delphi TCP/IP logger/server example

An example of simple TCP/IP logger written in Borland Delphi 6.0 demonstrates a server, that reacts on client requests, logs all incoming data, accesses and connection errors in two files. This program also shows, how to access Windows registry, native INI files etc.

The program is very simple application for demonstration purposes and it can be used as a base for your own programming. Main point of the program is to draw correct network solution and error handling during program lifetime.


TMainForm class methods

  • procedure DataSelectClick(Sender: TObject);
    (* This routine is called by DataSelect button and enables to choose the data output file by user *)
  • procedure AccessSelectClick(Sender: TObject);
    (* This method is called by user's AccessSelect button press and provides user to choose proper access logfile *)
  • procedure AppEventsMinimize(Sender: TObject);
    (* Call-back method handling minimalization of main window and its "cleaning" out of the screen *)
  • procedure TrayIconDblClick(Sender: TObject);
    (* Method called by double click on program's systray icon and restoring main window position on the screen *)
  • procedure FormCreate(Sender: TObject);
    (* A routine called by system while the program initializes main window. It handles INI file parsing, preparing the server part etc. *)
  • procedure TryConnect(Sender: TObject);
    (* Method that tries to open the server's listening mode, it also disables some buttons on the screen *)
  • procedure Disconnect(Sender: TObject);
    (* This method is called after request for closing the server's listening mode, enables appropriate buttons on the screen *)
  • procedure ServerSocketAccept(Sender: TObject; Socket: TCustomWinSocket);
    (* This method is called after first contact with client, for program itself it has only statistical meaning *)
  • procedure ServerSocketClientConnect(Sender: TObject; Socket: TCustomWinSocket);
    (* This method is called after client succesfuly connects the server, for program itself it has only statistical meaning *)
  • procedure ServerSocketClientDisconnect(Sender: TObject; Socket: TCustomWinSocket);
    (* This routine is called by system when the client disconnects, the event is logged in the file *)
  • procedure ServerSocketClientError(Sender: TObject; Socket: TCustomWinSocket; ErrorEvent: TErrorEvent; var ErrorCode: Integer);
    (* A method that reacts on connection errors (broken connection, busy server port etc.) It logs all errors to the file *)
  • procedure AppEventsException(Sender: TObject; E: Exception);
    (* Call-back method, that reacts on any errors and exceptions arising from inappropriate situations in program flow and logs the errors to the file for debugging purposes *)
  • procedure FormDestroy(Sender: TObject);
    (* A cleaning routine called by system after user requests an application finish *)
  • procedure ServerSocketClientRead(Sender: TObject; Socket: TCustomWinSocket);
    (* Call-back method called when any data from client arrive. It logs all incoming traffic and displays amount of incoming data for single connection in status bar *)
  • procedure WMMinimize( var E : TMessage );
    (* Helper routine that handles minimalization of main window after program startup. It uses Windows messaging system. *)
  • procedure AppendLog( Msg : string );
    procedure AppendData( Msg : string );

    (* These two routines log all incoming data, respectively access and error messages to appropriate files *)

 

Download of program & source codes

  • dphi_server_example.zip
       \Mail.pas, Mail.dfm, TCPIPlogger.dpr and other source files
       \Program\TCPIPlogger.exe, TCPIPlogger.ini


  Main page Products Support & Download Pricelist Contacts SiteMap  


HW group - Prague - Czech republic - Europe