forked from karthigaav/ChatApplication
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.java
More file actions
54 lines (47 loc) · 1.43 KB
/
Copy pathServer.java
File metadata and controls
54 lines (47 loc) · 1.43 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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;
public class Server {
public static void main (String args[])
{
try {
Scanner scan = new Scanner(System.in);
ServerSocket server_sock = new ServerSocket(6013); // 6013
// Socket sock = new Socket("127.0.0.1",6013);
//InputStream in = sock.getInputStream();
//BufferedReader bin = new BufferedReader(new InputStreamReader(in));
while (true) {
Socket client = server_sock.accept();
// we have a connection
PrintWriter pout = new PrintWriter(client.getOutputStream(), true);
Socket sock = new Socket("127.0.0.1",6014); // 6014
InputStream in = sock.getInputStream();
BufferedReader bin = new BufferedReader(new InputStreamReader(in));
String chatline;
String message = " ";
// write the Date to the socket
while(!(message.equals("bye"))){
message = scan.nextLine();
pout.println("Server Message"+" - "+ message);
/* read the date from the socket */
if ( (chatline = bin.readLine()) != null)
System.out.println(chatline);
}
/* close the socket and resume */
/* listening for connections */
client.close();
sock.close();
// close the socket and resume listening for more connections
//client.close();
}
}
catch (IOException ioe) {
System.err.println(ioe);
}
}
}