Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you please write this java code in Scala. import java.io. BufferedReader ; import java.io. InputStreamReader ; import java.io. PrintStream ; import java.net. Socket ;

Can you please write this java code in Scala.

import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintStream; import java.net.Socket; public class SimpleSocketClientExample { public static void main( String[] args ) { if( args.length < 2 ) { System.out.println( "Usage: SimpleSocketClientExample  " ); System.exit( 0 ); } String server = args[ 0 ]; String path = args[ 1 ]; System.out.println( "Loading contents of URL: " + server ); try { // Connect to the server Socket socket = new Socket( server, 80 ); // Create input and output streams to read from and write to the server PrintStream out = new PrintStream( socket.getOutputStream() ); BufferedReader in = new BufferedReader( new InputStreamReader( socket.getInputStream() ) ); // Follow the HTTP protocol of GET  HTTP/1.0 followed by an empty line out.println( "GET " + path + " HTTP/1.0" ); out.println(); // Read data from the server until we finish reading the document String line = in.readLine(); while( line != null ) { System.out.println( line ); line = in.readLine(); } // Close our streams in.close(); out.close(); socket.close(); } catch( Exception e ) { e.printStackTrace(); } } }

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

The Database Relational Model A Retrospective Review And Analysis

Authors: C. J. Date

1st Edition

0201612941, 978-0201612943

More Books

Students also viewed these Databases questions

Question

Know when firms should not offer service guarantees.

Answered: 1 week ago

Question

Recognize the power of service guarantees.

Answered: 1 week ago