Accessing Remote Gateway

Put your problem here if it does not fit any of the other categories.

Accessing Remote Gateway

Postby ManxAnts » Wed Jul 18, 2012 10:50 am

Hi

I am fairly new to Java and am having a problem trying to access a remote Gateway as it only accepts hex values and responds with hex. I have been working with Sockets, and can see, using Wireshark that my values are being sent as individual ascii values, rather than as hex characters. I have tried a variety of alternatives such as bigint, and char arrays, but can't get a sensible solution.

This is what I have :

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. // package bdn;
  2. /*  The java.net package contains the basics needed for network operations. */
  3. import java.net.*;
  4. /* The java.io package contains the basics needed for IO operations. */
  5. import java.io.*;
  6. /** The SocketClient class is a simple example of a TCP/IP Socket Client.
  7.  * For a detailed explanation of the classes in this project see
  8.  * http://bdn.borland.com/article/0,1410,31995,00.html
  9.  */
  10.  
  11. public class SocketClient {
  12.  
  13.   public static void main(String[] args) {
  14.     /** Define a host server */
  15.     String host = "192.168.1.186";
  16.     /** Define a port */
  17.     int port = 3376;
  18.     int i = 0;
  19.  
  20.     StringBuffer instr = new StringBuffer();
  21. //    String TimeStamp;
  22.     System.out.println("SocketClient initialized to " + host + ", port " + port );
  23.  
  24.     try {
  25.       /** Obtain an address object of the server */
  26.       InetAddress address = InetAddress.getByName(host);
  27.       /** Establish a socket connection */
  28.       Socket connection = new Socket(address, port);
  29.       /** Instantiate a BufferedOutputStream object */
  30.       BufferedOutputStream bos = new BufferedOutputStream(connection.
  31.           getOutputStream());
  32.  
  33.       /** Instantiate an OutputStreamWriter object with the optional character
  34.        * encoding.
  35.        */
  36.       OutputStreamWriter osw = new OutputStreamWriter(bos, "US-ASCII");
  37.  
  38. //      TimeStamp = new java.util.Date().toString();
  39.       String process = "0x308101000c00234C51050000000099670007";
  40.      
  41.       System.out.println("Data to be sent is " + process) ;
  42.      
  43.       /** Write across the socket connection and flush the buffer */
  44.       osw.write(process);
  45.       osw.flush();
  46.      
  47.       System.out.println("Data sent is " + process) ;
  48.  
  49.       /** Instantiate a BufferedInputStream object for reading
  50.        * incoming socket streams.
  51.        */
  52.  
  53.       BufferedInputStream bis = new BufferedInputStream(connection.
  54.           getInputStream());
  55.       /**Instantiate an InputStreamReader with the optional
  56.        * character encoding.
  57.        */
  58.  
  59.       InputStreamReader isr = new InputStreamReader(bis, "US-ASCII");
  60.  
  61.       /**Read the socket's InputStream and append to a StringBuffer */
  62.       int c;
  63.       for (i = 0;  i <= 18; i++ ) {
  64.           c = isr.read() ;
  65.           instr.append((char) c);
  66.           System.out.println("character " + i + " value " + c);
  67.     }
  68.    
  69.       /** Close the socket connection. */
  70.       connection.close();
  71.       System.out.println(instr);
  72.      }
  73.     catch (IOException f) {
  74.       System.out.println("IOException: " + f);
  75.     }
  76.     catch (Exception g) {
  77.       System.out.println("Exception: " + g);
  78.     }
  79.   }
  80. }
  81.  
Parsed in 0.040 seconds, using GeSHi 1.0.8.4


I get the impression from various forums that sending hex is a problem. I can not change the Gateway in anyway, so any help would be most welcome to code it from the Android side. - Thanks
ManxAnts
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Jul 18, 2012 10:30 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: MSNbot Media and 13 guests