0
0

TCP监听

Au3编程学习2022-10-05 11:04重庆
3380
服务端
#AccAu3Wrapper_UseX64=n
#include <FileConstants.au3>
#include <StaticConstants.au3>
#include <WinAPIEx.au3>
#include <AutoItConstants.au3>
#include <GUIConstantsEx.au3>
#include <array.au3>
#include <TrayConstants.au3>
#include <winapi.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <WinAPIFiles.au3>
#include <GuiListView.au3>
_WinAPI_Wow64EnableWow64FsRedirection(False)

Local $sIPAddress =''192.168.1.2'
Local $TCPPort= 8411
Local $mht = GUICreate("", 290, 322)
TCPStartup()
Local $iExWindowStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE)
Local $iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER)
Local $ListView3 = GUICtrlCreateListView("", 5, 10, 280, 310, -1, $iExWindowStyle)
_GUICtrlListView_SetExtendedListViewStyle($ListView3, $iExListViewStyle)
_GUICtrlListView_AddColumn($ListView3, "", 0)
_GUICtrlListView_AddColumn($ListView3, "Socket", 0)
_GUICtrlListView_AddColumn($ListView3, "序号", 40,2)
_GUICtrlListView_AddColumn($ListView3, "客户机名称", 116,2)
_GUICtrlListView_AddColumn($ListView3, "客户机 IP", 116,2)
GUICtrlSetFont(-1, 10, 400, 1, "微软雅黑")

GUISetState(@SW_SHOW, $mht)
_JT()

Func _JT()
While 1
        _While()
WEnd
EndFunc ;===>_JT

Func _While()
        Dim $msg = GUIGetMsg()
        Switch $msg
                Case $GUI_EVENT_CLOSE
                        Quit()
Local $iListenSocket = TCPListen($sIPAddress, $TCPPort)
Return False
Local $iSocket = 0
Do
$iSocket = TCPAccept($iListenSocket)
If @error Then
$iError = @error
Return False
EndIf
Until $iSocket <> -1
TCPCloseSocket($iListenSocket)
TCPCloseSocket($iSocket)
        EndSwitch
EndFunc   ;==>_While

Func Quit()
TCPShutdown()
Exit
EndFunc   ;==>Quit()
客户端
#include <MsgBoxConstants.au3>
Local $sIPAddress = '192.168.1.2'
Local $TCPPort = 8441
_start()

Func _start()
TCPStartup()

Local $iSocket = TCPConnect($sIPAddress, $TCPPort)
If @error Then
Local $iError = @error
MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Could not connect, Error code: " & $iError)
Return False
Else
MsgBox($MB_SYSTEMMODAL, "", "Connection successful")
EndIf
TCPCloseSocket($iSocket)
EndFunc   ;==>_start()


客户端边不上服务端,客户端用NetAssist.exe  能连上

全部回复 0
www8899

主题: 54

回复: 171

关注: 0

粉丝: 2

TA 的积分
  • 1744
  • 84
  • 0