个人网站: www.7dtest.com 7点测试群:(61369656)------(77273408)------(35710365)------(9410090)

autoIT3 help中的一个问题

上一篇 / 下一篇  2008-07-24 22:31:10 / 个人分类:Zee的生活

看下面的代码是帮助里的TCPRecv,尝试运行它,会出来一个对话框,这段代码的意思就是打开一个监听端口,接受字符,然后输出到窗口里。
但是,我们可以运行它看到这个窗口出现,如果我们发数据到这个端口就会发现,窗口很快就关闭了,并且,在编辑器的输出里看到了这一段:
引用:
"long_ptr", "int_ptr" and "short_ptr" DllCall() types have been deprecated.  Use "long*", "int*" and "short*" instead.:
Local $aRet = DLLCall("Ws2_32.dll","int","getpeername","int",$SHOCKET, "Ptr",DLLStructGetPtr($sockaddr),"int_ptr",DLLStructGetSize($sockaddr))
意思很明显了,类型不匹配。
然后把语句中的int_ptr改成int.看下面我标红的那个位置。
再运行,就可以接收到字符并打印出来了。



有兴趣的可以自己改改。

不知道这是不是一个文档BUG?
引用:
;SERVER!! Start Me First !!!!!!!!!!!!!!!
#include <GUIConstants.au3>

; Set Some reusable info
; Set your Public IP address (@IPAddress1) here.
Dim $szIPADDRESS = @IPAddress1
Dim $nPORT = 33891


; Start The TCP Services
;==============================================
TCPStartUp()

; Create a Listening "SOCKET".
;   Using your IP Address and Port 33891.
;==============================================
$MainSocket = TCPListen($szIPADDRESS, $nPORT)

; If the Socket creation fails, exit.
If $MainSocket = -1 Then Exit


; Create a GUI for messages
;==============================================
Dim $GOOEY = GUICreate("My Server (IP: " & $szIPADDRESS & ")",300,200)
Dim $edit = GUICtrlCreateEdit("",10,10,280,180)
GUISetState()


; Initialize a variable to represent a connection
;==============================================
Dim $ConnectedSocket = -1


;Wait for and Accept a connection
;==============================================
Do
    $ConnectedSocket = TCPAccept($MainSocket)
Until $ConnectedSocket <> -1


; Get IP of client connecting
Dim $szIP_Accepted = SocketToIP($ConnectedSocket)

Dim $msg, $recv
; GUI Message Loop
;==============================================
While 1
   $msg = GUIGetMsg()

; GUI Closed
;--------------------
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop

; Try to receive (up to) 2048 bytes
;----------------------------------------------------------------
    $recv = TCPRecv( $ConnectedSocket, 2048 )
   
; If the receive failed with @error then the socket has disconnected
;----------------------------------------------------------------
    If @error Then ExitLoop

; Update the edit control with what we have received
;----------------------------------------------------------------
    If $recv <> "" Then GUICtrlSetData($edit, _
            $szIP_Accepted & " > " & $recv & @CRLF & GUICtrlRead($edit))
WEnd


If $ConnectedSocket <> -1 Then TCPCloseSocket( $ConnectedSocket )

TCPShutDown()


; Function to return IP Address from a connected socket.
;----------------------------------------------------------------------
Func SocketToIP($SHOCKET)
    Local $sockaddr = DLLStructCreate("short;ushort;uint;char[8]")

    Local $aRet = DLLCall("Ws2_32.dll","int","getpeername","int",$SHOCKET, _
            "ptr",DLLStructGetPtr($sockaddr),"int_ptr",DLLStructGetSize($sockaddr))
    If Not @error And $aRet[0] = 0 Then
        $aRet = DLLCall("Ws2_32.dll","str","inet_ntoa","int",DLLStructGetData($sockaddr,3))
        If Not @error Then $aRet = $aRet[0]
    Else
        $aRet = 0
    EndIf

    $sockaddr = 0

    Return $aRet
EndFunc

TAG: Zee的生活

 

评分:0

我来说两句

我的栏目

日历

« 2024-04-18  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 157890
  • 日志数: 146
  • 图片数: 1
  • 建立时间: 2006-12-05
  • 更新时间: 2012-11-16

RSS订阅

Open Toolbar