Java Programming
Moderator: Thanas
-
- Fundamentalist Moron
- Posts: 129
- Joined: 2004-01-16 10:23pm
Java Programming
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.
I'm a fucktard and you can reach me at princessvenus2@juno.com
- CDS
- Padawan Learner
- Posts: 301
- Joined: 2004-12-15 03:55pm
- Location: Lancaster University, UK
- Contact:
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?
Also, WTF os LabVIEW?
"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." --Albert Einstein
nimoll.co.uk technology website | N forums | Nimoll web design and hosting | Macguide
-
- Fundamentalist Moron
- Posts: 129
- Joined: 2004-01-16 10:23pm
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?
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?
I'm a fucktard and you can reach me at princessvenus2@juno.com
- CDS
- Padawan Learner
- Posts: 301
- Joined: 2004-12-15 03:55pm
- Location: Lancaster University, UK
- Contact:
Don't presume your professors will help you with your personal workDark Sider wrote:I decided on Java because there are professors who are familiar with it at my school.
IMPO, I don't like the way it handles it all.Java seems a tad bit easier when it comes to the whole objected oriented nature and easier to program.
You can install othersWe are using a DSTINIm400 which has a Java runtime environment so it just seemed natural.
I can't promise anything, since Java isn't my strong language.If I posted my Java code, would you be able to help me with it?
"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." --Albert Einstein
nimoll.co.uk technology website | N forums | Nimoll web design and hosting | Macguide
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.
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.
Artillery. Its what's for dinner.
- Drooling Iguana
- Sith Marauder
- Posts: 4975
- Joined: 2003-05-13 01:07am
- Location: Sector ZZ9 Plural Z Alpha
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.
There's a book on the subject available online for free here.
"Stop! No one can survive these deadly rays!"
"These deadly rays will be your death!"
- Thor and Akton, Starcrash
"Before man reaches the moon your mail will be delivered within hours from New York to California, to England, to India or to Australia by guided missiles.... We stand on the threshold of rocket mail."
- Arthur Summerfield, US Postmaster General 1953 - 1961
"These deadly rays will be your death!"
- Thor and Akton, Starcrash
"Before man reaches the moon your mail will be delivered within hours from New York to California, to England, to India or to Australia by guided missiles.... We stand on the threshold of rocket mail."
- Arthur Summerfield, US Postmaster General 1953 - 1961
I don't think LabVIEW has a Python interface, which kinda defeats the purpose.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.
Artillery. Its what's for dinner.
-
- Fundamentalist Moron
- Posts: 129
- Joined: 2004-01-16 10:23pm
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);
}
}
}
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);
}
}
}
I'm a fucktard and you can reach me at princessvenus2@juno.com
- CDS
- Padawan Learner
- Posts: 301
- Joined: 2004-12-15 03:55pm
- Location: Lancaster University, UK
- Contact:
Might wanna disable BbCode therefor(;;) {
"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." --Albert Einstein
nimoll.co.uk technology website | N forums | Nimoll web design and hosting | Macguide
I think there is a <code></code> tag available, as well. Yeah, there is, right next to "Quote", below the subject field.CDS wrote:Might wanna disable BbCode therefor(;;) {
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.
Artillery. Its what's for dinner.
As long as you don't use Swing libraries...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.
Björn Paulsen
"Travelers with closed minds can tell us little except about themselves."
--Chinua Achebe
"Travelers with closed minds can tell us little except about themselves."
--Chinua Achebe
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.
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.
- CDS
- Padawan Learner
- Posts: 301
- Joined: 2004-12-15 03:55pm
- Location: Lancaster University, UK
- Contact:
Whoa... swing.. don't *ever* use that word in front of me...Eleas wrote:As long as you don't use Swing libraries...
"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." --Albert Einstein
nimoll.co.uk technology website | N forums | Nimoll web design and hosting | Macguide
- CDS
- Padawan Learner
- Posts: 301
- Joined: 2004-12-15 03:55pm
- Location: Lancaster University, UK
- Contact:
Y'know, there really needs to be some kind of punishment for that level of badness in puns!Eleas wrote:Lemme guess... you don't swing that way?CDS wrote:Whoa... swing.. don't *ever* use that word in front of me...
"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." --Albert Einstein
nimoll.co.uk technology website | N forums | Nimoll web design and hosting | Macguide
Feeling violent, are we? Want to take a swing at me?CDS wrote:Y'know, there really needs to be some kind of punishment for that level of badness in puns!Eleas wrote:Lemme guess... you don't swing that way?CDS wrote:Whoa... swing.. don't *ever* use that word in front of me...
Björn Paulsen
"Travelers with closed minds can tell us little except about themselves."
--Chinua Achebe
"Travelers with closed minds can tell us little except about themselves."
--Chinua Achebe
- CDS
- Padawan Learner
- Posts: 301
- Joined: 2004-12-15 03:55pm
- Location: Lancaster University, UK
- Contact:
I will after your next one!Eleas wrote:Feeling violent, are we? Want to take a swing at me?
"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." --Albert Einstein
nimoll.co.uk technology website | N forums | Nimoll web design and hosting | Macguide
- CDS
- Padawan Learner
- Posts: 301
- Joined: 2004-12-15 03:55pm
- Location: Lancaster University, UK
- Contact:
aargh! *cries*
"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." --Albert Einstein
nimoll.co.uk technology website | N forums | Nimoll web design and hosting | Macguide