Page 1 of 1
Java Programming
Posted: 2005-01-22 10:35pm
by Dark Sider
I am looking for someone who has a pretty good grasp on Java Internet programming. I am trying to put together a Java server that sends multiple pieces of data through a TCP stream and then have a client receive them that is programmed in LabVIEW.
Posted: 2005-01-23 12:02am
by CDS
The initial reaction that springs to mind is.. why Java? Java's only advantage as far as I can see is that it can be used on multiple platforms with little fuss. Theres no need for this advantage if it's going to be on the server. May I recommend a nicer language for the job such as C?
Also, WTF os LabVIEW?
Posted: 2005-01-23 12:34am
by Dark Sider
I decided on Java because there are professors who are familiar with it at my school. Java seems a tad bit easier when it comes to the whole objected oriented nature and easier to program. We are using a DSTINIm400 which has a Java runtime environment so it just seemed natural.
I can do a google search on Java network programming but I get the same old boring Echo server and Daytime server examples. I am trying to see how to send multiple pieces of data into the TCP stream and pull them out correctly in LabVIEW (Laboratory Virtual Instrument Engineering Workbench). It is a programming "language" by National Instruments. It is some powerful stuff.
If I posted my Java code, would you be able to help me with it?
Posted: 2005-01-23 06:48am
by CDS
Dark Sider wrote:I decided on Java because there are professors who are familiar with it at my school.
Don't presume your professors will help you with your personal work
Java seems a tad bit easier when it comes to the whole objected oriented nature and easier to program.
IMPO, I don't like the way it handles it all.
We are using a DSTINIm400 which has a Java runtime environment so it just seemed natural.
You can install others
If I posted my Java code, would you be able to help me with it?
I can't promise anything, since Java isn't my strong language.
Posted: 2005-01-23 09:38am
by Arrow
I'll throw in my two cents.
First off, I have to agree with CDS - C or C++ are superior to Java. Java babysits you and places some serve restrictions on how you can access memory and operate on data. Something than can be done in C/C++ with a few math operators and a couple of pointers becomes a nasty beast in Java.
C/C++ has a lot of TCP examples that you should be able to take advantage of (its possible you may only need to slightly modify them to get them to work with your code).
Also, I've worked with an A/D card for National Instruments and I've worked with Acqiris's A/D drivers, both of which support LabVIEW. While I haven't worked with LabVIEW myself, looking at how the calls are made in these A/D drivers and what they are moving around in memory, C/C++ will be a better solution for you.
Now, if you still want to use Java, you can post the code if you want. Its been a while since I've worked in Java, and my network programming experience is limited, so I'm not sure how much help I'll be. Also, example code written in ANSI C++ can usually be translated in Java without a of fuss; I believe Java is fair good at matching the ANSI calls.
And, if all else fails, head out to the local bookstore and shell out $60 on a big, meaty Java book. One of the ones I've used actually had an example about what you're talking about.
Posted: 2005-01-23 02:16pm
by Drooling Iguana
Or, if you want something a bit higher-level and easier to work with than C/C++, you could give
Python a shot. It has pretty much all the advantages of Java (object-orientation, automatic memory allocation/deallocation, ability to compile to bytecode to run on multiple platforms) but it's, imho, much better designed, being created from the ground up for its intended purpose rather than just being "C++ with training wheels" like Java is, and it can be used as a directly-interpreted scripting language as well, making it more suitable for small, quickly made programs than either Java or C.
There's a book on the subject available online for free
here.
Posted: 2005-01-23 02:23pm
by Arrow
Drooling Iguana wrote:Or, if you want something a bit higher-level and easier to work with than C/C++, you could give
Python a shot. It has pretty much all the advantages of Java (object-orientation, automatic memory allocation/deallocation, ability to compile to bytecode to run on multiple platforms) but it's, imho, much better designed, being created from the ground up for its intended purpose rather than just being "C++ with training wheels" like Java is, and it can be used as a directly-interpreted scripting language as well, making it more suitable for small, quickly made programs than either Java or C.
There's a book on the subject available online for free
here.
I don't think LabVIEW has a Python interface, which kinda defeats the purpose.
Posted: 2005-01-23 03:38pm
by Dark Sider
Here is my code...I think it is correct but I want to make sure it is correct. I was told it would be a good idea to send the length of a piece of data then actually send the data through the TCP stream. I am unsure of a command that sends the length of an integer, double, float, array etc etc. I know I can do it with a string for instance...mystring.length(mystring) -- I think that is the command anyway. If you all think it would be easier to do this in C++ I would appreciate any help or guidance with the coding. I have a C++ example as well! Thank you all for your help.
package examples;
import java.net.*;
import java.io.*;
public class BWTCPServer {
public static final int TCP_PORT = 2055;
public static void main(String args[]) {
try {
int a = 10;
int b = 15;
ServerSocket server = new ServerSocket(TCP_PORT);
int size = server.getReceiveBufferSize();
System.out.println("BioWave Server activated");
System.out.println("Size of receive buffer is: " + size);
for(;;) {
Socket nextClient = server.accept();
System.out.println("Received request from " + nextClient.getInetAddress()
+ nextClient.getPort());
OutputStream out = nextClient.getOutputStream();
PrintStream pout = new PrintStream(out);
pout.print(a);
pout.print(b);
//for ( int i = 0; i < a.length(); ++i )
//{
// char c = a.charAt( i );
// int j = (int) c;
// String hexstr = Integer.toHexString(j);
//System.out.println(hexstr);
//}
String intstr = Integer.toHexString(a);
System.out.println(a);
System.out.println(b);
out.flush();
out.close();
nextClient.close();
}
}
catch (BindException be) {
System.err.println("Service already running on port " + TCP_PORT);
}
catch (IOException ioe) {
System.err.println("I/O error - " + ioe);
}
}
}
Posted: 2005-01-23 03:46pm
by CDS
for(;;) {
Might wanna disable BbCode there
Posted: 2005-01-23 04:59pm
by Arrow
CDS wrote: for(;;) {
Might wanna disable BbCode there
I think there is a <code></code> tag available, as well. Yeah, there is, right next to "Quote", below the subject field.
Off hand, looks good, but its hard to tell with the formatting.
To pass your sizes, you should pass the length of the array of you're copying from, and if you have arrays of differents types, pass an enum indicating type.
C/C++, you can use sizeof() to tell what the size of a data type is, but it wouldn't help much (after all, a Windows int and float have the same size, as does a short int and unicode 16 character), so you still need to the same thing.
Posted: 2005-01-25 01:37pm
by Lord MJ
I could be considered a Java guru (at least in comparison to most on this board)
But it's been a while since I worked with sockets, so I'm not sure how much help I could be.
What I do know is that Java's networking apis are great and very useful, espescially in the latest versions.
Posted: 2005-01-26 01:41pm
by Eleas
Lord MJ wrote:I could be considered a Java guru (at least in comparison to most on this board)
But it's been a while since I worked with sockets, so I'm not sure how much help I could be.
What I do know is that Java's networking apis are great and very useful, espescially in the latest versions.
As long as you don't use Swing libraries...
Posted: 2005-01-26 03:29pm
by Vain
I can second the suggestions for C, or C++. I've done work with LabVIEW and TCP/IP before, and all of the backend stuff was written in some flavor of C.
As an aside, LabVIEW is nice in that a trained monkey can use it, but I don't know that I agree that it's 'powerful'. It's useful for hacking together a prototype or proof of concept for something that will end up being a printed circuit board (that's what we used it for, at least), but it's pretty abstract. It's useful for me as a CS major. I think it would be like trying to design something with legos for a trained electrical engineer.
Posted: 2005-01-26 07:17pm
by CDS
Eleas wrote:As long as you don't use Swing libraries...
Whoa... swing.. don't *ever* use that word in front of me...
Posted: 2005-01-26 07:19pm
by Eleas
CDS wrote:
Whoa... swing.. don't *ever* use that word in front of me...
Lemme guess... you don't swing that way?
Posted: 2005-01-26 07:24pm
by CDS
Eleas wrote:CDS wrote:Whoa... swing.. don't *ever* use that word in front of me...
Lemme guess... you don't swing that way?
Y'know, there really needs to be some kind of punishment for that level of badness in puns!
Posted: 2005-01-26 07:44pm
by Eleas
CDS wrote:Eleas wrote:CDS wrote:Whoa... swing.. don't *ever* use that word in front of me...
Lemme guess... you don't swing that way?
Y'know, there really needs to be some kind of punishment for that level of badness in puns!
Feeling violent, are we? Want to take a swing at me?
Posted: 2005-01-27 02:23am
by CDS
Eleas wrote:Feeling violent, are we? Want to take a swing at me?
I will after your next one!
Posted: 2005-01-27 10:58am
by Eleas
CDS wrote:Eleas wrote:Feeling violent, are we? Want to take a swing at me?
I will after your next one!
Just swing by Sweden and we'll discuss it.
Posted: 2005-01-27 04:12pm
by CDS
aargh! *cries*