Created
September 6, 2010 03:08
-
-
Save huacnlee/566590 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
procedure TForm1.UDPUDPRead(Sender: TObject; AData: TStream; | |
ABinding: TIdSocketHandle); | |
var | |
iType: Integer; | |
pBuf: Pointer; | |
str: String; | |
buf: array[0..8191] of char; | |
begin | |
pBuf := AllocMem(AData.Size); | |
try | |
AData.ReadBuffer(pBuf^, AData.Size); | |
iType := 0; | |
CopyMemory(@iType, pBuf, 4); | |
if iType <> 1001 then Exit; | |
SetLength(str, AData.Size-4); | |
CopyMemory(@str[1], Pointer(DWORD(pBuf)+4), AData.Size-4); | |
Memo1.Lines.Add(ABinding.PeerIP+' '+ IntToStr(ABinding.PeerPort)+':'+str); | |
UDP.Send(ABinding.PeerIP, ABinding.PeerPort, '接收消息成功!'); | |
finally | |
FreeMem(pBuf); | |
end; | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment