Small network management system based on WINSOCK and its implementation

zhaozj2021-02-08  194

Small network management system based on WINSOCK and its implementation Nicefeather

Abstract: This article mainly discusses the basic functions of small network information management systems based on the Internet, and provides a construction method based on WINSOCK control. Keywords: Winsock, small network information system, login mechanism, Internet data transfer

MNMS Based on WinSock and it's Implement NiceFeather Abstract: This paper describes some functions of a miniature network management system base on internet and offers the method of MNMS's implement with winsock Keywords:. Winsock, MNMS (Miniature Network Management System), Logon Mechanism, Internet Data Transfer

1. Functional user login authentication, email system, file transfer, message notification

2. Winsock control This section describes that Winsock controls are invisible to users, providing a convenient way to access TCP and UDP network services. Microsoft Access, Visual Basic, Visual C or Visual FoxPro developers can use it. To write customer or server applications, you don't have to know the details of TCP or call low Winsock APIs. By setting the properties of the control and calling its method to easily connect to a remote machine and can also exchange data two-way.

If you create a client application, you must know the server computer name or IP address (RemoteHost property), and know the port of "listening" (RemotePort property), then call the Connect method. If you create a server application, you should set a listening port (LocalPort property) and call the listen method. ConnectionRequest events occur when the client computer needs to connect. In order to complete the connection, you can call the AcceptRequest method within the ConnectionRequest event.

After establishing a connection, any one of the computers can send and receive data. In order to send data, the SendData method can be called. DataArrival events occur when receiving data. Call the getData method within the DataArrival event to get the data.

To implement data transfer between the two remote computers on the Internet, Winsock programming is a very convenient and fast choice. Obviously, Winsock communication is based on Client / Server mode. In the implementation, two Winsock objects can be generated, one of which as a server object in port 1 "listening", another as a client object to connect another computer in port 2 - that is, each computer can be used as a server, or Is the client.

In VB6.0, Winsock has two data transfer formats: string type and byte streaming; usual information interaction can use string type, but due to file transfer to take into account various format files, the file cannot be characterized Skewers are transmitted, at which point byte streaming data transfer ensures complete data.

The method is as follows: (1) If it is a transmitted string type, send: Winsock1.senddata strdata; receive: Winsock1.getdata strdata (strData is a string String type variable). (2) If it is a transmission byte stream, send: Winsock1.senddata strdata (); Receive: Winsock1.GetData strData () (STRDATA () is byte array DIM STRDATA () AS BYTE). 3 WINSOCK implementation method for small network management system

3.1 File Transfer Implementation Method on the Internet When the computer A requires files (including uploading and downloading) transmission, first "handshake", after the first "handshake" is first transmitted. Transfer. Data file data transmission sent by Winsock's SendData method, first handshake: file transfer (upload, download) Request data format: Operation type file name file block size file block number The last size (bytes) 0: Upload Local file name 1kb (default) file length / block size 1: Apply Download file name in remote computer The second handshake: File transfer (upload, download) Request response operation and reply information upload: Send OK, tell the other party to start Transfer Data Download Response: After the number of file blocks block size the last one byte size, the computer enters the real file data transfer, as shown (assuming from a → b): so repeated, until the data block of the file After completion, the progress bar can be displayed according to the remaining number of the transfer block.

3.2 User Login Management

(1) The user login mechanism is guaranteed security, the user login adopts the encrypted transmission user name and password, the user login mechanism is as follows: When the client issues a login request to the server, the server generates the corresponding Winsock Object Receive (Accept) client Winsock, thus establishing The server between the server and the different users.

(2) WINSOCK server creates multi-client connection method: first establish Winsock array Winsock1 () in the server, where Winsock (0) performs "listening", when the client issues a connection request (ClintWinsock.Connect server IP address, server listening port) When Winsock (0) generates the following message: Private Sub Winsock1_ConnectionRequest (Index As INTEGER, BYVAL REQUESTID As Long) If INDEX = 0 THEN 'Lord Winsock - Winsock (0) A message I = 1 While i <= CUR AND ONL (I 0) = 0 'In the previous WINSOCK found free WINSOCK I = i 1 Wend if i <= cur life "found in the currently loaded socket, found that users have left Winsock1 (i) .localport = 0' uses Socket Winsock1 (i) .accept Requestid 'Receive ONL (i, 0) = 0' Winsock (i) Used else 'in the currently loaded socket, no user leaves CUR = CUR 1' Current receiving port to increase loading Winsock1 (CUR) "Generates New 'Winsock Winsock1 (Cur) .localport = 0 Winsock1 (CUR) .accept requestid' Receive ONL (CUR) = 0 'Winsock (CUR) After the END IF END SUB is occupied, the server utilizes The generated Winsock (i) communicates with the i-th user. 3.3 Small Mail System We have established a user database and a mail database, under the implementation of the user's login of the user, performing user mail management; at this time, data management is involved. The database structure is as follows: (1) User Database Structure: UserID User Number Name User Name Chinesename Name CODE Password PP Permissions DSCRP Description () Mail Database Structure: MSGID Message Number Receiver Receiver Sender Sender STYLE Type Word Message Get None SJ Message Get Time BJ Message information

When the user logs in, the server extracts the Receiver from the mail database is the user and the message is a record of the new (Get field value "new"), package it, and transmits it with the user Winsock object. The server also provides the customer's command requirements, then performs the corresponding operation: Customer command format: Mail Command chr (13) Runchar Separation Command Data 0 Read New Email 1 Reading Old Email 2 Read All Messages 3 Delete Mail Short You need to provide the mail number to be deleted (send together in the user login) Server Response command: Send mail data, the field is separated from the carriageway, and the information processing is performed in the mail content - The car is encoded, such as replacing with% 0, and% by %% is replaced. Or send delete success messages, delete failed messages, read failed messages - these special messages can distinguish between data or messages and messages in the message front end. 3.4 The chat room obviously uses the user login mechanism described above, we can establish a chat room in the server for real-time conversations. Similarly, we can use special message management methods to chat management; as follows: select case command of the first byte case "0" enters conference room for i = 1 to cur 'Notification Other online users have users online IF ONL ( I, 0) = 0 THEN WINSOCK1 (i) .senddata "0" get_un (index) chr (13) Next Case "1" 'Leaving the meeting room for i = 1 to cur' Notification Other online users have users offline IF ONL (I, 0) = 0 THEN WINSOCK1 (i) .senddata "1" STR (ONL (INDEX, 1)) CHR (13) Next Case "2" Speech IF Second byte = "0" THEN 'Talk to all users for i = 1 to cur' to send words to all users IF ONL (i, 0) = 0 THEN WINSOCK1 (i) .senddata "2" INDEX user's name "said:" Text Endif Next Else 'tells a user whispered' From the following byte of the command (ends to the end of the Enter) X Winsock1 (x) .senddata "2" Nort Index user's name " You quietly said: " Text End if Case" 5 "'invitation to join a online user into the conference room' from the following bytes (to the end of the Enter) to get the user code X Winsock1 (x) .senddata" 5 " Name CHR (13) 'to send a command to the meeting room to the first XU, and wait for the response End Select

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

New Post(0)