本帖最后由 huoqingpo 于 2012-10-9 18:17 编辑
服务端#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
Global $MainSocket, $rAccept, $simage, $recv
Global $ipadd =IniRead (@ScriptDir&"\server.ini", "服务端", "ip", "" ), $port = IniRead (@ScriptDir&"\server.ini", "服务端", "端口", "" )
Global $ConnectedSocket = -1
TCPStartup()
$MainSocket = TCPListen($ipadd, $port, 100)
If $MainSocket = -1 Then Exit
#region ### START Koda GUI section ### Form=
_GUICtrlListView_SetColumnWidth($ListView1,100,50)
GUICtrlSendMsg($ListView1, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
$listMenu = GUICtrlCreateContextMenu($ListView1)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
Do
$ConnectedSocket = TCPAccept($MainSocket)
Until $ConnectedSocket <> -1
While 1
_recv()
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func _recv()
$recv = TCPRecv($ConnectedSocket, 2048)
If $recv <> "" Then
GUICtrlCreateListViewItem($recv, $ListView1)
FileWrite (@ScriptDir&"\log.txt",@CRLF&$recv)
EndIf
EndFunc
问题1 服务端运行后,无法关闭。必须客户端连接后才能关闭。
问题2 只能一个客户端连接到服务端。不能实现多个客户端同时连接到服务端。
给帮忙看下服务端该怎么修改下啊 |