{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

 Author:       Fran鏾is PIETTE
Object: Demo program to show how to use TWSocket object is a very
simple server program. This server just wait for a client to
connect, then send 'Hello'. When the user click on the
disconnect button, the client is disconnected.
Creation: September 19, 1996
Version: 2.02
EMail: francois.piette@overbyte.be http://www.overbyte.be
Support: Use the mailing list twsocket@elists.org
Follow "support" link at http://www.overbyte.be for subscription.
Legal issues: Copyright (C) 1996-2010 by Fran鏾is PIETTE
Rue de Grady 24, 4053 Embourg, Belgium. Fax: +32-4-365.74.56
<francois.piette@overbytet.be> This software is provided 'as-is', without any express or
implied warranty. In no event will the author be held liable
for any damages arising from the use of this software. Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it
and redistribute it freely, subject to the following
restrictions: 1. The origin of this software must not be misrepresented,
you must not claim that you wrote the original software.
If you use this software in a product, an acknowledgment
in the product documentation would be appreciated but is
not required. 2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source
distribution. Updates:
Mar 19, 1997 Use enhanced TWSocket object
Sep 06, 1997 Beautified
Aug 20, 1999 V2.02 Changed comment to correctly talk about interface use. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
unit OverbyteIcsSrv5; {$J+} interface uses
SysUtils, Windows, Messages, Classes, Graphics,
Controls, Forms, Dialogs, OverbyteIcsWSocket, Winsock, StdCtrls,
OverbyteIcsWndControl; type
TServerForm = class(TForm)
SrvSocket: TWSocket;
InfoLabel: TLabel;
CliSocket: TWSocket;
DisconnectButton: TButton;
procedure SrvSocketSessionAvailable(Sender: TObject; Error: Word);
procedure FormShow(Sender: TObject);
procedure DisconnectButtonClick(Sender: TObject);
procedure CliSocketSessionClosed(Sender: TObject; Error: Word);
procedure FormCreate(Sender: TObject);
procedure SrvSocketBgException(Sender: TObject; E: Exception;
var CanClose: Boolean);
end; var
ServerForm: TServerForm; implementation {$R *.DFM} {* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TServerForm.FormShow(Sender: TObject);
const
FirstTime : Boolean = TRUE;
begin
if FirstTime then begin
FirstTime := FALSE; { Do it only once ! }
SrvSocket.Addr := '0.0.0.0'; { Use any interface }
SrvSocket.Listen; { Start listening for client }
InfoLabel.Caption := 'Waiting for client';
end;
end; {* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{* This event handler is called once a client has connected the server. *}
procedure TServerForm.SrvSocketSessionAvailable(Sender: TObject; Error: Word);
var
NewHSocket : TSocket;
PeerName : TSockAddrIn;
Peer : String;
begin
{ We need to accept the client connection }
NewHSocket := SrvSocket.Accept; { And then associate this connection with our client socket }
CliSocket.Dup(NewHSocket); { Wants to know who is connected to display on screen }
CliSocket.GetPeerName(PeerName, Sizeof(PeerName)); { User likes to see internet address in dot notation }
Peer := IntToStr(ord(PeerName.sin_addr.S_un_b.s_b1)) + '.' +
IntToStr(ord(PeerName.sin_addr.S_un_b.s_b2)) + '.' +
IntToStr(ord(PeerName.sin_addr.S_un_b.s_b3)) + '.' +
IntToStr(ord(PeerName.sin_addr.S_un_b.s_b4));
InfoLabel.Caption := 'Remote ' + Peer + ' connected'; { Send a welcome message to the client }
CliSocket.SendStr('Hello' + # + #); { Enable the server user to disconect the client }
DisconnectButton.Enabled := TRUE;
end; {* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{* This event handler is called once the user clicks on Ddisconnect *}
procedure TServerForm.DisconnectButtonClick(Sender: TObject);
begin
CliSocket.ShutDown(); { Shut the communication down }
CliSocket.Close; { Close the communication }
end; {* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{* This event handler is called once the client connection is broken. *}
{* Either by the client or the server. *}
procedure TServerForm.CliSocketSessionClosed(Sender: TObject; Error: Word);
begin
DisconnectButton.Enabled := FALSE;
InfoLabel.Caption := 'Waiting for client';{ Inform the user }
end; {* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *} procedure TServerForm.FormCreate(Sender: TObject);
begin end; procedure TServerForm.SrvSocketBgException(Sender: TObject; E: Exception;
var CanClose: Boolean);
begin end; end.
 
 

最近一直在学习关于网络 cs方面的东西,写个小博客作为笔记吧。

delphi ICS控件示例解读的更多相关文章

  1. Delphi WebBrowser控件的使用(大全 good)

    Delphi WebBrowser控件的使用 WebBrowser控件属性:1.Application      如果该对象有效,则返回掌管WebBrowser控件的应用程序实现的自动化对象(IDis ...

  2. <总结>delphi WebBrowser控件的使用中出现的bug

    Delphi WebBrowser控件的使用中出现的bug:  1.WebBrowser.Visible=false:Visible属性不能使WebBrowser控件不可见,暂时用 WebBrowse ...

  3. 修改Delphi工具控件的默认字体

    修改Delphi工具控件的默认字体: 注册表: Delphi 6:    HKEY_CURRENT_USER\Software\Borland\Delphi\6.0Delphi 7:    HKEY_ ...

  4. Delphi TcxtreeList控件说明 转

    Delphi TcxtreeList控件说明   树.cxTreeList 属性: Align:布局,靠左,靠右,居中等 AlignWithMargins:带边框的布局 Anchors:停靠 (akT ...

  5. delphi按钮控件的default属性

    delphi按钮控件的default属性用于设置默认命令按钮,.设置为true时,按[Enter键]相当于用鼠标单击了该按钮 .窗口中如果有多个按钮的default是true的话,就根据tabinde ...

  6. asp.net模板控件示例

    原文:asp.net模板控件示例 模板控件允许将控件数据与其表示形式相分离,模板化控件不提供用户界面. 编写它则是为了实现一个命名容器以及包含属性和方法可由宿主页访问的类,MSDN是这样解释的. 下面 ...

  7. Delphi fmx控件在手机滑动与单击的问题

    Delphi fmx控件在手机滑动与单击的问题 (2016-03-08 10:52:00) 转载▼ 标签: it delphi 分类: Delphi10 众所周知,fmx制作的app,对于象TEdit ...

  8. React Native 教程:001 - 如何运行官方控件示例 App

    原文发表于我的技术博客 本文主要讲解了如何运行 React Native 官方控件示例 App,包含了一些 React Native 的基础知识以及相关环境的配置. 原文发表于我的技术博客 React ...

  9. Delphi maskedit控件的掩码含义及用法方法

    Delphi maskedit控件的掩码含义及用法方法   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 2 ...

随机推荐

  1. nginx upstream setting

    upstream proxy_1 { server 127.0.0.1:8080; #连接到上游服务器的最大并发空闲keepalive长连接数(默认是未设置,建议与Tomcat Connector中的 ...

  2. Linux学习之find命令

    find是我们很常用的一个Linux命令,但是我们一般查找出来的并不仅仅是看看而已,还会有进一步的操作,这个时候exec的作用就显现出来了. exec解释: -exec  参数后面跟的是command ...

  3. JavaWeb核心编程之使用Eclipse开发JavaWEB项目

    文章目录 1.eclipse切换到javaee项目 2.创建服务器(如果没有server选项, 怎么做) 3.定制新建面板内容 4.创建动态web工程 1.eclipse切换到javaee项目 如图 ...

  4. [虚拟化/云][全栈demo] 为qemu增加一个PCI的watchdog外设(四)

    通过前面的操作,我们已经可以创建一个带有我们自己的PCI的watchdog外设qemu 虚拟机了. 目的: 1. 了解我们的外设情况. 2. 为在guest中开发我们自己的linux PCI驱动程序做 ...

  5. 数组-Find Minimum in Rotated Sorted Array

    排序数组在旋转后,可以分为前后两个排序子序列.在没有相同元素的情况下,前一个数组中的元素均大于后一个数组中的元素. 如果我们要找最小元素,则只要找到两个数组的分界点即可,即第二个子序列的开始元素. 由 ...

  6. A Simple Problem with Integers(线段树,区间更新)

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 83822   ...

  7. EasyUI中datagrid实现显示、增加、 删除、 修改、 查询操作(后台代码C#)

    菜鸟进入,高手请绕道! +++++++++++++++++++++++++++++++++++++++ 一.数据的显示 1新建HtmlPage2.html页面,引入相关文件.如下所示 <scri ...

  8. 列表的实现-----数据结构与算法JavaScript描述 第三章

    实现一个列表 script var booklist = new List(); booklist.append('jsbook'); booklist.append('cssbook'); book ...

  9. 你应该知道CSS选择器技巧

    什么是:before和:after? 该如何使用他们? :before是css中的一种伪元素,可用于在某个元素之前插入某些内容. :after是css中的一种伪元素,可用于在某个元素之后插入某些内容. ...

  10. SQL Convert XML to Table

    将xml nodes 属性中的值 转为table 形式 declare @xml2 xml set @xml2 = '<CMADatas> <CMAData CmaName=&quo ...