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 :
Using java Syntax Highlighting
- // package bdn;
- /* The java.net package contains the basics needed for network operations. */
- import java.net.*;
- /* The java.io package contains the basics needed for IO operations. */
- import java.io.*;
- /** The SocketClient class is a simple example of a TCP/IP Socket Client.
- * For a detailed explanation of the classes in this project see
- * http://bdn.borland.com/article/0,1410,31995,00.html
- */
- public class SocketClient {
- public static void main(String[] args) {
- /** Define a host server */
- String host = "192.168.1.186";
- /** Define a port */
- int port = 3376;
- int i = 0;
- StringBuffer instr = new StringBuffer();
- // String TimeStamp;
- System.out.println("SocketClient initialized to " + host + ", port " + port );
- try {
- /** Obtain an address object of the server */
- InetAddress address = InetAddress.getByName(host);
- /** Establish a socket connection */
- Socket connection = new Socket(address, port);
- /** Instantiate a BufferedOutputStream object */
- BufferedOutputStream bos = new BufferedOutputStream(connection.
- getOutputStream());
- /** Instantiate an OutputStreamWriter object with the optional character
- * encoding.
- */
- OutputStreamWriter osw = new OutputStreamWriter(bos, "US-ASCII");
- // TimeStamp = new java.util.Date().toString();
- String process = "0x308101000c00234C51050000000099670007";
- System.out.println("Data to be sent is " + process) ;
- /** Write across the socket connection and flush the buffer */
- osw.write(process);
- osw.flush();
- System.out.println("Data sent is " + process) ;
- /** Instantiate a BufferedInputStream object for reading
- * incoming socket streams.
- */
- BufferedInputStream bis = new BufferedInputStream(connection.
- getInputStream());
- /**Instantiate an InputStreamReader with the optional
- * character encoding.
- */
- InputStreamReader isr = new InputStreamReader(bis, "US-ASCII");
- /**Read the socket's InputStream and append to a StringBuffer */
- int c;
- for (i = 0; i <= 18; i++ ) {
- c = isr.read() ;
- instr.append((char) c);
- System.out.println("character " + i + " value " + c);
- }
- /** Close the socket connection. */
- connection.close();
- System.out.println(instr);
- }
- catch (IOException f) {
- System.out.println("IOException: " + f);
- }
- catch (Exception g) {
- System.out.println("Exception: " + g);
- }
- }
- }
Parsed in 0.039 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

