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