加了一个输入IP回复,服务端一直发不出去消息,不知道问题在那儿,现在只是在测试回复一个,其实与选择回复都一样效果了,一个能做到其它都能做到!
#AutoIt3Wrapper_Icon=ico.ico ;需要使用的图标(路径)名称
#AutoIt3Wrapper_OutFile=TCP服务端.exe ;目标 exe/a3x 文件名.
HotKeySet("{ENTER}","_send")
#include <GUIConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
;$File="配置.ini"
;$ip=IniRead($File,"配置","服务器地址","")
$Dll = DllOpen(@ScriptDir & "\Skin\SkinCrafterDll.dll")
$skinTemp=iniread($File,"配置","皮肤","")
$skin="\skin\"&$skinTemp
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("【飛翔網絡】局域网聊天软件 Server", 291, 208, 192, 114)
_SkinGUI(@ScriptDir & "\Skin\SkinCrafterDll.dll", @ScriptDir & "\"&$skin, $Form1)
GUISetOnEvent($GUI_EVENT_CLOSE, "_ext")
$Edit0 = GUICtrlCreateEdit("历史消息:"&"本机用户名→"&@ComputerName, 8, 8, 273, 18, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_CLIPSIBLINGS,$ES_READONLY))
GUICtrlCreateLabel("请输入IP",8,152)
$Edit1 = GUICtrlCreateEdit("", 8, 28, 273, 116, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_CLIPSIBLINGS,$ES_READONLY,$ws_VSCROLL))
$Edit3 = GUICtrlCreateInput("", 63,148,30,20,$ES_NUMBER );IP地址
$Edit2 = GUICtrlCreateEdit("", 92, 148, 189, 20, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_CLIPSIBLINGS))
GUICtrlSetData(-1, "")
$Button1 = GUICtrlCreateButton("发送[&Enter]", 8, 176, 113, 25, 0)
GUICtrlSetOnEvent(-1, "_send")
$Button2 = GUICtrlCreateButton("退出[&Esc]", 168, 176, 113, 25, 0)
GUICtrlSetOnEvent(-1, "_ext")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
;----------------------------------
Global $aConnected[1] = [0]
TCPStartUp()
$MainSocket = TCPListen(@IPAddress1, 65432, 100 )
If $MainSocket = -1 Then Exit ;创建监听不成功就退出
$Socket = -1
While 1
Accept()
Recv()
Sleep(100)
Wend
Func _ext()
TCPCloseSocket($Socket)
TCPShutdown ( )
Exit
EndFunc
Func _send()
$szData = @ComputerName&">"&GUICtrlRead($Edit2)
$bj="本机发送:"&GUICtrlRead($Edit2)
$Edit=GUICtrlRead($Edit2)
If $Edit = "" Then
MsgBox(0,"提示","消息不能为空!",1) ;延时5秒自动退出
Else
$MainSocket = TCPListen(@IPAddress1, 65432, 100 )
$fs=TCPConnect($ip,65432)
$iph="192.168.0."&guictrlread($Edit3);读取IP号,用来做回复客户机用!
$szData1 = StringToBinary($szData, 4)
TCPSend($Socket,$szData1) ;发送信息
GUICtrlSetData($edit1, $bj& @CRLF &GUICtrlRead($edit1))
GUICtrlSetData($Edit2, "")
EndIf
If @error Then MsgBox(0,"提示","消息发送失败!",1) ;延时5秒自动退出
EndFunc
Func _SkinGUI($SkincrafterDll, $SkincrafterSkin, $Handle)
$Dll = DllOpen($SkincrafterDll)
DllCall($Dll, "int:cdecl", "InitLicenKeys", "wstr", "1", "wstr", "", "wstr", "1@1.com", "wstr", "1")
DllCall($Dll, "int:cdecl", "InitDecoration", "int", 1)
DllCall($Dll, "int:cdecl", "LoadSkinFromFile", "wstr", $SkincrafterSkin)
DllCall($Dll, "int:cdecl", "DecorateAs", "int", $Handle, "int", 25)
DllCall($Dll, "int:cdecl", "ApplySkin")
EndFunc ;==>_SkinGUI
Func Accept()
$ConnectedSocket = TCPAccept($MainSocket)
If $ConnectedSocket <> -1 Then
_ArrayAdd($aConnected, $ConnectedSocket)
$aConnected[0] += 1
EndIf
Return
EndFunc
Func Recv()
$i = 1
While $i <= UBound($aConnected) - 1
$sRecv = TCPRecv($aConnected[$i], 2048, 1);256)
If @error Then ; 客户端已关闭
_ArrayDelete($aConnected, $i)
$aConnected[0] -= 1
ElseIf $sRecv = "" Then ; 客户端未发送数据,继续处理下一客户端
$i += 1
Else
$srecv = BinaryToString($srecv, 4)
GUICtrlSetData($edit1, $srecv & @CRLF & GUICtrlRead($edit1))
; 接收数据处理。完成后TCPCloseSocket,然后删除数组单元并将 $aConnected[0] -= 1
EndIf
WEnd
Return
EndFunc
|