Datasnap How to monitor the connection of clients

Source: Internet
Author: User

It is not necessary if the client is TCP/IP is a short connection.

1 type2Pclientconns = ^tclientconns;//Customer Connection3Tclientconns =Record4 Clientid:integer;5Ip:string;6Portstring;7 Logintime:tdatetime;8 End;9 Ten type OneG_clientconnects:tdictionary<tidtcpconnection, pclientconns>;//Client Connection Dictionary A  - procedureTservercontainer1.dstcpservertransport1connect - (event:tdstcpconnecteventobject); the var - P:pclientconns; - begin - Try + ifG_connnectcount >= G_maxconnnum Then - begin +Loginfo ('the number of client connections authorized by the system has been exceeded'); A tidtcpconnection (event.connection). Disconnect; at exit; - End; - InterlockedIncrement (g_connnectcount); - New (p); - ifAssigned (P) Then - begin inP^.clientid: =Event.Channel.ChannelInfo.Id; -P^.ip: =Event.Channel.ChannelInfo.ClientInfo.IpAddress; toP^.port: =Event.Channel.ChannelInfo.ClientInfo.ClientPort; +P^.logintime: =Now ; - G_clientconnects.add (Tidtcpconnection (event.connection), p); the PostMessage (Application.MainForm.Handle, Wm_adduser, WParam (p), * LParam (Tidtcpconnection (event.connection))); $ End;Panax Notoginseng except - exit; the End; + End; A  the procedureTservercontainer1.dstcpservertransport1disconnect + (event:tdstcpdisconnecteventobject); - var $ P:pclientconns; $ begin - Try - ifG_connnectcount >=1  Then the interlockeddecrement (globalvar.g_connnectcount); -P: =g_clientconnects.items[tidtcpconnection (event.connection)];Wuyi ifAssigned (P) Then the begin -SendMessage (Application.MainForm.Handle, Wm_deluser, WParam (p),0); Wu G_clientconnects.remove (Tidtcpconnection (event.connection)); - End; About except $ exit; - End; - End; -  A procedureTf_mainform.adduser (varmsg:tmessage); + var the P:pclientconns; - begin $ Try theLabel4.caption: =IntToStr (g_connnectcount); theP: =Pclientconns (Msg. WParam); the ifAssigned (P) Then the begin - Clientdataset1.append; inClientdataset1.fieldbyname ('ID'). Asinteger: =P^.clientid; theClientdataset1.fieldbyname ('IP'). Asstring: =P^.ip; theClientdataset1.fieldbyname ('Port'). Asstring: =P^.port; AboutClientdataset1.fieldbyname (' Time'). Asdatetime: =P^.logintime; theClientdataset1.fieldbyname ('Conn'). Asinteger: =Msg. LParam; the Clientdataset1.post; the End; + except -On E:exception Do the beginBayiLoginfo ('Tf_mainform.adduser---'+e.message); the exit; the End; - End; - End; the  the procedureTf_mainform.deluser (varmsg:tmessage); the var the P:pclientconns; - begin the Try theLabel4.caption: =IntToStr (g_connnectcount); theP: =Pclientconns (Msg. WParam);94 ifAssigned (P) Then the begin the ifClientdataset1.findkey ([P^.clientid]) Then the Clientdataset1.delete;98 Dispose (p); About End; - except101On E:exception Do102 begin103Loginfo ('Tf_mainform.deluser---'+e.message);104 exit; the End;106 End;107 End;

Datasnap How to monitor the connection of clients

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.