服务端代码:

unit RtcHttpServer;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ImgList, StdCtrls, ComCtrls, rtcInfo, rtcConn, rtcDataSrv, rtcHttpSrv,
rtcFunction, rtcSrvModule; type
TMsgType = (mtOK, mtHelp, mtErr); TrtcHttpServerDemo = class(TForm)
RtcHttpServer1: TRtcHttpServer;
ListView1: TListView;
Button1: TButton;
Button2: TButton;
ImageList1: TImageList;
RtcFunctionGroup1: TRtcFunctionGroup;
RtcFunction1: TRtcFunction;
RtcServerModule1: TRtcServerModule;
procedure Button1Click(Sender: TObject);
procedure RtcHttpServer1Connect(Sender: TRtcConnection);
procedure RtcHttpServer1Connecting(Sender: TRtcConnection);
procedure RtcHttpServer1Disconnect(Sender: TRtcConnection);
procedure RtcHttpServer1ListenStart(Sender: TRtcConnection);
procedure RtcHttpServer1SessionClose(Sender: TRtcConnection);
procedure RtcHttpServer1SessionOpen(Sender: TRtcConnection);
procedure RtcHttpServer1ListenLost(Sender: TRtcConnection);
procedure RtcFunction1Execute(Sender: TRtcConnection;
Param: TRtcFunctionInfo; Result: TRtcValue);
private
procedure LogEvent(msg: String; msgType: TMsgType);
procedure LogClear;
public
{ Public declarations }
end; var
rtcHttpServerDemo: TrtcHttpServerDemo; implementation {$R *.dfm} procedure TrtcHttpServerDemo.Button1Click(Sender: TObject);
begin
//开始监听
RtcHttpServer1.Listen();
end; procedure TrtcHttpServerDemo.LogClear;
begin
//清除事件列表
ListView1.Items.Clear;
end; procedure TrtcHttpServerDemo.LogEvent(msg: String; msgType:TMsgType);
var
ltIco: TListItem;
begin
ltIco := ListView1.Items.Add;
ltIco.SubItems.Add(msg);
ltIco.SubItems.Add(DateTimeToStr(Now));
//设置图标
case msgType of
mtOK: ltIco.StateIndex := ;
mtHelp: ltIco.StateIndex := ;
mtErr: ltIco.StateIndex := ;
end; ListView1.Scroll(, );
end; procedure TrtcHttpServerDemo.RtcFunction1Execute(Sender: TRtcConnection;
Param: TRtcFunctionInfo; Result: TRtcValue);
begin
with Sender as TRtcDataServer do
begin
//请求名字
LogEvent('请求参数:' + Param.asString['name'], mtOK);
Result.asString := 'Hello: ' + Param.asString['name'];
end;
end; procedure TrtcHttpServerDemo.RtcHttpServer1Connect(Sender: TRtcConnection);
//连接事件
begin
LogEvent('连接成功:客户端地址:' + Sender.PeerAddr + ',当前客户端连接数'
+ IntToStr(Sender.TotalConnectionCount), mtOK); end; procedure TrtcHttpServerDemo.RtcHttpServer1Connecting(Sender: TRtcConnection);
begin
LogEvent(Sender.sPeerAddr + '正在连接中...', mtOk);
end; procedure TrtcHttpServerDemo.RtcHttpServer1Disconnect(Sender: TRtcConnection);
begin
LogEvent(Sender.sPeerAddr + '连接断开了... 当前客户端连接数'
+ IntToStr(Sender.TotalConnectionCount - ), mtOk);
end; procedure TrtcHttpServerDemo.RtcHttpServer1ListenLost(Sender: TRtcConnection);
begin
LogEvent('监听丢失:' + Sender.PeerAddr, mtErr);
end; procedure TrtcHttpServerDemo.RtcHttpServer1ListenStart(Sender: TRtcConnection);
begin
LogClear;
LogEvent('服务启动中',Mtok);
end; procedure TrtcHttpServerDemo.RtcHttpServer1SessionClose(Sender: TRtcConnection);
begin
LogEvent('会话已关闭',MtErr);
end; procedure TrtcHttpServerDemo.RtcHttpServer1SessionOpen(Sender: TRtcConnection);
begin
LogEvent('会话已成功连接',MtErr);
end; end.

客户端代码:

