0

I am new to java. Here i showed three different rfid card to my rfid machine.but i get only one correct ans and that answer is repeating what is wrong with my code, Advance thanks.....

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketTimeoutException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;

public class Serverc {
    static String s= "55000016910001DB00FB63ABEEAFC1EC888F1030090602111114ABC200000000";
     static ArrayList<String> al=new ArrayList<String>();
    final protected static char[] hexArray = "0123456789ABCDEF".toCharArray();
    public static String bytesToHex(byte[] bytes) {
        char[] hexChars = new char[bytes.length * 2];
        for ( int j = 0; j < bytes.length; j++ ) {
            int v = bytes[j] & 0xFF;
            hexChars[j * 2] = hexArray[v >>> 4];
            hexChars[j * 2 + 1] = hexArray[v & 0x0F];
        }
        return new String(hexChars);
    }
    public static void connection() throws IOException
    {

      ServerSocket ss=new ServerSocket(9888);//exce
      ss.setSoTimeout(300000000);//exce
      System.out.println("Waiting for client on port " +
                ss.getLocalPort() + "...");
       while(true)
       {

                  Socket server = ss.accept();//exce
                  System.out.println("Just connected to "
                             + server.getRemoteSocketAddress());
                  DataInputStream in =
                  new DataInputStream(server.getInputStream());//exce
                  int input = 0;
                  //BufferedReader br = new BufferedReader(in);

                  byte byteArr[] = new byte[32];
//                example.getBytes();
                  try{
                       while((input = in.read(byteArr)) != -1)//exce
                       {

                         System.out.println("Size read is " + input);
                         System.out.println("Data is " + bytesToHex(byteArr));

                       }


//                       System.out.println("inside finally");
                         server.close();//exce
//                       System.out.println("outside finally");
                   }
                  catch(SocketTimeoutException ex){
                   System.out.println("Socket timed out!");
                 }
                  try {
                    Thread.sleep(1000);
                  } catch (InterruptedException e) {

                   e.printStackTrace();
                  }

      }
    }


    public static void main(String args[]) throws IOException{
        Serverc obj=new Serverc();
        obj.connection();


    }
}

my console is shown below(PLEASE NOTE I AM WRITING SERVER CODE HERE CLIENT IS MY RFID MACHINE)

I got a single answer instead of three repeated here(Correct answer is three different ids,here i get only one id and that id is correct but other two are not obtained)

Waiting for client on port 9888...
Just connected to /223.185.14.90:7435
Size read is 9
Data is 55000003580000B8E30000000000000000000000000000000000000000000000
Size read is 24
Data is 55000012920001E200600107C47B7D520615031211141F810000000000000000
Size read is 24
Data is 55000012920001E200600107C47B7D520615031211141F810000000000000000
Size read is 24
Data is 55000012920001E200600107C47B7D520615031211141F810000000000000000
Size read is 24
Data is 55000012920001E200600107C47B7D520615031211141F810000000000000000
Size read is 24
Data is 55000012920001E200600107C47B7D520615031211141F810000000000000000
Miller
  • 744
  • 3
  • 15
  • 39
  • `PLEASE NOTE I AM WRITING SERVER CODE HERE CLIENT IS MY RFID MACHINE` - no need to shout :) – Thomas Nov 12 '14 at 10:04
  • @Thomas :ohh sorry if it is not needed – Miller Nov 12 '14 at 10:06
  • Btw, did you debug your code? – Thomas Nov 12 '14 at 10:09
  • yes code executed..up to this line System.out.println("Data is " + bytesToHex(byteArr)); After that i wait a lot of time but no result my data is repeting – Miller Nov 12 '14 at 10:14
  • Did you debug the client, if possible? I'd suspect the client just keeps sending the same data. – Thomas Nov 12 '14 at 10:17
  • no client is sending correct data....because for checking there is a software provided by client using that we can view datas sending to my server – Miller Nov 12 '14 at 10:33
  • the code not reached at this line server.close(); – Miller Nov 12 '14 at 12:01
  • As I said, the `read()` method seems to keep returning the same data which would mean that the `SocketInputStream` (assuming you use the standard implementation) succeeds in reading data from the client. AFAIK this would either indicate a problem in the underlying native code (not very probable) or with the client. – Thomas Nov 12 '14 at 12:16
  • What you could try is call `available()` in the stream and see if it returns a value > 0, meaning there's still data to be read. – Thomas Nov 12 '14 at 12:20
  • @Thomas I tried it but i am getting a value zero. – Miller Nov 13 '14 at 09:55

0 Answers0