Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify the programs of SocketServer.java and SocketClient.java to have a Window-based user interface on Client side, and to use ObjectInputStream and ObjectOutputStream. So that you

Modify the programs of SocketServer.java and SocketClient.java to have a Window-based user interface on Client side, and to use ObjectInputStream and ObjectOutputStream. So that you can use writeObject() in ObjectOutputStream and readObject() in ObjectInputStream.

i want this type of client side window

image text in transcribed

SocketClient.java

import java.io.*; import java.net.*;

public class SocketClient {

public static void main(String[] args) throws IOException { Socket client; InputStream sin = null; OutputStream sout = null;

if (args.length != 2) { System.err.println("Usage: java SocketClient server port"); return; } try { client = new Socket(args[0], Integer.parseInt(args[1])); sin = client.getInputStream(); sout = client.getOutputStream(); } catch (UnknownHostException e) { System.err.println("can't locate server: " + args[0]); return; } String s; byte[] b = new byte[1024]; //BufferedReader in = new BufferedReader(new InputStreamReader(sin)); BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

System.out.println("connection to " + args[0] + " established"); do { System.out.print("> "); System.out.flush(); s = in.readLine(); if (s.length() == 0) continue; // make sure it doesnt hang sout.write(s.getBytes()); sout.flush(); int i = sin.read(b); System.out.write(b, 0, i); System.out.println(); } while (!s.equals("exit")); } }

SocketServer.java

import java.io.*; import java.net.*;

public class SocketServer {

public static void main(String[] args) throws IOException { Socket echoSocket; InputStream sin = null; OutputStream sout = null; byte[] b = new byte[1024]; int i; if (args.length != 1) { System.err.println("Usage: java SocketServer port"); return; } try { ServerSocket s = new ServerSocket(Integer.parseInt(args[0])); echoSocket = s.accept(); System.out.println("Connection from: " + echoSocket.getInetAddress()); sin = echoSocket.getInputStream(); sout = echoSocket.getOutputStream();

while ((i = sin.read(b)) != -1) { byte[] temp = new byte[i+2]; temp[0] = (byte) '*'; for (int k=1; k O my chat Here is the place to write a message! Send O my chat Here is the place to write a message! Send

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

Handbook Of Relational Database Design

Authors: Candace C. Fleming, Barbara Von Halle

1st Edition

0201114348, 978-0201114348

More Books

Students also viewed these Databases questions

Question

4. What will the team agreement contain?

Answered: 1 week ago

Question

What were the issues and solutions proposed by each team?

Answered: 1 week ago