Answered step by step
Verified Expert Solution
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
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