-1
私たちはすでにUIを構築しているので私たちは私のmifareカードを使用することができますシステムを作成するrfidリーダーとmysqlデータベースを使用して、クライアントにサーバーがクライアントと通信できるようにthredを使用する方法
元のメッセージを送信するサーバ。そのような気にいらない「あなたはドアを渡す」には、我々は我々の目標を達成するために、マルチスレッドを使用しようとするが、それはここで
がコードで停止し続けますpublic class DoorServer4 {
static{
try{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("connect ti MySQLToJava");
}
catch (Exception e){
System.out.println("Error loading MySQL Driver");
e.printStackTrace();
}
}
public class EchoThread extends Thread {
PrintWriter out;
String wel;
public EchoThread(Socket ss, String wel) throws IOException{
this.wel = wel;
out = new PrintWriter(new OutputStreamWriter(ss.getOutputStream()));
}
public void printText() throws IOException{
out.println(wel);
out.flush();
}
public void run(){
try {
printText();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
new DoorServer4().go();
}
public void go() throws IOException{
String wel = null;
ArrayList<String> list=new ArrayList<String>();
ServerSocket ss = new ServerSocket(25566);
System.out.println("start listening...");
while(true){
Socket socket = ss.accept();
System.out.println("client connected...");
InputStream rawIn = socket.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(rawIn));
String line=null;
while ((line=in.readLine()) != null) {
list.add(line);
//System.out.println(line);
}
System.out.println(list.get(0));
System.out.println(list.get(1));
try{
DBConnection DBCon = new
DBConnection("jdbc:mysql://localhost/lanyang?useUnicode=true&characterEncoding=big5","root","1234");
Connection conn = DBCon.makeConnection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT `m_name`,`card_num` FROM memberdata WHERE `card_num` LIKE '"+list.get(0)+"%'") ;
if(rs.next()){
String card = rs.getString("card_num");
if(card !="")
wel = "welcome"+rs.getString("m_name");
System.out.println("welcome"+rs.getString("m_name"));
Statement st = conn.createStatement();
String qry1 = "INSERT INTO door VALUES ('" +list.get(0)+"','" +list.get(1)+"')";
st.executeUpdate(qry1);
}
else{
wel = "member not found";
System.out.println("member not found");
}
}
catch(Exception e){
e.printStackTrace();
}
EchoThread echo = new EchoThread(socket, wel);
echo.start();
list.clear();
}
}
}
あなたが
writer.close()
を使用
DoorClient3#go()
で
SS
public class DoorClient3 {
PrintStream writer;
BufferedReader in;
Socket socket;
public static void main(String[] args) throws CardException {
// TODO Auto-generated method stub
DoorClient3 client = new DoorClient3();
client.go();
}
public void go() throws CardException {
setUpNetworking();
SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
String nowDate = sdFormat.format(new Date());
// Display the list of terminals
TerminalFactory factory = TerminalFactory.getDefault();
List<CardTerminal> terminals = factory.terminals().list();
System.out.println("Terminals: " + terminals);
// Use the first terminal
CardTerminal terminal = terminals.get(0);
// Connect wit hthe card
Card card = terminal.connect("*");
System.out.println("card: " + card);
CardChannel channel = card.getBasicChannel();
// Send Select Applet command
ResponseAPDU answer = channel.transmit(new CommandAPDU(new byte[] { (byte)0xFF, (byte)0xCA, (byte)0x00, (byte)0x00, (byte)0x00 }));
System.out.println("answer: " + answer.toString());
// Send test command
answer = channel.transmit(new CommandAPDU(new byte[] { (byte)0xFF, (byte)0xCA, (byte)0x00, (byte)0x00, (byte)0x00 }));
System.out.println("answer: " + answer.toString());
//byte r[] = answer.getData();
String hex = DatatypeConverter.printHexBinary(answer.getBytes());
writer.println((String)hex);
writer.print((String)nowDate);
writer.flush();
writer.close();
// Disconnect the card
card.disconnect(false);
try{
Thread.sleep(10000);
}catch (InterruptedException e){
e.printStackTrace();
}
Thread readerThread = new Thread(new IncomingReader());
readerThread.start();
}
private void setUpNetworking() {
try {
socket = new Socket("localhost", 25566);
InputStreamReader rawIn = new InputStreamReader(socket.getInputStream());
in = new BufferedReader(rawIn);
writer = new PrintStream(socket.getOutputStream());
}catch(IOException ex) {
ex.printStackTrace();
}
}
public class IncomingReader implements Runnable {
@Override
public void run() {
// TODO Auto-generated method stub
String message;
try {
while ((message = in.readLine()) != null) {
System.out.println("read" + message);
}
}catch(Exception ex){
ex.printStackTrace();
}
}
}
}
こんにちは、私はそれを調整しますが、現在はドアの44番と62番の接続リセットを示しています。 –