回复 5# solo_k
以前收藏的。
服务端:Local $szIPADDRESS = @IPAddress1;你的公共IP地址
Local $nPORT = 33891;端口
Local $MainSocket, $GOOEY, $edit, $ConnectedSocket, $szIP_Accepted
Local $msg, $recv
TCPStartup()
$MainSocket = TCPListen($szIPADDRESS, $nPORT)
$GOOEY = GUICreate("My Server (IP: " & $szIPADDRESS & ")", 300, 200)
$edit = GUICtrlCreateEdit("", 10, 10, 280, 180)
GUISetState()
$ConnectedSocket = -1
Do
$ConnectedSocket = TCPAccept($MainSocket)
Until $ConnectedSocket <> -1
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
$recv = TCPRecv($ConnectedSocket, 2048)
If @error Then ExitLoop
If $recv <> "" Then GUICtrlSetData($edit, $recv & @CRLF & GUICtrlRead($edit))
WEnd
If $ConnectedSocket <> -1 Then TCPCloseSocket($ConnectedSocket)
TCPShutdown()
客户端:Local $ConnectedSocket, $szData
Local $szIPADDRESS = @IPAddress1
Local $nPORT = 33891
TCPStartup()
$ConnectedSocket = -1
$ConnectedSocket = TCPConnect($szIPADDRESS, $nPORT)
If @error Then
MsgBox(4112, "错误", "TCP连接失败,服务端未启用!错误代码: " & @error)
Else
While 1
$szData = InputBox("发送数据给服务端", @LF & @LF & "输入一个要发送给服务端的数据:")
If @error Or $szData = "" Then ExitLoop
TCPSend($ConnectedSocket, $szData)
If @error Then ExitLoop
WEnd
EndIf
|