Question
Mail User Agent- Simplified Version In this assignment, you will write a Java program that establishes a TCP connection with a mail server through the
Mail User Agent- Simplified Version
In this assignment, you will write a Java program that establishes a TCP connection with a mail server through the socket interface, and sends an email message. Your program sends SMTP commands to local mail server, receives and processes SMTP commands from local mail server. It sends email message to one recipient at a time. The email message contains a typical message header and a message body.
Here is a skeleton of the code you'll need to write:
import java.io.*; import java.net.*; public class EmailSender { public static void main(String[] args) throws Exception { // Create a socket which connect to Server (HOSTNAME, PORTNUM) String Hostname = "___________________"; int Port = _______; Socket emailClient; try { emailClient = new Socket(Hostname, Port); //InputStream & outputStream Scanner inFromServer = new Scanner(emailClient.getInputStream()); DataOutputStream outToServer = new DataOutputStream(emailClient.getOutputStream()); // Read greeting from the server. String response = inFromServer.nextLine(); System.out.println(response); if (!response.startsWith("220")) { throw new Exception("220 reply not received from server."); } // Send HELO command and get server response. String command = "HELO usca.edu "; System.out.print(command); outToServer.writeBytes(command); response = inFromServer.nextLine(); System.out.println(response); if (!response.startsWith("250")) { throw new Exception("250 reply not received from server."); } // Send MAIL FROM command. // Send RCPT TO command. // Send DATA command. // Send message data. // End with line with a single period. // Send QUIT command. // Close the connection emailClient.close(); } catch (Exception e) { System.err.print("Caught Exception" + e.getMessage()); } } }
Socket Web Programming Single Thread Web Server
Your target is to develop a single thread web server that is capable of serving one request and response at a time. Your program will establish a separate TCP connection for each request/response pair, respond to correct GET request and send back information that the client requests, reject all other type of request by send a http 400 bad request response. If the file is not found, send a http 404 file not found response. You may only support text/html and image/jpeg file type.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started