如何知道UDPServerUDPRead所收到的訊息是來自Broadcast |
尚未結案
|
rain299799
一般會員 ![]() ![]() 發表:1 回覆:0 積分:0 註冊:2004-09-27 發送簡訊給我 |
我是認為GetSockOpt可以用來解決這個問題,check optval 的value(in debug mode),假如是"True"那麼就是Broadcast,但一直try不出來.因為optval的value 一直是"False".為什麼? 煩請眾前輩們幫幫忙.謝謝!
procedure TfrmMain.UDPServerUDPRead(Sender: TObject; AData: TStream; ABinding: TIdSocketHandle); var DataStringStream: TStringStream; s: String; optval: Boolean; begin DataStringStream := TStringStream.Create(''); try DataStringStream.CopyFrom(AData, AData.Size); ABinding.GetSockOpt(Id_SOL_SOCKET, Id_SO_BROADCAST, PChar(@optval), sizeof(optval)); lbResult.Items.Append('Received "' DataStringStream.DataString '" from ' ABinding.PeerIP ' on port ' IntToStr(ABinding.PeerPort)); s := 'Replied from ' UDPServer.LocalName ' to "' DataStringStream.DataString '"'; ABinding.SendTo(ABinding.PeerIP, ABinding.PeerPort, s[1], Length(s)); finally DataStringStream.Free; end; end; procedure TfrmMain.UDPSendMessage; var ThisMessage: String; ReceivedString: String; begin ThisMessage := 'Message: ' edMsg.Text; if edIP.Text <> '' then begin UDPClient.Host := edIP.Text; UDPClient.Port := StrToInt(edPort.Text); UDPClient.Send(ThisMessage); end else begin UDPClient.Broadcast(ThisMessage, StrToInt(edPort.Text)); end; ThisMessage := 'Message: ' edMsg.Text; lbResult.Items.Append('Sending ' ThisMessage); ReceivedString := UDPClient.ReceiveString(); if ReceivedString = '' then lbResult.Items.Append('No response received from the Server after ' IntToStr(UDPClient.ReceiveTimeout) ' millseconds.') else lbResult.Items.Append('Received: ' ReceivedString) end;發表人 - rain299799 於 2004/09/27 16:25:33 |
Ktop_Robot
站務副站長 ![]() ![]() 發表:0 回覆:3511 積分:0 註冊:2007-04-17 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |