- Create a Server program to resolve domain names. If a client sends a machine name, the Server will reply with the corresponding IP address.
-
Forms:
-
Client Side:
- Use
TcpClient
to connect to the Server. Upon successful connection, open a separate thread to receive data from the Server while the login panel disappears and the working panel appears.
- Use
-
Server Side:
- After entering the IP address and port, use
TcpListener
to listen for connections from Clients. When a client sends a connection request, open a separate thread to receive domain names for resolution.
- After entering the IP address and port, use
-
Domain Resolution:
- When the Server receives a domain name from the Client, it will use
Dns.GetHostAddresses(<domain>)
to get a list of IPs corresponding to the domain and filter the list based on the requested format. If no IP is found, the Server returns an empty string.
- When the Server receives a domain name from the Client, it will use
-
First, enter the IP address and port for the Client and Server to connect (enter for Server and click connect first).
-
After the Client connects to the Server, it can enter any domain name and select the desired IP format before clicking the "Query" button to send data to the Server for processing.
-
The program will display errors for incorrect actions, such as:
- The Client sends the Server the path of a file located on the Server, and the Server returns the content of the requested file. Multiple Clients can connect to the Server simultaneously.
-
Forms:
-
Client Side:
- Create a
TcpClient
with hostname127.0.0.1
and port8080
. Create aNetworkStream
and send the Server path as a byte array. Wait for the Server to return the byte array. If the file is text, convert it to a string and display it; if it’s an image, display it in a picture box.
- Create a
-
Server Side:
- Create a
TcpListener
to listen for connections and accept incomingTcpClient
. Similar to the Client, create aNetworkStream
for data transfer. When the Server receives a byte array as a path, it checks if the file exists. If it does, it sends the file content as a byte array to the Client. If the file does not exist, it sends a byte array of the string “-1”, and the Client will notify that the file does not exist and terminate.
- Create a
-
Open the window and press the "Server" button to start the Server and the "Client" button to open the Client. To move the form, click and hold anywhere on the Client form that does not contain buttons or textboxes, and for the Server, hold between the two images.
-
Enter the path in the "File Path" field on the Server and press "Connect". A dialog will open to save the file. Name the file and press "Save". The content will display on the form.
- The Client attempts to connect before the Server is started.
- Only one Server can listen on the same IPEndpoint (
0.0.0.0:8080
). If two Servers are listening, the one started last will automatically stop and close the form. - If the Server path textbox is empty during the Client connection, a MessageBox will prompt for the path.
- If the user enters an incorrect path, the program will notify that the file cannot be found on the Server.
- Read emails, send emails, and view emails sent in the last 7 days.
- The program consists of three forms designed as follows: