-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathTCPServer.java
More file actions
42 lines (35 loc) · 948 Bytes
/
TCPServer.java
File metadata and controls
42 lines (35 loc) · 948 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
35
36
37
38
39
40
41
42
import java.io.*;
import java.net.*;
class Thr extends Thread
{
Socket s;
Thr(){s=null; }
Thr(Socket s1) { s=s1;}
public void run()
{
String clientSentence;
String capitalizedSentence;
try{
BufferedReader inFromClient =new BufferedReader(new InputStreamReader(s.getInputStream()));
DataOutputStream outToClient=new DataOutputStream(s.getOutputStream());
clientSentence = inFromClient.readLine();
System.out.println(clientSentence);
capitalizedSentence = clientSentence.toUpperCase() + '\n';
outToClient.writeBytes(capitalizedSentence);
s.close();
if(clientSentence.equals("exit"))
System.exit(1);
}
catch(Exception e){}
}
}
class TCPServer {
public static void main(String argv[]) throws Exception {
ServerSocket dataReceive = new ServerSocket(4444);
while(true) {
Socket connectionSocket = dataReceive.accept();
Thr t=new Thr(connectionSocket);
t.start();
}
}
}