-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddition_client.java
More file actions
63 lines (48 loc) · 1.56 KB
/
Addition_client.java
File metadata and controls
63 lines (48 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package newpackage;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;
public class Addition_client {
public static void main(String [] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter Server Address: ");
String serverName;
serverName = sc.next();
System.out.println("Enter Port Number: ");
String port;
port = sc.next();
try
{
System.out.println("Connecting to " + serverName
+ " on port " + port);
Socket client = new Socket(serverName, Integer.parseInt(port));
System.out.println("Just connected to "
+ client.getRemoteSocketAddress());
OutputStream outToServer = client.getOutputStream();
DataOutputStream out =
new DataOutputStream(outToServer);
System.out.println("Enter a first number: ");
//userInput.nextInt();
Integer x= sc.nextInt();
System.out.println("Enter a second number: ");
// userInput.nextInt();
Integer y= sc.nextInt();
// System.out.println("hello");
out.writeInt(x);
out.writeInt(y);
InputStream inFromServer = client.getInputStream();
DataInputStream in =
new DataInputStream(inFromServer);
System.out.println("Server responds: " +in.readInt());
client.close();
}catch(IOException e)
{
e.printStackTrace();
}
}
}