Write network pager with VB (2)

zhaozj2021-02-08  318

Second, a form is also established in the server-side server engineering, load the Winsock control, called TCPServer, the protocol selection TCP, set its index value of 0, and add a module in the project. The content is as follows string 'records the client's IP address client' records the current session Port ClientID as long 'records the customer's ID number ClientConnected AS Boolean' client connection status, True means connected, false said no connection End Type Dim CurUser () as ActiveUser Dim tcpIndex as Integer 'track the current number of connections established add the following code in the Form_Load event: Private Sub Form_Load () tcpServer (0) .Protocol = sckTCPProtocol tcpServer (0) .LocalPort = 1001' will LocalPort The property is set to an integer. TCPServer (0) .Listen 'then calls the listen method.

tcpIndex = 1 End Sub request will be answering client connection using ConnectionRequest event response to the request client program, as follows: Private Sub tcpServer_ConnectionRequest (Index As Integer, ByVal requestID As Long) Dim i As Integer On Error GoTo ErrHandle For i = 1 to TCPINDEX 'Select an idle port if curuser (i) .clientconnected = false and i <> tcpindex the loading tcpserver (i) TCPServer (i) .localport = curuser (i) .clientport - 1 TCPServer (i). Accept requestID Exit For ElseIf CurUser (i) .ClientConnected = False Then Load tcpServer (i) tcpServer (i) .LocalPort = Port If tcpServer (i) .State <> sckClosed Then tcpServer (i) .Close End If tcpServer (i) .Accept requestid exit for end if next doevents' Test connection Success If TCPServer (i) .State = Sckconnected Then I = TCPINDEX TEN 'has no available port, record customers' IP address and port number TCPIndex = TCPIndex 1 port = Port 1 ReDim Preserve CurUser (tcpIndex) CurUser (i) .ClientIP = tcpServer (i) .RemoteHostIP CurUser (i) .ClientConnected = True CurUser (i) .ClientPort = Port CurUser (tcpIndex) .ClientConnected = False Else CurUser (i ) .Clientip = TCPSERVER (i) .Remotehosti P curuser (i) .clientport = port curuser (i) .clientConnected = true end if End 'Check the STATE attribute of the control, if not closed, close before accepting a new connection. If TCPSERVER (0) .State <> SCKCLOSED THEN TCPSERVER (0) .close TCPServer (0) .accept requestid 'accepts the RequestID parameter, connection.

转载请注明原文地址:https://www.9cbs.com/read-1508.html

New Post(0)