-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClient_2.java
56 lines (49 loc) · 1.77 KB
/
Client_2.java
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
import java.io.*;
import java.net.*;
public class Client_2 {
private Socket client_socket = null;
private DataOutputStream output_stream = null;
private DataInputStream input_stream = null;
public Client_2(String host_address, int port_number) throws UnknownHostException,IOException
{
try
{
//socket initialization
client_socket = new Socket(host_address,port_number);
System.out.println("Connected to Server");
output_stream = new DataOutputStream(client_socket.getOutputStream());
//client to server communication
System.out.println("Sending message to server >>");
output_stream.writeUTF("Hello Server ..!!!");
//Server to client communication
System.out.println("Accepting message from server >>");
input_stream = new DataInputStream(client_socket.getInputStream());
String message = input_stream.readUTF().toString();
System.out.println(message);
//Closing connections
output_stream.close();
client_socket.close();
input_stream.close();
}
catch(UnknownHostException e)
{ System.out.println(e); }
catch(IOException e)
{ System.out.println(e); }
}
public static void main(String args[])
{
try
{
//local host address
String host_address = "192.168.1.205";
Client client = new Client(host_address,6060);
}
catch(UnknownHostException e)
{ System.out.println(e); }
catch(IOException e)
{ System.out.println(e); }
System.out.println("Sending Message to server >>>");
System.out.println("Accepting message from server >>>");
System.out.println("Hello Client...!!!");
}
}