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