[SOLVED] html Java socket Submission Instructions

$25

File Name: html_Java_socket_Submission_Instructions.zip
File Size: 376.8 KB

5/5 - (1 vote)

Submission Instructions
Make sure that all your submitted files contain yournames and studentIDs. Please submit only from one student account but make sure to include both names in the header.
No extras implemented
SMTPConnect.java
HttpInteract.java
With extras
SMTPConnect.javaHttpInteract.java12
ext .txt:
smtpconnect .java
httpinteract .java
extras.txt

Overview

:

usersomeschool.eduSMTPSMTPwebmailclientEmailclient.java

SMTPConnect
httpinteractionweb
:
EmailClient
The user interface
EmailMessage
Email message
SMTPConnect
Connection to the SMTP server
HttpInteract
Interaction with HTTP server

java
EmailClient

Part One SMTPConnect

Part Two HttpInteract
EmailClientGetListener
HTTP:URL
Get:
1.EmailClienthttpinteraction
2.EmailClientHttpInteract.send

3.EmailClient
httpinteractionHttpInteract.send
URLrequestMessage
HttpInteract.send:
1.TCP
2.requestMessageOuputStream
3.InputStream
4. 200InputStreamContentLength:ContentLength:BufferedReaderreadLine
5.InputStreamBufferedReaderread
Send:,HTTPSwebSSLSSLHTTPurl:comp211.gairing.comtest.txt
comp211.gairing.comfoobarpage2.html
comp211.gairing.comtest404index.php
comp211.gairing.comnolength.php
For the extras this might also be useful:
comp211.gairing.comredirectindex.php

80extras.txt
::
java
ziparchiveEmailClientjava
:
JavainetaddressFromheader
:FromToSubjectDateRFC 822idRFC
oMIMEContentTypeHTMLHTML
oASCIIjpgimagesMIME
cc
http301302EmailClientURLly.

HttpInteract.java
This is the code for the HttpInteract class that you will need to complete for part 2. The code for the other classes is provided onthis page.

Filename:HttpInteract.java
Names:
StudentIDs:
Date:

import java.net.;
import java.io.;
import java.util.;

Class for downloading one object from http server.

public class HttpInteract
private String host;
private String path;
private String requestMessage;

private static final int HTTPPORT80;
private static final String CRLFrn;
private static final int BUFSIZE4096;
private static final int MAXOBJECTSIZE102400;

Create HttpInteract object.
public HttpInteractString url

Split URL into host name and path name, and
set host and path class variables.
if the URL is only a host name, useas path

1. Fill in

Construct requestMessage, add a header line so that
server closes connection after one response.

2. Fill in

return;

Send Http request, parse response and return requested object
as a String if no errors,
otherwise return meaningful error message.
Dont catch Exceptions. EmailClient will handle them.
public String send throws IOException

buffer to read object in 4kB chunks
char bufnew charBUFSIZE;

Maximum size of object is 100kB, which should be enough for most objects.
Change constant if you need more.
char bodynew charMAXOBJECTSIZE;

String statusLine; status line
int status; status code
String headers; headers
int bodyLength1; lenghth of body

String tmp;

The socket to the server
Socket connection;

Streams for reading from and writing to socket
BufferedReader fromServer;
DataOutputStream toServer;

System.out.printlnConnecting server: hostCRLF;

Connect to http server on port 80.
Assign input and output streams to connection.
connection3. Fill in ;
fromServer4. Fill in ;
toServer5. Fill in ;

System.out.printlnSend request:nrequestMessage;

Send requestMessage to http server
6. Fill in

Read the status line from response message
statusLine 7. Fill in ;
System.out.printlnStatus Line:nstatusLineCRLF;

Extract status code from status line. If status code is not 200,
close connection and return an error message.
Do NOT throw an exception
8. Fill in

Read header lines from response message, convert to a string,
and assign to headers variable.
Recall that an empty line indicates end of headers.
Extract lengthfrom ContentLength: or Contentlength:
header line, if present, and assign to bodyLength variable.

9. Fill in requires about 10 lines of code
System.out.printlnHeaders:nheadersCRLF;

If object is larger than MAXOBJECTSIZE, close the connection and
return meaningful message.
if 10. Fill in
11. Fill in
return12. Fill inbodyLength;

Read the body in chunks of BUFSIZE using buf and copy the chunk
into body. Stop when either we have
read ContentLength bytes or when the connection is
closed when there is no ContentLength in the response.
Use one of the read methods of BufferedReader here, NOT readLine.
Make sure not to read more than MAXOBJECTSIZE characters.

int bytesRead0;

13. Fill in Requires 1020 lines of code

At this points body should hold to body of the downloaded object and
bytesRead should hold the number of bytes read from the BufferedReader

Close connection and return object as String.
System.out.printlnDone reading file. Closing connection.;
connection.close;
returnnew Stringbody, 0, bytesRead;

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] html Java socket Submission Instructions
$25