|
发表于 2009-3-17 21:47:15
|
显示全部楼层
;客户机源码
;----------------------------------
#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$AForm1 = GUICreate("Client", 282, 202, 294, 149)
GUISetOnEvent($GUI_EVENT_CLOSE, "_ext")
$Edit1 = GUICtrlCreateEdit("", 0, 0, 281, 161)
GUICtrlSetData(-1, "")
$Button1 = GUICtrlCreateButton("send", 32, 168, 73, 25, 0)
GUICtrlSetOnEvent(-1, "_send")
$Button2 = GUICtrlCreateButton("exit", 176, 168, 73, 25, 0)
GUICtrlSetOnEvent(-1, "_ext")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
;-------------------------------------------
$Server_IP = "192.168.1.72" ;设置服务器IP
TCPStartUp()
;-------------------------------------------
$Socket = TCPConnect( $Server_IP, 65432 ) ;创建一个套接字连接到已经存在的服务器
If $socket = -1 Then MsgBox(0,"提示","服务器连接失败!",5) ;延时5秒自动退出
;-------------------------------------------
While 1
$recv = TCPRecv( $Socket, 2048 ) ;接收内容
;把接收的内容放到文本框内
If $recv <> "" Then GUICtrlSetData($Edit1, GUICtrlRead($Edit1)& @CRLF & $recv )
Sleep (100)
WEnd
;-------------------------------------------
Func _ext()
TCPCloseSocket($Socket)
TCPShutdown ( )
Exit
EndFunc
;-------------------------------------------
Func _send()
$szData = GUICtrlRead($Edit1)
If $szData = "" Then
MsgBox(0,"提示","消息不能为空!",5) ;延时5秒自动退出
Else
TCPSend($Socket,$szData) ;发送信息
EndIf
If @error Then MsgBox(0,"提示","消息发送失败!",5) ;延时5秒自动退出
EndFunc |
|