-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathSocketServer.java
74 lines (37 loc) · 1.04 KB
/
SocketServer.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// import java.net.*;
public class SocketServer
{
public static void main(String args[])
{
ServerSocket server;
// Socket client;
int port=10000;
// int port=1000;
// DataInputStream dis;
PrintStream ps;
System.out.println("Starting Server Application");
// System.out.println("Trying to open the connection");
try
{
server=new ServerSocket(port);asdisa
System.out.println("Successfully opened ServerSocket");
System.out.println("waiting for client connections");
client=server.accept();
System.out.println("Client connection established");
System.out.println("IP address of client is "+client.getInetAddress());
dis=new DataInputStream(client.getInputStream());
ps=new PrintStream(client.getOutputStream());
String s=dis.readLine();
// System.out.println("The client:"+s);
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
LocalDateTime now = LocalDateTime.now();
ps.println(dtf.format(now));
ps.println("Hello");
}
catch(Exception e)
{
System.out.println(e);
}
}
}class sever {
}