|
code show as below:
Private Sub Command1_Click ()
If Command1.Caption = "Start service" Then
'txtip.Text = Winsock1.LocalPort
List1.AddItem Time&"Starting service"
On Error GoTo skip 'Note: If there is a communication program on the port, it will exit
sckListen.LocalPort = txtport.Text
sckListen.Listen
Command1.Caption = "Stop service"
List1.AddItem Time&"Service started successfully and is running ..."
Label3.Caption = "Server Status: Running"
Exit Sub
skip:
If Err.Number = 10048 Then
List1.AddItem Time&"Port is already occupied"
End If
Else
Command1.Caption = "Start service"
List1.AddItem Time&"Stop service"
sckListen.Close
List1.AddItem Time&"Successfully stopped service"
Label3.Caption = "Server Status: Stopped"
End If
End Sub
Private Sub Command2_Click ()
'Select directory
Dim strResFolder As String
strResFolder = BrowseForFolder (hWnd, "Please select a directory.")
If strResFolder = "" Then
'Call MsgBox ("You deselected the directory ...", vbExclamation)
Else
'Call MsgBox ("Directory"&strResFolder&"Selected!", VbExclamation)
txtml.Text = strResFolder
End If
End Sub
Private Sub Command3_Click ()
i = WriteIni ("server", "mulu", txtml.Text, App.Path&"\server.ini")
j = WriteIni ("server", "ip", txtip.Text, App.Path&"\server.ini")
k = WriteIni ("server", "port", txtport.Text, App.Path&"\server.ini")
If i <> 0 And j <> 0 And k <> 0 Then
msg = MsgBox ("Saved successfully!", vbOKOnly, "Prompt")
Unload Me
Else
msg = MsgBox ("Save failed! Please check"&App.Path&"Is\server.ini write permission?", vbInformation, "Prompt")
End If
Form1.Show
End Sub
Private Sub Form_Load ()
txtip.Text = sckListen.LocalIP
txtport.Text = getIni (App.Path&"\server.ini", "server", "port")
txtml.Text = getIni (App.Path&"\server.ini", "server", "mulu")
End Sub
Private Sub sckListen_ConnectionRequest (ByVal requestID As Long)
List1.AddItem Time&"Request number:"&requestID&"Requesting connection"
Dim i As Long
Dim sckServer () As Winsock
If CurNumber <MaxNumber Then 'MaxNumber is the maximum number of connections, CurNumber is the current number of connections
For i = 1 To CurNumber
If sckServer (i) .State = 0 Then 'Determine if there is an idle Winsock control
Exit For
End If
Next i
If i = CurNumber Then
CurNumber = CurNumber + 1
i = CurNumber
End If
Load sckServer (i) 'Load Winsock control dynamically
sckServer (i) .Protocol = sckTCPProtocol
sckServer (i) .Accept requestID
Exit Sub
End If
'sckBusy.Close
'sckBusy.Accept requestID
'If sckListen.State <> sckClosed Then
'sckListen.Close
'End If
'sckListen.Accept requestID
End Sub
Private Sub sckServer_DataArrival (ByVal bytesTotal As Long)
i = MsgBox (sckServer.GetData, vbOKCancel, "")
End Sub |
|