unit RtcClient;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, rtcConn, rtcDataCli, rtcHttpCli, rtcInfo, rtcFunction, StdCtrls,
ExtCtrls, ComCtrls, ImgList, rtcCliModule; type TMsgType = (mtOK, mtHelp, mtErr); TfrmRtcHttpClient = class(TForm)
RtcFunction1: TRtcFunction;
RtcHttpClient1: TRtcHttpClient;
ListView1: TListView;
Panel1: TPanel;
Button1: TButton;
ImageList1: TImageList;
RtcClientModule1: TRtcClientModule;
RtcFunctionGroup1: TRtcFunctionGroup;
Button2: TButton;
RtcResult1: TRtcResult;
edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure RtcHttpClient1ConnectError(Sender: TRtcConnection; E: Exception);
procedure RtcHttpClient1ConnectFail(Sender: TRtcConnection);
procedure RtcFunction1Execute(Sender: TRtcConnection;
Param: TRtcFunctionInfo; Result: TRtcValue);
procedure edit1KeyPress(Sender: TObject; var Key: Char);
procedure RtcResult1Return(Sender: TRtcConnection; Data, Result: TRtcValue);
procedure RtcHttpClient1Connect(Sender: TRtcConnection);
private
procedure LogEvent(msg: String; msgType: TMsgType);
procedure LogClear;
public
{ Public declarations }
end; var
frmRtcHttpClient: TfrmRtcHttpClient; implementation {$R *.dfm} procedure TfrmRtcHttpClient.Button1Click(Sender: TObject);
begin
if RtcHttpClient1.isConnected
or RtcHttpClient1.isConnecting then
exit;
RtcHttpClient1.Connect();
end; procedure TfrmRtcHttpClient.edit1KeyPress(Sender: TObject; var Key: Char);
begin
//发送请求
if key = # then begin
with RtcClientModule1, Data do
begin
with NewFunction('SimpleTest') do begin
asString['name'] := edit1.Text;
Call(RtcResult1);
end;
end;
end; end; procedure TfrmRtcHttpClient.LogClear;
begin
ListView1.Items.Clear;
end; procedure TfrmRtcHttpClient.LogEvent(msg: String; msgType: TMsgType);
var
ltIco, ltEvent, ltDate: TListItem;
begin
ltIco := ListView1.Items.Add;
ltIco.SubItems.Add(msg);
ltIco.SubItems.Add(DateTimeToStr(Now));
//设置图标
case msgType of
mtOK: ltIco.StateIndex := ;
mtHelp: ltIco.StateIndex := ;
mtErr: ltIco.StateIndex := ;
end; ListView1.Scroll(, );
end; procedure TfrmRtcHttpClient.RtcFunction1Execute(Sender: TRtcConnection;
Param: TRtcFunctionInfo; Result: TRtcValue);
begin
Param.asString['name'] := 'pengshaomin';
LogEvent('服务器响应:' + Result.asString, mtOK);
end; procedure TfrmRtcHttpClient.RtcHttpClient1Connect(Sender: TRtcConnection);
begin
LogEvent('连接服务器[' + Sender.sServerAddr +']成功', mtOK);
end; procedure TfrmRtcHttpClient.RtcHttpClient1ConnectError(Sender: TRtcConnection;
E: Exception);
begin
LogEvent('连接服务器[' + Sender.sServerAddr +']错误', mtErr);
end; procedure TfrmRtcHttpClient.RtcHttpClient1ConnectFail(Sender: TRtcConnection);
begin
LogEvent('连接服务器[' + Sender.sServerAddr +']失败', mtErr);
end; procedure TfrmRtcHttpClient.RtcResult1Return(Sender: TRtcConnection; Data,
Result: TRtcValue);
begin with Sender as TRtcDataClient do
begin
LogEvent( (Sender as TRtcDataClient).sServerAddr + '服务器:' + Result.asString, mtOK);
end;
end; end.

http://www.cnblogs.com/pengshaomin/archive/2012/10/10/2718579.html

