谁有两台机子对发信息的源码?
谁有两台机子对发信息的源码?:face (37): 本人想拿来研究做网吧聊天 帮助里有。。。 ;服务器的源码;---------------------------------
#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$AForm1 = GUICreate("Server", 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 ###
;----------------------------------
TCPStartUp()
$MainSocket = TCPListen(@IPAddress1, 65432,100 )
If $MainSocket = -1 ThenExit ;创建监听不成功就退出
$Socket = -1
;当接受成功后(默认的错误返回值为-1,成功时值不为-1) 再执行后面的语句
Do
$Socket = TCPAccept($MainSocket);尝试接受一个套接字连接
Until $Socket() <> -1 ;条件为真就退出循环
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 ;客户机源码
;----------------------------------
#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 通发信息,不完善,你要是能完善一下的话就发个给我,一起学习
页:
[1]