下载

0下载券

加入VIP
  • 专属下载特权
  • 现金文档折扣购买
  • VIP免费专区
  • 千万文档免费下载

上传资料

关闭

关闭

关闭

封号提示

内容

首页 Delphi UDP聊天软件实例

Delphi UDP聊天软件实例.doc

Delphi UDP聊天软件实例

tian相吉
2017-11-10 0人阅读 举报 0 0 0 暂无简介

简介:本文档为《Delphi UDP聊天软件实例doc》,可适用于综合领域

DelphiUDP聊天软件实例:使用IdUDPClient与IDUDPServer,例子如下:服端:务务务unitUDPServerMaininterfaceuses{$IFDEFLinux}QGraphics,QControls,QForms,QDialogs,QStdCtrls,{$ELSE}windows,messages,graphics,controls,forms,dialogs,IdWinsock,stdctrls,{$ENDIF}SysUtils,Classes,IdBaseComponent,IdAntiFreezeBase,IdAntiFreeze,IdComponent,IdUDPBase,IdUDPClient,IdStack,IdUDPServer,IdSocketHandletypeTUDPMainForm=class(TForm)SourceGroupBox:TGroupBoxHostNameLabel:TLabelHostAddressLabel:TLabelHostName:TLabelHostAddress:TLabelUDPServer:TIdUDPServerUDPAntiFreeze:TIdAntiFreezePortLabel:TLabelPort:TLabelBufferSizeLabel:TLabelBufferSize:TLabelUDPMemo:TMemoprocedureFormCreate(Sender:TObject)procedureUDPServerUDPRead(Sender:TObjectAData:TStreamABinding:TIdSocketHandle)private{Privatedeclarations}public{Publicdeclarations}endvarUDPMainForm:TUDPMainFormimplementationconstHOSTNAMELENGTH={$IFDEFMSWINDOWS}{$R*dfm}{$ELSE}{$R*xfm}{$ENDIF}procedureTUDPMainFormFormCreate(Sender:TObject)beginHostNameCaption:=UDPServerLocalNameHostAddressCaption:=GStackLocalAddressPortCaption:=IntToStr(UDPServerDefaultPort)BufferSizeCaption:=IntToStr(UDPServerBufferSize)UDPServerActive:=TrueendprocedureTUDPMainFormUDPServerUDPRead(Sender:TObjectAData:TStreamABinding:TIdSocketHandle)varDataStringStream:TStringStreams:StringbeginDataStringStream:=TStringStreamCreate('')tryDataStringStreamCopyFrom(AData,ADataSize)UDPMemoLinesAdd('Received"'DataStringStreamDataString'"from'ABindingPeerIP'onport'IntToStr(ABindingPeerPort))s:='Repliedfrom'UDPServerLocalName'to"'DataStringStreamDataString'"'ABindingSendTo(ABindingPeerIP,ABindingPeerPort,s,Length(s))finallyDataStringStreamFreeendendend客端:务务务unitUDPClientMaininterfaceuses{$IFDEFLinux}QGraphics,QControls,QForms,QDialogs,QStdCtrls,{$ELSE}windows,messages,graphics,controls,forms,dialogs,IdWinsock,stdctrls,{$ENDIF}SysUtils,Classes,IdBaseComponent,IdAntiFreezeBase,IdAntiFreeze,IdComponent,IdUDPBase,IdUDPClient,IdStacktypeTUDPMainForm=class(TForm)SourceGroupBox:TGroupBoxHostNameLabel:TLabelHostAddressLabel:TLabelHostName:TLabelHostAddress:TLabelUDPAntiFreeze:TIdAntiFreezePortLabel:TLabelPort:TLabelDestinationLabel:TLabelDestinationAddress:TLabelBufferSizeLabel:TLabelBufferSize:TLabelUDPMemo:TMemoSendButton:TButtonUDPClient:TIdUDPClientprocedureFormCreate(Sender:TObject)procedureSendButtonClick(Sender:TObject)private{Privatedeclarations}public{Publicdeclarations}endvarUDPMainForm:TUDPMainFormimplementationconstHOSTNAMELENGTH=RECIEVETIMEOUT=milliseconds{$IFDEFMSWINDOWS}{$R*dfm}{$ELSE}{$R*xfm}{$ENDIF}procedureTUDPMainFormFormCreate(Sender:TObject)beginRandomizeremoveifyouwantreproducibleresultsHostNameCaption:=UDPClientLocalNameHostAddressCaption:=GStackLocalAddressPortCaption:=IntToStr(UDPClientPort)DestinationAddressCaption:=UDPClientHostBufferSizeCaption:=IntToStr(UDPClientBufferSize)UDPClientReceiveTimeout:=RECIEVETIMEOUTendprocedureTUDPMainFormSendButtonClick(Sender:TObject)varMessageID:IntegerThisMessage:StringReceivedString:StringbeginMessageID:=Random(MAXINT)ThisMessage:='Message:'IntToStr(MessageID)UDPMemoLinesAdd('Sending'ThisMessage)UDPClientSend(ThisMessage)ReceivedString:=UDPClientReceiveString()ifReceivedString=''thenUDPMemoLinesAdd('Noresponsereceivedfromtheserverafter'IntToStr(UDPClientReceiveTimeout)'millseconds')elseUDPMemoLinesAdd('Received:'ReceivedString)endend

用户评价(0)

关闭

新课改视野下建构高中语文教学实验成果报告(32KB)

抱歉,积分不足下载失败,请稍后再试!

提示

试读已结束,如需要继续阅读或者下载,敬请购买!

评分:

/6

VIP

在线
客服

免费
邮箱

爱问共享资料服务号

扫描关注领取更多福利