สองฟังชั่นนี้คืออยู่ในหน้าของ Server ครับ Code (VB.NET)
#Region "Server Code"
Public Sub btnStopServe_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStopServe.Click
If Server Is Nothing Then
Exit Sub
Else
If ServerOn = False Then
Exit Sub
Else
Server.stopListen(True)
serverLogMessage("No longer serving.")
ServerOn = False
port50 = 0
End If
End If
End Sub
Public Sub btnServe_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnServe.Click
If Server Is Nothing Then
Server = New socketServer()
port50 = 1
Else
If ServerOn = False Then
port50 = 1
Server = New socketServer()
Else
Exit Sub
End If
End If
ServerOn = True
AddHandler Server.IncomingData, AddressOf handleServerIncomingData
AddHandler Server.Connected, AddressOf handleServerConnected
AddHandler Server.ConnectionError, AddressOf handleServerConnectionError
AddHandler Server.ConnectionRefused, AddressOf handleServerConnectionRefused
AddHandler Server.Disconnected, AddressOf handleServerDisconnected
AddHandler Server.DisconnectError, AddressOf handleServerDisconnectError
AddHandler Server.IncomingDataError, AddressOf handleServerIncomingDataError
AddHandler Server.ListenError, AddressOf handleServerListenError
AddHandler Server.SendDataError, AddressOf handleServerSendDataError
ReDim InUse(63)
Server.Listen(64, txtServePort.Text)
serverLogMessage("Now serving.")
End Sub
#End Region
ส่วนของ Form ที่จะเรียกใช้ Code (VB.NET)
Private Sub st0_Click(sender As Object, e As EventArgs) Handles st0.Click
frm9050.btnStopServe_Click(sender, e)
chkSts()
End Sub