0% found this document useful (0 votes)
16 views

Import Public Class Public Static Void Try New New New: Java Io

This Java code defines a Client class that establishes a socket connection to a server on port 9999. It uses input and output streams to send messages read from the console to the server and receive responses, printing them, in a loop that continues until the input is "end". Any exceptions are caught and printed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Import Public Class Public Static Void Try New New New: Java Io

This Java code defines a Client class that establishes a socket connection to a server on port 9999. It uses input and output streams to send messages read from the console to the server and receive responses, printing them, in a loop that continues until the input is "end". Any exceptions are caught and printed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Client.

java

1 import java.io.*;
3
4 public class Client {
5 public static void main(String[] args)
6 {
7 try
8 {
9 Socket s = new Socket("localhost", 9999);
10
11 DataInputStream din = new
DataInputStream(s.getInputStream());
12 DataOutputStream dout = new
DataOutputStream(s.getOutputStream());
13
14 BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
15
16 String msgin = "";
17 String msgout = "";
18
19 while(!msgin.equals("end"))
20 {
21 msgout = br.readLine();
22 dout.writeUTF(msgout);
23 msgin = din.readUTF();
24 System.out.println(msgin);
25 }
26 s.close();
27
28 }
29 catch(Exception e)
30 {
31 e.printStackTrace();
32 }
33 }
34
35 }
36

Page 1

You might also like