RealThinClient学习(一)的更多相关文章

  1. RealThinClient SDK 学习笔记(1)

    从客户端调用远程函数的两种方法 1: RtcClientModule1.Prepare('select'); // call the "select" function on th ...

  2. 从直播编程到直播教育:LiveEdu.tv开启多元化的在线学习直播时代

    2015年9月,一个叫Livecoding.tv的网站在互联网上引起了编程界的注意.缘于Pingwest品玩的一位编辑在上网时无意中发现了这个网站,并写了一篇文章<一个比直播睡觉更奇怪的网站:直 ...

  3. Angular2学习笔记(1)

    Angular2学习笔记(1) 1. 写在前面 之前基于Electron写过一个Markdown编辑器.就其功能而言,主要功能已经实现,一些小的不影响使用的功能由于时间关系还没有完成:但就代码而言,之 ...

  4. ABP入门系列(1)——学习Abp框架之实操演练

    作为.Net工地搬砖长工一名,一直致力于挖坑(Bug)填坑(Debug),但技术却不见长进.也曾热情于新技术的学习,憧憬过成为技术大拿.从前端到后端,从bootstrap到javascript,从py ...

  5. 消息队列——RabbitMQ学习笔记

    消息队列--RabbitMQ学习笔记 1. 写在前面 昨天简单学习了一个消息队列项目--RabbitMQ,今天趁热打铁,将学到的东西记录下来. 学习的资料主要是官网给出的6个基本的消息发送/接收模型, ...

  6. js学习笔记:webpack基础入门(一)

    之前听说过webpack,今天想正式的接触一下,先跟着webpack的官方用户指南走: 在这里有: 如何安装webpack 如何使用webpack 如何使用loader 如何使用webpack的开发者 ...

  7. Unity3d学习 制作地形

    这周学习了如何在unity中制作地形,就是在一个Terrain的对象上盖几座小山,在山底种几棵树,那就讲一下如何完成上述内容. 1.在新键得项目的游戏的Hierarchy目录中新键一个Terrain对 ...

  8. 《Django By Example》第四章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:祝大家新年快乐,这次带来<D ...

  9. 菜鸟Python学习笔记第一天:关于一些函数库的使用

    2017年1月3日 星期二 大一学习一门新的计算机语言真的很难,有时候连函数拼写出错查错都能查半天,没办法,谁让我英语太渣. 关于计算机语言的学习我想还是从C语言学习开始为好,Python有很多语言的 ...

随机推荐

  1. 【代码】Android: 怎样设置app不被系统k掉

    有一种方法可以设置app永远不会被kill,AndroidManifest.xml 中添加: android:persistent="true" 适用于放在/system/app下 ...

  2. iOS 使用Block实现函数回调

    事实上.iOS中的Block就是C++中的函数指针,实现方式都是一样的,以下贴出一个简单的实践. 首先,创建一个回调的类 BlockStudy.h // // BlockStudy.h // Bloc ...

  3. Recipes — Bottle 0.13-dev documentation

    Recipes - Bottle 0.13-dev documentation Recipes¶ This is a collection of code snippets and examples ...

  4. C#的静态构造函数

    “静态构造函数”典型应用于第一次使用类时的初始化工作,注意“第一次”,意思是它只执行一次. 有同学说了,类的初始化不是有构造函数嘛?我们回答:构造函数是每个实例被声明时都会执行的,它属于每一个实例,而 ...

  5. Swift - 通过设置视图的transform属性实现动画

    设置视图对象的transform属性,可以实现各种动画效果. 1,移动 指在同一平面内,将控件按照某个直线方向平移一定的距离. 1 2 3 4 5 //每次都从当前位置平移 self.imageVie ...

  6. QT中的pro文件的编写

    原地址:http://blog.csdn.net/fjb2080/article/details/4833666 我们在编译QT的工程的时候,一般都会让qmake自动生成,但有时我们需要定制我们的工程 ...

  7. 关于Delphi中TRttiContext.FindType失效的问题

    自从Delphi2010后,Delphi中的Rtti功能得到了增强.我们终于可以不用先RegisterClass,再GetClass获取类的信息了.而只是简单的通过TRttiContext.GetTy ...

  8. jQuery EasyUI API 中文文档 - 分隔按钮(splitbutton)

    <html> <head> <script src="jquery-easyui/jquery.min.js"></script> ...

  9. html5的自定义data-*属性和jquery的data()方法的使用

    人们总喜欢往HTML标签上添加自定义属性来存储和操作数据.但这样做的问题是,你不知道将来会不会有其它脚本把你的自定义属性给重置掉,此外,你这样做也会导致html语法上不符合Html规范,以及一些其它副 ...

  10. web攻击方式和防御方法

    在http请求报文中载入攻击代码,就能发起对web应用的攻击.通过url查询字段或者表单.http首部.cookie等途径吧攻击代码传入,若这时web应用存在安全漏洞,那内部信息就会遭到窃取! 对we ...