用户操作
[即时聊天] [发私信] [加为好友]
JohnsonID:51357
20514次访问,排名5825好友0人,关注者0
51357的文章
原创 27 篇
翻译 0 篇
转载 12 篇
评论 12 篇
最近评论
coolboylmk:你就是51357的作者吗?非常喜欢你的作品,51357,longator,中国网爪,都非常棒!
为什么不继续开发longator呢?期待中。。。
怀念当年用56k猫和51357的日子。。。
ScriptBaby:阁下于2000年在delphibbs的一个回复中解释了TWebBrowser内存泄漏的成因和解决办法, 化解了我的一个疑问, 因此我非常感谢您.
我在我的blog中引用了您的回复, 以表示敬意.
http://blog.csdn.net/scriptbaby/archive/2007/05/20/1618486.aspx

btw 从我知道那个问题……
ScriptBaby:阁下是否delphibbs的zhongs?
xuyunlong:看得懂,但有个问题不明白。UDP方式是否还有采用完成端口的必要,如果用,怎么实现呢?UDP下可没有listen和Accept,也返回不了客户端连接的套接口。该把哪个Socket关联到IOCP。
lovefox_zoe:大哥有没有完成端口的例子啊。
文章分类
收藏
相册
音乐
coool link
Ajax基础
C51单片机串行口中断服务程序
cnpack
homepage
STC实现IO_SOFT_SPI接口
UI参考
Visual Studio 2005 Web Application Project Tutorials (with C#)
winx blog
存档
软件项目交易
订阅我的博客
XML聚合  FeedSky
订阅到鲜果
订阅到Google
订阅到抓虾
订阅到BlogLines
订阅到Yahoo
订阅到GouGou
订阅到飞鸽
订阅到Rojo
订阅到newsgator
订阅到netvibes

原创 对已经存在的TCP系统进行登录验证收藏

新一篇: 捕捉网页的windowClose事件,并调用注销登录页面 | 旧一篇: MediaPlayer ActiveX访问自定义的URL协议时问题

要求:使用Media Service作为VOD server,点播流程: WMP - > WMS

由于登录帐号保存在数据库,要实现自己的验证机制,需要在WMS前面加上Socket代理,检查URL中包含

的SessionKey,验证流程:WMP -> Proxy -> WMS

主要是实现一个代理,利用Delphi本身带的控件IdMappedPortTCP很容易就实现了。

unit frmMains;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdBaseComponent, IdComponent, IdTCPServer, IdMappedPortTCP,
  StdCtrls;

type
  TfrmMain = class(TForm)
    Server: TIdMappedPortTCP;
    Label1: TLabel;
    lblConnections: TLabel;
    Memo1: TMemo;
    Button1: TButton;
    procedure ServerConnect(AThread: TIdMappedPortThread);
    procedure ServerDisconnect(AThread: TIdMappedPortThread);
    procedure ServerExecute(AThread: TIdMappedPortThread);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    procedure printf(const S: string);

  end;

var
  frmMain: TfrmMain;

implementation

{$R *.dfm}

var
    ClientCount: Integer = 0;

type
  TThreadData = class
  public
    IsFirstRecv: Boolean;
  end;

procedure TfrmMain.ServerConnect(AThread: TIdMappedPortThread);
begin
    InterlockedIncrement(ClientCount);
    lblConnections.Caption:= IntTostr(ClientCount);

    AThread.Data:= TThreadData.Create;
    TThreadData(AThread.Data).IsFirstRecv:= True;
end;

procedure TfrmMain.ServerDisconnect(AThread: TIdMappedPortThread);
begin
    InterlockedDecrement(ClientCount);
    lblConnections.Caption:= IntTostr(ClientCount);

    // Auto free by TIdMappedPortThread
    //AThread.Data.Free;
end;

procedure TfrmMain.ServerExecute(AThread: TIdMappedPortThread);
var
    Header: string;
    n: Integer;
    Data: string;
    threadData: TThreadData;

    procedure CloseConnect;
    begin
        AThread.OutboundClient.Disconnect;
        AThread.Connection.Disconnect;
    end;
begin
    threadData:= TThreadData(AThread.Data);

    // first recv data, check is HTTP Protocol
    if (threadData <> nil) and threadData.IsFirstRecv then
    begin
        Data:= AThread.NetData;
        n:= Pos(#13, Data);
        if n  > 0 then
        begin
            Header:= Copy(Data, 1, n - 1);
            printf(Header);

            // sample: check URL if has SID string
            // GET /?SID=XXXXXXX HTTP/1.1
            if Copy(Header, 1, 5) = 'GET /' then
            begin
                // check SessionID of Login
                // todo: really check login
                if Pos('SID=', Header) = 0 then
                begin
                    printf('Access denied. ************');
                    CloseConnect;
                end;
            end
            else CloseConnect;
        end
        else CloseConnect;

        threadData.IsFirstRecv:= False;
    end;
end;

procedure TfrmMain.Button1Click(Sender: TObject);
begin
     Memo1.Clear;
end;

procedure TfrmMain.printf(const S: string);
begin
    Memo1.Lines.Add(S);
end;

end.

 

发表于 @ 2007年03月31日 23:01:00|评论(loading...)|编辑

新一篇: 捕捉网页的windowClose事件,并调用注销登录页面 | 旧一篇: MediaPlayer ActiveX访问自定义的URL协议时问题

评论:没有评论。

发表评论  


当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
Csdn Blog version 3.1a
Copyright © Johnson