-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat_client.java
More file actions
34 lines (32 loc) · 1004 Bytes
/
chat_client.java
File metadata and controls
34 lines (32 loc) · 1004 Bytes
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
/*Network Programming: chat_client*/
package newpackage;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;
public class chat_client {
public static void main(String[] args)
{
try
{
Socket server=new Socket("localhost",1794);
Scanner sc=new Scanner(System.in);
Scanner in=new Scanner(server.getInputStream());
PrintWriter out=new PrintWriter(server.getOutputStream(),true);
String s=" ";
System.out.println("Connected with server"+"\n");
do
{
System.out.println("Client: ");
s=sc.nextLine();
out.println(s);
s=in.nextLine();
System.out.println("Server: "+s);
}while(!s.equalsIgnoreCase("Bye"));
server.close();
}
catch(Exception e)
{
System.out.println("Error :"+e);
}
}
}