异常断开后会发生Error事件, 在Error事件中判断它的状态是否已经断开, 如果断开则使它处于监听状态 if winsock1.State <> sckClosed then winsock1.Listen end if你试试吧.
噢, 写错了:) 应该这样判断: if winsock1.State = sckClosed then
架构错误 1、应该是监听和处理分开处理 2、建立一个sock只负责监听,建立一个sock组负责处理 3、当监听sock获得一个连接请求在sock组中查找空闲的sock,然后让他处理这个连接,如果没有空闲的就返回out of max connection.
按楼上的方法试了,timer2的间隔是50秒,还是出错 错误提示 "操作完成,进行中没有分快操作", Private Sub Command1_Click() WskServer(0).Listen Timer2.Enabled = False End SubPrivate Sub WskServer_Error(Index As Integer, ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean) If Winsock(0).State = sckClosed Then Timer2.Enabled = True
'Winsock(0).Listen End If DstPath = "c:\bb.txt" Timer1.Enabled = True If Number <> 0 Then MsgBox Number End If End Sub
在Error事件中判断它的状态是否已经断开, 如果断开则使它处于监听状态
if winsock1.State <> sckClosed then
winsock1.Listen
end if你试试吧.
应该这样判断:
if winsock1.State = sckClosed then
1、应该是监听和处理分开处理
2、建立一个sock只负责监听,建立一个sock组负责处理
3、当监听sock获得一个连接请求在sock组中查找空闲的sock,然后让他处理这个连接,如果没有空闲的就返回out of max connection.
错误提示
"操作完成,进行中没有分快操作",
Private Sub Command1_Click()
WskServer(0).Listen
Timer2.Enabled = False
End SubPrivate Sub WskServer_Error(Index As Integer, ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean) If Winsock(0).State = sckClosed Then
Timer2.Enabled = True
'Winsock(0).Listen
End If
DstPath = "c:\bb.txt"
Timer1.Enabled = True
If Number <> 0 Then
MsgBox Number
End If
End Sub
我用数组做的,WskServer(0)为监听,Load WskServer(Index + 1)为处理监听连接,
可是当客户端退出时,或者由于连接异常中断时,服务器端能否自动处于"监听"状态呢?而不是重新启动?
只需要判断客户端请求有没有空闲的WskServer来处理