你好:

     感谢你访问我的 Blog ,本博客只提供博主的技术经验分享,你可以在此做简单的留言和评论,我会抽空回复你;若是要深入交流探讨,请联系QQ:47853253或者加QQ群:12012081


 

【Au3】脚本—简单的聊天程序—tcp通讯原理

 #Region ;**** 参数创建于 ACNWrapper_GUI ****

#AutoIt3Wrapper_icon=..\..\..\tools\高清ICO\letters.ico
#AutoIt3Wrapper_Res_File_Add=("gs.bmp","")
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#cs ____________________________________
Au3 版本: 汉化版本 1.76
脚本作者: 思想在祼奔
网站支持: http://wdqq.f3322.net/
Email:    47853253@qq.com
QQ/TM:    47853253
脚本编号: ip设置程序
#ce ____________________________________
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiIPAddress.au3>
#include <Process.au3>
#include <StaticConstants.au3>
Opt("TrayMenuMode", 3) ; 默认菜单项目 (脚本暂停中/退出)(Script Paused/Exit) 将不会显示,并且所选项目不能被选中(checkbox不会打勾) . 请参考TrayMenuMode选项1和2(3=1+2).
$aboutitem    = TrayCreateItem("关于")
TrayCreateItem("")
$exititem = TrayCreateItem("退出")
TraySetState()
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("简单的聊天程序__By__QQ:47853253", 473, 469, 433, 230)
$Edit1 = GUICtrlCreateList("", 0, 142, 465, 217)
GUICtrlSetData(-1, "")
$Input1 = GUICtrlCreateInput("", 8, 372, 457, 21)
$Button1 = GUICtrlCreateButton("发送消息", 384, 416, 75, 25, 0)
GUICtrlSetCursor (-1, 0)
$Button2 = GUICtrlCreateButton("远程关机", 192, 416, 75, 25, 0)
GUICtrlSetCursor (-1, 0)
$Button3 = GUICtrlCreateButton("退出", 16, 416, 75, 25, 0)
GUICtrlSetCursor (-1, 0)
$Button4 = GUICtrlCreateButton("武定彝岭电脑科技有限责任公司", 0, 0, 468, 100, $BS_BITMAP)
GUICtrlSetImage(-1, "gs.bmp", 0)
GUICtrlSetCursor (-1, 0)
;$Pic1 = GUICtrlCreatePic("gs.jpg", 0, 0, 468, 100, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
$IPAddress1 = _GUICtrlIpAddress_Create($Form1, 92, 112, 130, 21)
_GUICtrlIpAddress_Set($IPAddress1, "192.168.1.2")
$Label1 = GUICtrlCreateLabel("对方IP:", 36, 115, 50, 17)
$Label2 = GUICtrlCreateLabel("端口:", 300, 115, 40, 17)
$Input2 = GUICtrlCreateInput("12345", 350, 112, 50, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Global $sEndSocket
dim $ip1=@IPAddress1
;msgbox(0,"",$ip1)
;exit
$port1=12345
tcpstartup()
$socket=tcplisten($ip1,$port1)
$connectsocket = -1
$me="他说:"
$he="我说:"
Dim $AccelKeys[2][2]=[["{Enter}", $Input1], ["{Enter}", $Input1]]
GUISetAccelerators($AccelKeys)
While 1
if $connectsocket=-1 Then
$connectsocket=TCPAccept($socket)
EndIf
$recv=tcprecv($connectsocket,2048,1)
if $recv <> "" Then
Guictrlsetdata($edit1,$me & BinaryToString($recv,4) & @CRLF)
$connectsocket = -1
TCPCloseSocket($connectsocket)
EndIf
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE,$Button3
tcpclosesocket($connectsocket)
tcpshutdown()
Exit
case $Button1
$tmp1=GUICtrlRead($Input1)
if $tmp1 <> "" Then
_send(GUICtrlRead($Input1))
EndIf
guictrlsetdata($input1,"")  ;清空发送框数据
Case $Button2
_Send('shutdown6')
case $Button4
Run(@ProgramFilesDir & "\Internet Explorer\iexplore.exe wdqq.f3322.net")
case $input1
$tmp=GUICtrlRead($Input1)
if $tmp <> "" Then
_send(GUICtrlRead($Input1))
guictrlsetdata($input1,"")  ;清空发送框数据
EndIf
EndSwitch
   Local $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $aboutitem
            MsgBox(64, "关于", "简单的聊天程序__By__QQ:47853253")
        Case $msg = $exititem
            ExitLoop
    EndSelect
WEnd
Func _send($sData)
$ip2=_guictrlipaddress_get($IPAddress1)
$port2=guictrlread($Input2)
$sEndSocket=TCPConnect($ip2,$port2)
if @error Then
msgbox(0,"状态","无法与对方建立连接,请检查网络。")
Else
;if @error or $sData = "" Then
$sMsg = StringToBinary($sData, 4);转换数据用来发送
TCPSend($sEndSocket, $sMsg)
Guictrlsetdata($edit1,$he & $sData & @CRLF)
EndIf
;EndIf
EndFunc
 


文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags:
评论: 0 | 引用: 0 | 查看次数: 161
发表评论
你没有权限发表留言!