# 以 Winsock 作 server 时, 该如何 login ?

Posted by ptc on November 20, 1998 at 11:16:19:

以下程式作 server 时, 用 telnet 作 client , 会有 login 及 userid 的输入要求, 不知该如何处理 ? (Where are login 及 userid )

Private id1 As Long
Dim R_buffer, v, w, d_file, x_ As String
Const max = 1
Dim df(max + 2), onef As Long
Private Sub Form_Load()
id1 = 1: onef = 0
For i = 1 To max + 1: df(i) = 0: Next i
d_file = "Default.htm"
tcp(0).LocalPort = 23: tcp(0).Listen
List1.AddItem "port" + Str(tcp(0).LocalPort), 0
MSComm1.CommPort = 2
MSComm1.Settings = "1200,e,7,1"
MSComm1.RThreshold = 1
MSComm1.DTREnable = True
MSComm1.RTSEnable = True
'MSComm1.PortOpen = True
'client.Show
End Sub

Private Sub Form_Unload(Cancel As Integer)
If tcp(0).State <> 0 Then tcp(0).Close
End Sub

Private Sub tcp_Close(Index As Integer)
List1.AddItem "connect off=" & Index, 0
tcp(Index).Close
Unload tcp(Index)
df(Index) = 0
End Sub

Private Sub tcp_ConnectionRequest(Index As Integer, ByVal requestID As Long)
If Index = 0 Then
If onef = 0 Then MSComm1.PortOpen = True: onef = 1
For i = 1 To max
If df(i) = 0 Then Exit For
Next i
id1 = i
Debug.Print "id=" & id1
Load tcp(id1)
df(id1) = 1
tcp(id1).LocalPort = 0
tcp(id1).Accept id
List1.AddItem "socket= " & id1 & " on", 0
If id1 = max Then
tcp(id1).SendData "sorry full"
DoEvents
Unload tcp(id1)
df(id1) = 0
Else
tcp(id1).SendData "welcome to ulestd" & vbCrLf
DoEvents
End If
End If
End Sub

Private Sub tcp_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Dim s As String
tcp(Index).GetData s, vbString, total
MSComm1.Output = s
End Sub

Private Sub tcp_SendComplete(Index As Integer)
'List1.AddItem "socket=" & Index & "off", 0
'tcp(Index).Close
End Sub

Follow Ups: