Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Translate this client java class to python programming language. import java.io.BufferedReader; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.InputStreamReader; import java.net.InetAddress; import java.net.Socket; public class client {

Translate this client java class to python programming language.

import java.io.BufferedReader;

import java.io.DataInputStream;

import java.io.DataOutputStream;

import java.io.InputStreamReader;

import java.net.InetAddress;

import java.net.Socket;

public class client {

public static void main(String[] args) {

Socket sock = null;

InetAddress addr = null;

DataOutputStream sockStrm = null;

DataInputStream sockStrmIn= null;

InputStreamReader instrm = null;

BufferedReader stdin = null;

System.out.println("Client starting.");

try {

addr = InetAddress.getByName("");

sock = new Socket(addr,13544); // create client socket

} catch (Exception e) {

System.out.println("Creation of client's Socket failed.");

System.exit(1);

}

try {

instrm = new InputStreamReader(System.in);

stdin = new BufferedReader(instrm);

sockStrmIn = new DataInputStream(sock.getInputStream());

sockStrm = new DataOutputStream(sock.getOutputStream());

} catch (Exception e) {

System.out.println("Socket output stream failed.");

System.exit(1);

}

String clientInput="";

do{

try {

clientInput = stdin.readLine();

sockStrm.writeUTF(clientInput);

System.out.println(sockStrmIn.readUTF());

} catch (Exception e) {

System.out.println("Terminal read or socket output failed.");

System.exit(1);

}

}while(!clientInput.equals("E"));

try {

instrm.close();

stdin.close();

sockStrm.close();

sockStrmIn.close();

sock.close();

} catch (Exception e) {

System.out.println("Client couldn't close socket.");

System.exit(1);

}

System.out.println("Client finished.");

}

}

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

Concepts of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

7th edition

978-1111825911, 1111825912, 978-1133684374, 1133684378, 978-111182591

More Books

Students also viewed these Databases questions