/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
*/
package mautcpsongsong;
import java.net.*;
import java.io.*;
/**
*
* @author PTVLNE
*/
public class serversongsong {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
ServerSocket ss = new ServerSocket(7);
System.out.println("Da tao server");
while (true) {
try {
Socket s = ss.accept();
System.out.println("Co 1 client ket noi");
Thread client = new Thread(new client(s));
client.start();
} catch (IOException ex) {
System.out.println("Loi ket noi"+ ex);
}
}
} catch (IOException ex) {
System.out.println("khong the tao server)" + ex);
}
}
}
class client implements Runnable{
private Socket Client;
public client(Socket Client){
this.Client = Client;
}
public void run(){
try {
InputStream is = Client.getInputStream();
OutputStream os = Client.getOutputStream();
DataInputStream dis = new DataInputStream(is);
DataOutputStream dos = new DataOutputStream(os);
while (true) {
String data = dis.readUTF();
char ch = data.charAt(0);
String luutru = "";
if (Character.isDigit(ch)){
int n = Character.getNumericValue(ch);
switch (n) {
case 0:
luutru = "khong";
break;
case 1:
luutru = "mot";
break;
case 2:
luutru = "hai";
break;
case 3:
luutru = "ba";
break;
case 4:
luutru = "bon";
break;
case 5:
luutru = "nam";
break;
case 6:
luutru = "sau";
break;
case 7:
luutru = "bay";
break;
case 8:
luutru = "tam";
break;
case 9:
luutru = "chin";
break;
default:
luutru = "khong phai so nguyen";
break;
}
}else{
luutru = "khong phai la so nguyen";
}
dos.writeUTF(luutru);
if(data.equals("@")){
break;
}
}
Client.close();
System.out.println("Dong ket noi");
} catch (IOException ex) {
System.out.println("Loi ket noi"+ ex);
}
}
}