Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!