Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven NoSQL Databases In A Week Get Up And Running With The Fundamentals And Functionalities Of Seven Of The Most Popular NoSQL Databases

Authors: Aaron Ploetz ,Devram Kandhare ,Sudarshan Kadambi ,Xun Wu

1st Edition

1787288862, 978-1787288867

More Books

Students also viewed these Databases questions

Question

Compare and contrast symmetric and asymmetric encryption.

Answered: 1 week ago