Home arrow Delphi-Kylix arrow Page 2 - Server Side Chat Application with Borland Delphi/Indy, concluded
DELPHI-KYLIX

Server Side Chat Application with Borland Delphi/Indy, concluded


This article picks up where last week's article on building a server side chat application left off. By the time you reach the end, you should have a fully functioning chat server.

Author Info:
By: Jacques Noah
Rating: 5 stars5 stars5 stars5 stars5 stars / 8
January 02, 2006
TABLE OF CONTENTS:
  1. · Server Side Chat Application with Borland Delphi/Indy, concluded
  2. · Code for connecting clients
  3. · The heart of the application
  4. · Code for leaving a chat

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Server Side Chat Application with Borland Delphi/Indy, concluded - Code for connecting clients
(Page 2 of 4 )

The next bit of code gets fired when a client connects. Click on the idtcpserver component and then go to the object inspectors events’ tab and double click on the OnConnect procedure. Now add the following code:

procedure TForm1.tsConnect(AContext: TIdContext);
    begin
//tmycontext is the class that holds client info such as nickname, ip etc
        with TMyContext(AContext) do
        begin
//get time and date that the client connected
            Con := Now;
            if (Connection.Socket <> nil) then
//get client ip address
            IP :=Connection.Socket.Binding.PeerIP;
//get client nickname
            Nick := Connection.IOHandler.ReadLn;
            if Nick <> '' then
            begin
//send a welcome msg to client
                Connection.IOHandler.WriteLn('Welcome ' + Nick + '!');
//tell everybody else that he joined
                BroadcastMsg(Nick + ' just joined!');
            end else
            begin
//if no nickname is not provided, end connection
                Connection.IOHandler.WriteLn('No Nick provided! Goodbye.');
                Connection.Disconnect;
            end;
        end;
    end;


blog comments powered by Disqus
DELPHI-KYLIX ARTICLES

- Loading an XML Document into the DOM
- Delphi Wrapper Classes and XML
- Delphi and the DOM
- Delphi and XML
- Internet Access: Client Service
- Finishing the Client for an Internet Access ...
- The Client for an Internet Access Control Ap...
- User Management for an Internet Access Contr...
- Important Procedures for an Internet Access ...
- Server Code for an Internet Access Control A...
- Constructing the Interface for an Internet A...
- Building a Server Application for an Interne...
- Building an Internet Access Control Applicat...
- Client Dataset: Working with Data Packets an...
- Using the Client Dataset in an N-Tiered Appl...

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 8 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials