'/////////////////////////////////////////////////////////////////////
'//名称: SendData
'//功能: send command to computer
'//入口: COMMAND, Computer, SendTime
'//出口:
'//返回值:
' 0: failue
' 1: success
'/////////////////////////////////////////////////////////////////////
Public Function SendData(Command As Long, Computer As String, _
SendTime As Date, Optional Flag As Long) As Long
Dim mskSend As HHMsgSock
Dim sDataSend As String
If Flag = 0 Then
mskSend.RoomComputer = Computer
mskSend.SendCommand = Command
mskSend.SendDirection = HH_WATCH
mskSend.SendTime = SendTime
' If Command < 50 Then 'resend data
' If Command <> 5 Then
' frmMain.mRetryTimes = 2
' frmMain.tmrReSend.Enabled = True
' End If
' End If
Else
sDataSend = gstrLastSend
End If
sockClient.RemoteHost = "255.255.255.255"
sockClient.RemotePort = PORTWATCH
On Error GoTo ErrHandle
sockClient.SendData sDataSend
On Error GoTo 0
SendData = 1
Exit Function
ErrHandle:
If Err.Number = 126 Then
Resume Next
Else
MsgBox Err.Number & Err.Description
End If
function MakeSockAddrIn(IP:String;Port:String;proto:String):TSockAddrIn;
begin
Result.sin_family:=AF_INET;
Result.sin_port := WSocket_htons(WSocketResolvePort(Port,proto));
Result.sin_addr.s_addr := WSocketResolveHost(IP).s_addr;
end;
procedure Send;
var
Dest:TSockAddrIn;
begin
Dest:=MakeSockAddrIn('255.255.255.255',port,'udp');
ClientWSocket.SendTo(Dest,sizeof(Dest),@SendBuffer,Len);
end;