Delphi develops a chat room based on DCOM

Source: Internet
Author: User
Tags empty

The advent of Distributed COM (hereinafter referred to as DCOM) gives us an opportunity to easily create distributed applications; we can totally ignore the low-level Windows Sockets (DCOM communicates with the object through MS-RPC, fortunately, to develop COM applications, Developers can almost ignore MS-RPC and develop distributed computing systems that are powerful, low in coupling (function modules are relatively independent, well played with OO ideas), and are easily deployable.

In this article, we intend to use DCOM to develop a LAN chat room, not only as a technical research, but actually I believe this should also be a useful tool. First of all we want to have a general understanding of the function of this chat room:

1, at least this chat room should allow multiple LAN users to chat.

2, should be able to have a number of topics of the child chat room, users can choose to enter a chat room to chat.

3, the client should be as simple as possible (do not configure DCOM), and need a server to manage all the interactive behavior, management of the number of chat rooms and related configuration, and do a good job of monitoring and logging system.

4, the chat room function to expand (such as private message function, emoticons, etc.). Based on the above functional description, after careful analysis of the problem we design the following sketch:

In this article we want to basically implement a basic core of this program, including Ichatmanager, Tchatroommanager, Tchatroom, complete a most basic function of the server side, and do a simple client to detect. Our focus is on the server side, because it will implement most of the functions of the chat room, the client is just a very small and simple program.

Due to the length of the relationship, we only list important parts of the code, complete the program please email me. First, let's look at what our Ichatmanager interface looks like:

Ichatmanager = Interface (IDispatch)
[' {e7cd7f0d-447f-497a-8c7b-1d80e748b67f} ']
Procedure Speakto (const content:widestring; destid:integer); Safecall;
The client speaks to the appointed room, DestID the room number.
function Readfrom (Sourceid:integer): istrings; Safecall;
The client reads the conversation from the specified room, SourceID the room number.
function Readready (Id:integer): Byte; Safecall;
Customer detects if the specified room is ready to read the conversation
Procedure Connectroom (const username:widestring; Roomid:integer); Safecall;
Customer Login to designated room
Procedure Disconnectroom (const username:widestring; Roomid:integer); Safecall;
Customer exits designated room
function Testclearbuffertag (Roomid:integer): Integer; Safecall;
Customer tests whether the buffer in the specified room is empty or not
End
Let's look at the implementation class Tchatmanager part of the interface:
Type
Tchatmanager = Class (Tautoobject, Ichatmanager)
Protected
function Readfrom (Sourceid:integer): istrings; Safecall;
Here we use the Delphi extended Complex Type tstings, in order for COM to support this
Type, Delphi provides the Istrings interface
Procedure Speakto (const content:widestring; destid:integer); Safecall;
function Readready (Id:integer): Byte; Safecall;
Used to provide the client query whether the specified room is readable, specifying whether the room buffer is empty
Procedure Connectroom (const username:widestring; Roomid:integer);
Safecall;
Procedure Disconnectroom (const username:widestring; Roomid:integer);
Safecall;
function Testclearbuffertag (Roomid:integer): Integer; Safecall;
End

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.