Use Socket and ServerSocket to implement data transmission between client and server

Table of contents

complete program

program analysis

Series of articles


When shopping in malls such as JD.com/Taobao, you need to register an account first and save the username and password on the server of the mall such as JD.com/Taobao. You must log in before shopping and verify that the username and password entered by the user are consistent with the server of the mall such as JD.com/Taobao. Check whether the saved username and password are consistent. If they are consistent, the login is successful. If they are inconsistent, the login fails.

This case uses the TCP protocol to simulate the login operation (Socket as the client, ServerSocket as the server), creates the user.properties file on the server, and saves the user name and password of the registered user (format: root=toor, root on the left represents the user name , Toor on the right represents the password), the client enters the user name and password through the keyboard, and sends it to the server for verification. If the verification is passed, the server will give the client a response "Login successful" prompt message. If the verification fails, the server will give the client Respond to the "login failed" prompt message.

training objectives

Able to write registration and login functions under TCP protocol

training tips

1. How to create client and server objects?

2. How to write data into the .properties file?

3. How to send data according to rows

Guess you like

Origin blog.csdn.net/m0_68111267/article/details/134028307