-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServer_U1910060.java
59 lines (49 loc) · 1.49 KB
/
Server_U1910060.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
/*
Student:
U1910060
Alimov Abdullokh
MSC2070-002
*/
import java.io.*;
import java.net.*;
import java.util.*;
public class Server_U1910060
{
public static void main(String[] args)
{
new Server_U1910060();
}
public Server_U1910060()// constructor
{
try
{
// Create a server socket
ServerSocket serverSocket = new ServerSocket(8000);
System.out.println("Server started at " + new Date() + '\n');
// Listen for a connection request
Socket socket = serverSocket.accept();
// Create data input and output streams
DataInputStream inputFromClient = new DataInputStream(
socket.getInputStream());
DataOutputStream outputToClient = new DataOutputStream(
socket.getOutputStream());
while (true)
{
// Receive radius from the client
String lowerMessgae = inputFromClient.readUTF();
InetAddress ip=socket.getInetAddress();
System.out.println("Host Name: "+ip.getHostName());
System.out.println("IP Address: "+ip.getHostAddress());
System.out.println("We have received Message "+ lowerMessgae);
// Make Meassage Uppercase Leters
String upperMessage = lowerMessgae.toUpperCase();
// Send area back to the client
outputToClient.writeUTF(upperMessage);
}
}
catch(IOException ex)
{
System.err.println(ex);
}
}
}