Difference between revisions of "Alien Example Client"

From RifidiWiki

Jump to: navigation, search
Line 1: Line 1:
 +
=[http://yjucofi.co.cc This Page Is Currently Under Construction And Will Be Available Shortly, Please Visit Reserve Copy Page]=
 
You can see a list of possible alien commands by sending the 'help' command to the alien reader.  However, not all of these commands are implemented in rifidi.  See this [[Alien_9800#Supported Commands | List of supported commands]].  
 
You can see a list of possible alien commands by sending the 'help' command to the alien reader.  However, not all of these commands are implemented in rifidi.  See this [[Alien_9800#Supported Commands | List of supported commands]].  
  
<pre>
+
&lt;pre&gt;
 
/*
 
/*
 
  *  AlienExampleClient.java
 
  *  AlienExampleClient.java
Line 30: Line 31:
 
public class AlienExampleClient {
 
public class AlienExampleClient {
  
public static final String IP_ADDRESS = new String("127.0.0.1");
+
public static final String IP_ADDRESS = new String(&quot;127.0.0.1&quot;);
 
public static final int READER_PORT = 20000;
 
public static final int READER_PORT = 20000;
 
private static Socket connection = null;
 
private static Socket connection = null;
Line 43: Line 44:
 
*/
 
*/
 
private void  init() throws IOException, InterruptedException{
 
private void  init() throws IOException, InterruptedException{
connection = new Socket("127.0.0.1", READER_PORT);
+
connection = new Socket(&quot;127.0.0.1&quot;, READER_PORT);
  
 
in = new BufferedReader(new InputStreamReader(connection
 
in = new BufferedReader(new InputStreamReader(connection
Line 51: Line 52:
 
Thread.sleep(500);
 
Thread.sleep(500);
 
System.out.println(readFromReader(in));
 
System.out.println(readFromReader(in));
out.write("alien\n");
+
out.write(&quot;alien\n&quot;);
 
out.flush();
 
out.flush();
 
System.out.println(readFromReader(in));
 
System.out.println(readFromReader(in));
 
Thread.sleep(500);
 
Thread.sleep(500);
out.write("password\n");
+
out.write(&quot;password\n&quot;);
 
out.flush();
 
out.flush();
 
System.out.println(readFromReader(in));
 
System.out.println(readFromReader(in));
Line 65: Line 66:
 
*/
 
*/
 
private void tearDown() throws IOException{
 
private void tearDown() throws IOException{
out.write("q");
+
out.write(&quot;q&quot;);
 
out.flush();
 
out.flush();
 
connection.close();
 
connection.close();
Line 76: Line 77:
 
*/
 
*/
 
private String getTags() throws IOException{
 
private String getTags() throws IOException{
String command = "t";
+
String command = &quot;t&quot;;
out.write(command + "\n");
+
out.write(command + &quot;\n&quot;);
 
out.flush();
 
out.flush();
 
String returnVal = readFromReader(in);
 
String returnVal = readFromReader(in);
Line 117: Line 118:
 
}
 
}
  
</pre>
+
&lt;/pre&gt;

Revision as of 23:26, 23 November 2010

This Page Is Currently Under Construction And Will Be Available Shortly, Please Visit Reserve Copy Page

You can see a list of possible alien commands by sending the 'help' command to the alien reader. However, not all of these commands are implemented in rifidi. See this List of supported commands.

<pre> /*

*  AlienExampleClient.java
*
*  Created:	Dec 6, 2007
*  Project:	RiFidi Emulator - A Software Simulation Tool for RFID Devices
*  				http://www.rifidi.org
*  				http://rifidi.sourceforge.net
*  Copyright:	Pramari LLC and the Rifidi Project
*  License:	Lesser GNU Public License (LGPL)
*  				http://www.opensource.org/licenses/lgpl-license.html
*  Author:    Kyle Neumeier - kyle@pramari.com
*/

package sandbox;

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.Socket;

/**

* This class shows how to create a program to talk to the alien reader.
* 
* @author Kyle Neumeier - kyle@pramari.com
*
*/

public class AlienExampleClient {

public static final String IP_ADDRESS = new String("127.0.0.1"); public static final int READER_PORT = 20000; private static Socket connection = null;

private static PrintWriter out = null; private static BufferedReader in = null;

/** * Initialize the connection and send username/password * @throws IOException * @throws InterruptedException */ private void init() throws IOException, InterruptedException{ connection = new Socket("127.0.0.1", READER_PORT);

in = new BufferedReader(new InputStreamReader(connection .getInputStream())); out = new PrintWriter(connection.getOutputStream());

Thread.sleep(500); System.out.println(readFromReader(in)); out.write("alien\n"); out.flush(); System.out.println(readFromReader(in)); Thread.sleep(500); out.write("password\n"); out.flush(); System.out.println(readFromReader(in)); }

/** * Tear down the connection * @throws IOException */ private void tearDown() throws IOException{ out.write("q"); out.flush(); connection.close(); }

/** * Get tags back from the alien reader * @return * @throws IOException */ private String getTags() throws IOException{ String command = "t"; out.write(command + "\n"); out.flush(); String returnVal = readFromReader(in); return returnVal; }

/** * @param args * @throws InterruptedException * @throws IOException */ public static void main(String[] args) throws IOException, InterruptedException { AlienExampleClient client = new AlienExampleClient(); client.init(); Thread.sleep(500); String tags = client.getTags(); System.out.println(tags); Thread.sleep(500); client.tearDown();

}

/** * Read responses from the socket * @param inBuf * @return * @throws IOException */ public static String readFromReader(BufferedReader inBuf) throws IOException{ StringBuffer buf=new StringBuffer(); int ch=inBuf.read(); while((char)ch!='\0'){ buf.append((char)ch); ch=inBuf.read(); } return buf.toString(); }

}

</pre>

Personal tools