-
Notifications
You must be signed in to change notification settings - Fork 0
/
7C.java
53 lines (39 loc) · 933 Bytes
/
7C.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
import java.net.*;
import java.io.*;
import java.util.*;
public class Client
{
public static void main(String[] args)
{
Scanner sci = new Scanner(System.in);
String userstr ,str;
int ch=1;
try
{
Socket s= new Socket("localhost",6000);
do
{
// SENDING MESSAGE TO SERVER.....
DataOutputStream dout = new DataOutputStream (s.getOutputStream());
System.out.println("Enter message for server...");
userstr = sci.nextLine();
if(userstr.equals("exit"))
{
break;
}
dout.writeUTF(userstr);
// RECEIVING MESSAGE FROM SERVER....
DataInputStream dis = new DataInputStream (s.getInputStream());
str = (String)dis.readUTF();
System.out.println("Message from server is:: \n"+ str);
}while(ch==1);
// CLOSING CONNECTIONS.....
System.out.println("EXITED......");
s.close();
}
catch (Exception e)
{
System.out.println("EXITED......");
}
}
}