662
社区成员
发帖
与我相关
我的任务
分享
结构体定义:
type icmp_echo_reply from structure
unsignedlong address
unsignedlong status
unsignedlong roundtriptime
unsignedlong datasize
unsignedlong reserved[3]
character data[]
end type
API 声明:
Function ulong FormatMessage( &
ulong dwFlags, &
ulong lpSource, &
ulong dwMessageId, &
ulong dwLanguageId, &
Ref string lpBuffer, &
ulong nSize, &
ulong Arguments &
) Library "kernel32.dll" Alias For "FormatMessageW"
Function ulong GetLastError() Library "kernel32.dll"
Function ulong inet_addr(string cp) Library "ws2_32.dll" Alias for "inet_addr;Ansi"
Function ulong IcmpCreateFile() Library "icmp.dll"
Function long IcmpSendEcho ( &
ulong IcmpHandle, &
ulong DestinationAddress, &
string RequestData, &
long RequestSize, &
long RequestOptions, &
Ref icmp_echo_reply ReplyBuffer, &
long ReplySize, &
long Timeout &
) Library "icmp.dll" Alias for "IcmpSendEcho"
Function long IcmpCloseHandle(ulong IcmpHandle) Library "icmp.dll"
// -----------------------------------------------------------------------------
// FUNCTION: n_ping.of_FormatMessage
//
// PURPOSE: This function returns the message text for
// the given system error code.
//
// ARGUMENTS: aul_error - Error code
//
// RETURN: Message text
//
// DATE PROG/ID DESCRIPTION OF CHANGE / REASON
// ---------- -------- -----------------------------------------------------
// 03/23/2004 RolandS Initial coding
// -----------------------------------------------------------------------------
Constant ULong FORMAT_MESSAGE_FROM_SYSTEM = 4096
Constant ULong LANG_NEUTRAL = 0
String ls_buffer, ls_errmsg
ls_buffer = Space(200)
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, &
aul_error, LANG_NEUTRAL, ls_buffer, 200, 0)
ls_errmsg = "Error# " + String(aul_error) + "~r~n~r~n" + ls_buffer
Return ls_errmsg
// -----------------------------------------------------------------------------
// FUNCTION: n_ping.of_WSAGetLastError
//
// PURPOSE: This function returns the message text for
// the most recent Winsock error.
//
// RETURN: Counter value
//
// DATE PROG/ID DESCRIPTION OF CHANGE / REASON
// ---------- -------- -----------------------------------------------------
// 03/23/2004 RolandS Initial coding
// -----------------------------------------------------------------------------
ULong lul_error
String ls_errmsg
lul_error = WSAGetLastError()
If lul_error = 0 Then
ls_errmsg = "An unknown error has occurred!"
Else
ls_errmsg = of_FormatMessage(lul_error)
End If
Return ls_errmsg
// -----------------------------------------------------------------------------
// FUNCTION: n_ping.of_Ping
//
// PURPOSE: This function performs a 'ping' against the
// server at the specified IP address.
//
// ARGUMENTS: as_ipaddress - IP address of the server
// as_echomsg - The text to send to server
//
// RETURN: True = Success, False = Failed
//
// DATE PROG/ID DESCRIPTION OF CHANGE / REASON
// ---------- -------- -----------------------------------------------------
// 03/23/2004 RolandS Initial coding
// -----------------------------------------------------------------------------
ULong lul_address, lul_handle
Long ll_rc, ll_size
String ls_errmsg, ls_reply
icmp_echo_reply lstr_reply
lul_address = inet_addr(as_ipaddress)
If lul_address > 0 Then
lstr_reply.Data[Len(as_echomsg)] = ""
lul_handle = IcmpCreateFile()
ll_size = Len(as_echomsg) * 2
ll_rc = IcmpSendEcho(lul_handle, lul_address, &
as_echomsg, ll_size, 0, &
lstr_reply, 28 + ll_size, il_timeout)
IcmpCloseHandle(lul_handle)
If ll_rc = 0 Then
ls_errmsg = of_WSAGetLastError()
MessageBox( "Send Echo Error in of_Ping", &
ls_errmsg, StopSign!)
Else
If lstr_reply.Status = 0 Then
ls_reply = String(lstr_reply.Data)
If ls_reply = as_echomsg Then
Return True
Else
ls_errmsg = "The returned string is different:~r~n~r~n"
ls_errmsg += "Sent: " + as_echomsg + "~r~n"
ls_errmsg += "Recv: " + ls_reply
MessageBox( "Echo Error in of_Ping", &
ls_errmsg, StopSign!)
End If
Else
ls_errmsg = of_FormatMessage(lstr_reply.Status)
MessageBox( "Echo Status Error in of_Ping", &
ls_errmsg, StopSign!)
End If
End If
Else
ls_errmsg = "The given IP Address is invalid!"
MessageBox( "Winsock Error in of_Ping", &
ls_errmsg, StopSign!)
End If
Return False
// -----------------------------------------------------------------------------
// FUNCTION: n_ping.of_Ping
//
// PURPOSE: This function provides a default echo string
// to the main of_Ping function.
//
// ARGUMENTS: as_ipaddress - IP address of the server
//
// RETURN: True = Success, False = Failed
//
// DATE PROG/ID DESCRIPTION OF CHANGE / REASON
// ---------- -------- -----------------------------------------------------
// 03/23/2004 RolandS Initial coding
// -----------------------------------------------------------------------------
String ls_echomsg
ls_echomsg = "abcdefghijklmnopqrstuvwxyz"
Return of_Ping(as_ipaddress, ls_echomsg)
l1=conn.setoptions( 'Timeout=2')
l2=conn.setproxyserveroptions("address='http://192.168.22.61/x.asmx'")
rc = conn.createinstance(obj,"x1Soap")
try
//如何超时退出?如何捕获错误?
id=obj.getGuestInfo( '2010-12-16', 'CZ378', '109')
catch ( exception e )
messagebox("error",e.text )
finally
destroy conn
end try