0% found this document useful (0 votes)
3 views1 page

Java Client Program Example

The document contains a Java program for a client that connects to a server using sockets. It allows the user to input mathematical operations which are sent to the server for processing, and the results are displayed. The program continues to accept input until the user types 'Over' to terminate the connection.

Uploaded by

aditi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Java Client Program Example

The document contains a Java program for a client that connects to a server using sockets. It allows the user to input mathematical operations which are sent to the server for processing, and the results are displayed. The program continues to accept input until the user types 'Over' to terminate the connection.

Uploaded by

aditi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

// A Java program for a Client

import [Link].*;
import [Link].*;
import [Link].*;

public class Client2 {


private Socket s = null;
public Client2(String address, int port)
{
try {
// In this Code Input Getting from a user
Scanner sc = new Scanner([Link]);
s = new Socket(address, port);
[Link]("Connected");

// Create two objects first is dis and dos for


// input and output
DataInputStream dis
= new DataInputStream([Link]());
DataOutputStream dos
= new DataOutputStream([Link]());

// Making a Loop
while (true) {
[Link](
"Name : Abhinandan Gaikwad Roll No : TA42");
[Link](
"Enter the operation in the form operand operator
operand");
[Link]("Example 3 + 5 ");
String inp = [Link]();

// Check the user input if user enter over


// then
// connect is stopped by server and user
if ([Link]("Over"))
break;
[Link](inp);

String ans = [Link]();


[Link]("Answer = " + ans);
}
}
catch (Exception e) {
[Link]("Error in Connection");
}
}

public static void main(String args[])


{
// Connection With Server port 5000
Client2 client = new Client2("[Link]", 5000);
}
}

You might also like