server端如何发送消息给调用接口方法的client端 ,能让client坐相应的处理!

lile_zhy 2003-06-07 11:22:17
如何将server端的一些信息发送给 client,能让client进行一些处理
比如,
server正在进行一个较长循环的过程,我怎么通知client,目前server已经运行到那里,发送消息给client把处理进度显示在client,这样用户知道还要等多久,否则用户很不耐烦的,
...全文
199 25 打赏 收藏 转发到动态 举报
写回复
用AI写文章
25 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaohuan 2003-08-08
  • 打赏
  • 举报
回复
试一下
PhilexPei 2003-08-06
  • 打赏
  • 举报
回复
最近只会UP:(
beginer001 2003-08-04
  • 打赏
  • 举报
回复
s
freekany2002 2003-07-30
  • 打赏
  • 举报
回复
callback
ZRX_JYP 2003-07-30
  • 打赏
  • 举报
回复
midas 的服务器端能否把信息主动推到客户端?

在数据库中产生了一条新的记录,midas 的服务器端程序能否
主动的将这一信息主动的推到指定的客户端,让客户端知道.
就象 Lotus Notes 一样.
ihihonline 2003-07-18
  • 打赏
  • 举报
回复
//////////索性将服务应用程序也贴上,没有作用的,就是用来标示客户是否可以正确连接
unit ServerM;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Label1: TLabel;
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

end.
unit Server_TLB;

// ************************************************************************ //
// WARNING
// -------
// The types declared in this file were generated from data read from a
// Type Library. If this type library is explicitly or indirectly (via
// another type library referring to this type library) re-imported, or the
// 'Refresh' command of the Type Library Editor activated while editing the
// Type Library, the contents of this file will be regenerated and all
// manual modifications will be lost.
// ************************************************************************ //

// PASTLWTR : $Revision: 1.130 $
// File generated on 2002-11-24 0:46:21 from Type Library described below.

// ************************************************************************ //
// Type Lib: D:\练习\Midas\DCOM\200210232330\Server.tlb (1)
// LIBID: {4C13B05F-CEBC-4CEF-9B10-C0C6C5381A70}
// LCID: 0
// Helpfile:
// DepndLst:
// (1) v2.0 stdole, (C:\WINNT\System32\stdole2.tlb)
// (2) v4.0 StdVCL, (C:\WINNT\System32\stdvcl40.dll)
// (3) v1.0 Midas, (C:\WINNT\System32\midas.dll)
// ************************************************************************ //
{$TYPEDADDRESS OFF} // Unit must be compiled without type-checked pointers.
{$WARN SYMBOL_PLATFORM OFF}
{$WRITEABLECONST ON}

interface

uses ActiveX, Classes, Graphics, Midas, StdVCL, Variants, Windows;



// *********************************************************************//
// GUIDS declared in the TypeLibrary. Following prefixes are used:
// Type Libraries : LIBID_xxxx
// CoClasses : CLASS_xxxx
// DISPInterfaces : DIID_xxxx
// Non-DISP interfaces: IID_xxxx
// *********************************************************************//
const
// TypeLibrary Major and minor versions
ServerMajorVersion = 1;
ServerMinorVersion = 0;

LIBID_Server: TGUID = '{4C13B05F-CEBC-4CEF-9B10-C0C6C5381A70}';

IID_IDCOMServerSL1: TGUID = '{3532A2E2-A14F-4C6F-BEDD-2E195668C084}';
CLASS_DCOMServerSL1: TGUID = '{3D40FD5D-FFD8-4712-9C4A-2058FEA41C5C}';
IID_IDCOMBackCall: TGUID = '{A9B9B314-662F-4B95-8282-7EFD3F78549E}';
CLASS_DCOMBackCall: TGUID = '{B140EEA0-2115-433C-A8FB-3BD915B24FCC}';
IID_IDCOMBackCalls: TGUID = '{6C16F66E-CF22-4E61-9F4F-82F5F1933154}';
type

// *********************************************************************//
// Forward declaration of types defined in TypeLibrary
// *********************************************************************//
IDCOMServerSL1 = interface;
IDCOMServerSL1Disp = dispinterface;
IDCOMBackCall = interface;
IDCOMBackCallDisp = dispinterface;
IDCOMBackCalls = interface;
IDCOMBackCallsDisp = dispinterface;
//.............
// *********************************************************************//
// DispIntf: IDCOMBackCallDisp
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {A9B9B314-662F-4B95-8282-7EFD3F78549E}
// *********************************************************************//
IDCOMBackCallDisp = dispinterface
['{A9B9B314-662F-4B95-8282-7EFD3F78549E}']
procedure GetInfos(var Infos: OleVariant); dispid 1;
end;

// *********************************************************************//
// Interface: IDCOMBackCalls
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {6C16F66E-CF22-4E61-9F4F-82F5F1933154}
// *********************************************************************//
IDCOMBackCalls = interface(IDispatch)
['{6C16F66E-CF22-4E61-9F4F-82F5F1933154}']
procedure SetInfo(var InfoName: OleVariant; var InfoPass: OleVariant); safecall;
end;

// *********************************************************************//
// DispIntf: IDCOMBackCallsDisp
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {6C16F66E-CF22-4E61-9F4F-82F5F1933154}
// *********************************************************************//
IDCOMBackCallsDisp = dispinterface
['{6C16F66E-CF22-4E61-9F4F-82F5F1933154}']
procedure SetInfo(var InfoName: OleVariant; var InfoPass: OleVariant); dispid 1;
end;

// *********************************************************************//
// The Class CoDCOMServerSL1 provides a Create and CreateRemote method to
// create instances of the default interface IDCOMServerSL1 exposed by
// the CoClass DCOMServerSL1. The functions are intended to be used by
// clients wishing to automate the CoClass objects exposed by the
// server of this typelibrary.
// *********************************************************************//
CoDCOMServerSL1 = class
class function Create: IDCOMServerSL1;
class function CreateRemote(const MachineName: string): IDCOMServerSL1;
end;

// *********************************************************************//
// The Class CoDCOMBackCall provides a Create and CreateRemote method to
// create instances of the default interface IDCOMBackCall exposed by
// the CoClass DCOMBackCall. The functions are intended to be used by
// clients wishing to automate the CoClass objects exposed by the
// server of this typelibrary.
// *********************************************************************//
CoDCOMBackCall = class
class function Create: IDCOMBackCall;
class function CreateRemote(const MachineName: string): IDCOMBackCall;
end;

implementation

uses ComObj;

class function CoDCOMServerSL1.Create: IDCOMServerSL1;
begin
Result := CreateComObject(CLASS_DCOMServerSL1) as IDCOMServerSL1;
end;

class function CoDCOMServerSL1.CreateRemote(const MachineName: string): IDCOMServerSL1;
begin
Result := CreateRemoteComObject(MachineName, CLASS_DCOMServerSL1) as IDCOMServerSL1;
end;

class function CoDCOMBackCall.Create: IDCOMBackCall;
begin
Result := CreateComObject(CLASS_DCOMBackCall) as IDCOMBackCall;
end;

class function CoDCOMBackCall.CreateRemote(const MachineName: string): IDCOMBackCall;
begin
Result := CreateRemoteComObject(MachineName, CLASS_DCOMBackCall) as IDCOMBackCall;
end;

end
希望对你有帮助
ihihonline 2003-07-18
  • 打赏
  • 举报
回复
unit ServerRDM; ////////远程数据模块,是回调机制用的,于DCOM无关;

{$WARN SYMBOL_PLATFORM OFF}

interface

uses
Windows, Messages, SysUtils, Classes, ComServ, ComObj, VCLCom, DataBkr,
DBClient, Server_TLB, StdVcl;

type
TDCOMBackCall = class(TRemoteDataModule, IDCOMBackCall)
private
BackCallSL : OleVariant;
{ Private declarations }
protected
class procedure UpdateRegistry(Register: Boolean; const ClassID, ProgID: string); override;
procedure GetInfos(var Infos: OleVariant); safecall;
public
{ Public declarations }
end;

implementation

{$R *.DFM}

class procedure TDCOMBackCall.UpdateRegistry(Register: Boolean; const ClassID, ProgID: string);
begin
if Register then
begin
inherited UpdateRegistry(Register, ClassID, ProgID);
EnableSocketTransport(ClassID);
EnableWebTransport(ClassID);
end else
begin
DisableSocketTransport(ClassID);
DisableWebTransport(ClassID);
inherited UpdateRegistry(Register, ClassID, ProgID);
end;
end;

procedure TDCOMBackCall.GetInfos(var Infos: OleVariant);
begin
BackCallSl := Infos;
BackCallSl.SetInfo('a','b');
{////////////////////////////////////////////////
///////BackCallSl := Infos;(还记得这个参数传过来的是什么吗?呵呵,看前边去;)
/////回调,可以由任意事件进行激发
///////////////////////////////////////////////// }
end;

initialization
TComponentFactory.Create(ComServer, TDCOMBackCall,
Class_DCOMBackCall, ciMultiInstance, tmApartment);
end.
unit SLXK;//////////DCOM,与回调无关

{$WARN SYMBOL_PLATFORM OFF}

interface

uses
ComObj, ActiveX, Server_TLB, StdVcl;

type
TDCOMServerSL1 = class(TAutoObject, IDCOMServerSL1)
protected
function GetInfo(const UserName, Pass: WideString): WordBool; safecall;
procedure Call; safecall;
{ Protected declarations }
end;

implementation
uses
ServerM ,ComServ;

function TDCOMServerSL1.GetInfo(const UserName,
Pass: WideString): WordBool;
begin
if ( UserName <>'Server' ) or (Pass <>'Admin') then
begin
Result := False
end else
begin
Result := True;
Form1.Label1.Caption := '客户成功登录';
end;
{//////////////////////////////////////////////////////////////////////////////
/////////这个自己分析,如果说不会,那就惨喽
//////////////////////////////////////////////////////////////////////////////}
end;

procedure TDCOMServerSL1.Call;
begin
ShowMessage('aa'); //// or GetInfo(UserName,Pass);
end;

initialization
TAutoObjectFactory.Create(ComServer, TDCOMServerSL1, Class_DCOMServerSL1,
ciMultiInstance, tmApartment);
end.
ihihonline 2003-07-18
  • 打赏
  • 举报
回复
unit ClientM; /////////客户端窗体;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,ComObj,Server_TLB,MConnect, DB, DBClient, SConnect,ActiveX,
ComServ;

type
TClientCallBack = Class(TAutoIntfObject , IDCOMBackCalls)
procedure SetInfo(var InfoName: OleVariant; var InfoPass: OleVariant); safecall;
end;

//////////////////////////////////////////////////////////////////////////////
//////////TClientCallBack = Class(TAutoIntfObject,IDCOMBackCalls) TClientCallBack 它继承类TAutoIntfObject
//////////同时又是实现了接口IDCOMBackCalls,而这个接口是需要在TypeLib中声明的;
///////////接口的实现,需要知道,之后还要进行类的实例化;
///////////需要实现这个接口的方法 :SetInfo(.....) SafeCall ,注意,这儿只能用SafeCall;
//////////下边有接口的实例化,FClientCallBack : TClientCallBack;
//////////uses ComObj;
///////////////////////////////////////////////////////////////////////////////////
TForm2 = class(TForm)
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
SocketConnection1: TSocketConnection;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
FClientCallBack : TClientCallBack;
/////////这一句是接口正真的实例化;
{ Private declarations }
public
MyDCOMConnection : TDispatchConnection;
//////注意这一句:TDispatchConnection 是如下定义的:
//////TDispatchConnection = class(TCustomRemoteServer)
{ Public declarations }
end;

var
Form2: TForm2;
ClientVar : IDCOMServerSL1;
//////////////////////////////////////////////////////////////////////////////
//////定义一个接口,是TypeLib中声明的哦;uses Server_TLB,(User TypeLib)
//////////////////////////////////////////////////////////////////////////////

implementation


{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);
begin
ClientVar := CoDCOMServerSL1.Create;
if ClientVar.GetInfo(Edit1.Text,Edit2.Text) then
begin
Application.MessageBox('恭喜您,登录成功!','操作提示',MB_OK + MB_ICONINFORMATION);
end else
begin
Application.MessageBox('对不起,登录失败!','操作提示',MB_OK + MB_ICONINFORMATION);
end;
/////////////////////////////////////////////////////////////////////////////////////
/////////MyDCOMConnection.AppServer.ProcName;,也可以用这种进行回调
/////////CoDCOMBackCall = class
/////////class function Create: IDCOMBackCall;
////////class function CreateRemote(const MachineName: string): IDCOMBackCall;
////////end;
////////看一看它的定义,它其实是一个类,呵呵,协同接口类;是实现一个或多个接口的类,
///////有一个类生成库和一个类标识器;
///////这一部分是DCOM的,和回调无关;
///////////////////////////////////////////////////////////////////////////////////////
end;

{ TClientCallBack }


procedure TForm2.FormCreate(Sender: TObject);
var
TypeLib : ITypeLib;
begin
MyDCOMConnection := SocketConnection1;
MyDCOMConnection.Connected := True;
OLECheck(LoadRegTypeLib(LIBID_Server,0,0,1,TypeLib));
MyDCOMConnection.AppServer.GetInfos(FClientCallBack as IDispatch);
{/////////////////////////////////////////////////////////////////////////////
//////MyDCOMConnection := SocketConnection1;是回调的关键,你要用它来代替TSocketConnection,操作还是类实例之间,你明白吗?
//////MyDCOMConnection.Connected := True;还用说吗?
//////OLECheck(LoadRegTypeLib(LIBID_Server,0,0,1,TypeLib));在客户端注册;
//////MyDCOMConnection.AppServer.GetInfos(FClientCallBack as IDispatch);开始执行,而且进行接口转化;
//////TypeLib : ITypeLib;可以应用类型库类 Uses ActiveX;
//////////////////////////////////////////////////////////////////////////////}
end;

{ TClientCallBack }

procedure TClientCallBack.SetInfo(var InfoName, InfoPass: OleVariant);
begin
ShowMessage(InfoName);
ShowMessage(InfoPass);
{/////////////////////////////////////////////////////////////////////////////
/////我不知道你是否知道RDM中是如果引用接口的,这和它是一样的;
//////////////////////////////////////////////////////////////////////////////}
end;

end.
whxhz80 2003-07-17
  • 打赏
  • 举报
回复
回调可以实现,不过,不懂,关注
dm1cyg 2003-07-06
  • 打赏
  • 举报
回复
dcom 有放火强配置起来可是复杂呀
zbluecn 2003-07-06
  • 打赏
  • 举报
回复
用COM的事件。。DELPHI5开发人员指南上有例子
luckyboy97 2003-07-05
  • 打赏
  • 举报
回复
uo
ninglng 2003-07-03
  • 打赏
  • 举报
回复
服务器端加一个执行进度条(当然有其他的变通的方法),客户端读服务器的进度条的进度不就可以啦。

当然客户端多长时间读一次应该有个节制合适的周期,不然会影响效率。

如果由服务器发消息给客户端,那网络压力,嘿嘿自己想把
duxin 2003-06-19
  • 打赏
  • 举报
回复
其实服务端发消息这个办法我想比较不错

duxin 2003-06-19
  • 打赏
  • 举报
回复
同意楼主
server端的变动客户端能得到及时更新
客户端无法达到主动的目的 虽然编程上不提倡
可有时还要用到

可以在客户端写事件服务端调用
我试过不过并不是很合适
那位高手有好的解决办法?
foxe 2003-06-19
  • 打赏
  • 举报
回复
同意楼主!Server的反映可以直观的显示在Client端!Client主动是不错,可放个Timer怎么预计处理的时间!
owl_927 2003-06-19
  • 打赏
  • 举报
回复
服务端发消息有可能造成"消息风暴"
owl_927 2003-06-18
  • 打赏
  • 举报
回复
严重同意jpyc(智若愚(斯文)) ,
可以在服务端写一个属性,可客户在需要的时候去读,比如放个时钟什么的!但一定是客户端主动。
karl 2003-06-15
  • 打赏
  • 举报
回复
不是说有回调机制嘛,可以用吗?不过我对三程还不熟悉,只是在书上看到
online 2003-06-14
  • 打赏
  • 举报
回复
关注!
加载更多回复(5)

1,593

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