Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Transmitting / receiving hex values (Transmitting hex values using Java in Eclipse Indigo)
Transmitting / receiving hex values [message #882513] Wed, 06 June 2012 15:56 Go to next message
Tony Verrall is currently offline Tony VerrallFriend
Messages: 3
Registered: June 2012
Junior Member
I am new to the forums, and may have posted this to the wrong one - please help a newbie. Confused

As part of project to develop Android App, I need to be able to connect from the app to a set location, which has a small microprocessor based(unchangable) LAN interface, which will accept set commands in hex. The response is given in hex.

Using a sample socket program, which I have tried to modify (see code below), I can see (using wireshark) that the transmitted string is in ASCII, not hex, so I am sending 38 bytes, and not the 18 with the 0x prefix.

I have tried using a LONG, but the value I am trying to send is too large (see String process = '0x.....' midway through the code), and I get 'The literal 0x.... of type int is out of range.

I would appreciate someone pointing me in the right direction.

Thanks




// 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
* 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.199";
/** 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);
}
}
}
Re: Transmitting / receiving hex values [message #882520 is a reply to message #882513] Wed, 06 June 2012 16:01 Go to previous message
Russell Bateman is currently offline Russell BatemanFriend
Messages: 3798
Registered: July 2009
Location: Provo, Utah, USA
Senior Member

On 6/6/2012 9:56 AM, Tony Verrall wrote:
> I am new to the forums, and may have posted this to the wrong one -
> please help a newbie. :?
> As part of project to develop Android App, [snip]

Google chose Eclipse for Android development. Eclipse has nothing to do
with it. Please repost in a proper Android development forum. There are
some listed below:

http://www.javahotchocolate.com/tutorials/android.html#support
Previous Topic:XSD schema for html tag completion
Next Topic:Eclipse Juno creating files and directories in my home
Goto Forum:
  


Current Time: Fri Apr 19 22:27:31 GMT 2024

Powered by FUDForum. Page generated in 0.07669 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top