CodeTown

www.codetown.us ::: a software developer's community

Sending strings between two computers via ethernet

A while ago I asked a question about using RS-232 communication with Java.  It seems as though I need to abandon that route because it no longer fits the desired system requirements.  Thanks to Nem for his advice on that one.

 

Now what I need to be able to do is send and receive strings between two computers connected via a network hub.  The computers in use would not be connected to the outside world and would only be communicating with each other at this point.

 

I need to be able to send a string like "auto" terminated with a carriage return when a button on a GUI is pressed by the user.  The GUI would then need to get back a string like "ok" or "err" also followed by a carriage return.

 

I am sure that I am making this much harder than I need to, so if anyone can help out it would appreciated.  For some reason I am having a lot of trouble absorbing how to use Java, so any help or explanations need to be in beginner terms.

 

Thanks.

Tags: ethernet, over, strings

Views: 349

Reply to This

Replies to This Discussion

Hi Paul,

 

So if I am not wrong, you want to run an application App1 on computer A, and an App2 on computer B, and then you want App1 to send a message to App2 and receive a reply, right?

 

If so, let me know and I can give you some pointers.

 

Cheers,

Behrang

Behrang:

 

Thanks for the reply.  Yes, I am looking for a way to send strings between two computers on a closed network.  App1 as you call it, will grow more complex as I figure out how to add the various sliders, buttons and so on.  App2 will not need to do much more than send a string that is either "OK" of "ERR" and display the incoming string in text field or label.

 

Any advice would be apprecitated.  Thanks again for your time.

 

 

Paul

Behrang:

 

Just wondering if you had any advice for me yet.

 

Thanks.

 

 

Paul


Behrang Saeedzadeh said:

Hi Paul,

 

So if I am not wrong, you want to run an application App1 on computer A, and an App2 on computer B, and then you want App1 to send a message to App2 and receive a reply, right?

 

If so, let me know and I can give you some pointers.

 

Cheers,

Behrang

Hi Paul,

 

Sorry for the long delay. It was a couple of busy weeks for me. I have written a program and pasted the code here:

 

http://paste.ly/CXuN

http://paste.ly/CXuQ

http://paste.ly/CXuR

http://paste.ly/CXuS

 

I have commented it a bit, but if you had more questions don't hesitate to ask me. A simpler example that can only handle one client and hence does not have the complexity associated with thread management is also available here:

 

http://download.oracle.com/javase/tutorial/networking/sockets/

 

Also the code I have uploaded is not complete enough: the only way to stop the threads is to quit the program.

Thanks Behrang!

 

I will give these a try.  I understand about the busy weeks.  That is kind why it is taking me so long to understand this.  I do not write code for a living and am trying to learn Java as my schedule permits, which is not all that often.

 

Thanks again.

 

 

Paul

Behrang:

 

Using the code you supplied and an example I found in one of my Java books I was able to open up connection between two laptops on my home network.  I think I can adapt the code to create a simplified version of the GUI I am trying to create.  Thanks so much for you assistance so far.

 

However, I do have a question.  Currently I am testing this on two laptops where I manually start the server code and then the client code.  In my real GUI, I will have a laptop or some other computer try to connect to a computer that is running MS-DOS and using an RS-232 to Ethernet converter.  In that case, I do not know how I can start a client application on the DOS machine.

 

The DOS machine is setup so that the RS-232 connection is always listening for incoming commands, that is why I was originally thinking about starting my GUI project using only RS-232.  I assume that will still be the case with the Ethernet converter.  I would also assume that my GUI would have to act as the client and ask to connect to the DOS computer.  I just need to figure out how to identify the Ethernet converter on the network.

 

Does my logic make sense?  Have you ever attempted something like this before?

 

Thanks.

 

Paul

Hi Paul,

 

You're welcome! 

 

Now back to the problem, could you please elaborate a little bit more about the the setup of your system? Is it something like this:

 

1- An MS-DOS system that acts as a server and is not running Java (Java cannot be installed on MS-DOS)

2- A Java GUI client that runs on a machine that has Java installed that tries to communicate with the MS-DOS server through TCP/IP (ethernet)

3- There's an app on the MS-DOS system that acts as a bridge between the ethernet and the RS-232 port

 

Or is it that you want to run Java on the MS-DOS machine as well? I think this won't be possible as Java is not available for MS-DOS.

 

Cheers,

Behrang

Behrang:

1- An MS-DOS system that acts as a server and is not running Java (Java cannot be installed on MS-DOS).

 

Yes, the MS-DOS computer is running a program called Hercules which provides automated control of a/v equipment used in planetariums like slide projectors, special effects, lights, video projectors and so on.  The software was written several years ago in assembly language because that provided the performance required to control up to 256 devices at 100 cues per second.  It was always intended to move the software to newer platform, but time and resources did not permit the necessary development.  The system was designed to take external commands from other computer systems via the RS-232 port.

I want to try using an RS-232 to Ethernet converter to allow the DOS machine to be accessible via a network.  I think it will work provided I can find a way to identify the Ethernet converter.

 

2- A Java GUI client that runs on a machine that has Java installed that tries to communicate with the MS-DOS server through TCP/IP (ethernet)

 

Yes, I want to build a GUI in Java that will live on another computer in the network.  The GUI will allow the user access to the DOS program without having to actually work in the DOS world.  This is only a temporary measure to provide a GUI to the existing version of the program.  A newer version of Hercules is in the planning stages, but a new platform has not yet been decided upon.

 

Since I cannot run a Java application on the DOS machine, I was hoping that I could connect to it if it was treated as the server.  I know I cannot run a server application, but if I can identify it on the network and it is always looking for incoming comm traffic, I thought my GUI could act as a client to connect to it.

 

 

3- There's an app on the MS-DOS system that acts as a bridge between the ethernet and the RS-232 port

 

I am hoping that the RS-232 to Ethernet converter will handle some of the connection issues.  It appears as though I can send a string to the converter and it will handle translating the string into the RS-232 protocol.  I should have the converter later this week and will be attempting to communicate through it.

 

I know that Java will not run on the DOS computer, but was hoping there was a work around for it provided I could get access to it via the network.  I hope this helps to clarify what I am trying to accomplish.

 

 

Paul

 

 

Thanks for the elaboration. I think your logic makes sense. I haven't done something similar to this before, but as you've already mentioned, as long as you can make the ethernet controller and the ethernet-to-RS-233 converter work, you can use Java sockets* to communicate with the server. In case you've already encountered a problem setting up the ethernet controller let me know and I might be able to provide some help.

 

* However it might be that you need to communicate with the server over the UDP protocol rather than TCP. In that case your app would need to use DatagramSocket (example here) to communicate with the server.

Thanks for your support.  I should be able to perform a test later this week with an actual system setup.  I do not have all the pieces here with me, so a lot of this has been theory and work arounds.

 

I will let you know if I have any success.  Stay tuned.

Behrang:

 

I wanted to let you know that after a little trouble with the string being sent, I was successful in getting the DOS program to receive and execute command strings that I sent from my GUI.  I had some issues finding the right method to use in sending the strings.

 

I saw that you used println() in your example, but I noticed this automatically included a carriage return and line feed.  The carriage return was fine, but the line feed caused an error.

 

I tried using writeChars(), but this sent the ASCII characters as two bytes for Unicode.  The DOS program saw the string, but was not written to handle the Unicode version of ASCII so it kicked back an error.

 

After some research I found the writeBytes() method which sent the ASCII characters as one byte and success was had along with much rejoicing.  Now that I had communication between my GUI and the DOS program, I have to make the GUI pretty.  I have several sliders and check boxes to add for the necessary functionality.

 

Eventually I want to add a timeline feature where I can set up several commands to execute at a specific time code.  I would like it to look something like the time line that is used in Adobe After Effects, Premiere, or Audition.  You would not know where I might look to tackle that problem would you?

 

Thanks again for you assistance.  When I get stuck again, and I will, I will post a new question.

 

 

Paul

Hi Paul,

 

That's great news!

 

I haven't used any of the products that you have mentioned in your post, but regarding scheduling commands to be executed at certain points in time, one option is to use java.util.Timer. It has methods for scheduling code (tasks) to be executed at a given date, or at a given fixed rate (e.g. once every two hours). Here's an example.

 

For a more sophisticated scheduling system, IMHO the most popular library in the Java world is the Quartz Scheduler. Using Quartz you can express schedules using cron expressions. Here's the tutorial for Quartz.

Reply to Discussion

RSS

Translate Codetown

Looking for Jobs or Staff?

Check out the Codetown Jobs group. There's also a free Jobs mailing list.

 

 



Enjoy the site? Support Codetown with your donation.




Reading List

HowStuffWorks "How Cloud Computing Works"

In a cloud computing system, there's a significant workload shift. Local computers no longer have to do all the heavy lifting when it comes to running applications. The network of computers that make up the cloud handles them instead. Hardware and software demands on the user's side decrease. The only thing the user's computer needs to be able to run is the cloud computing system's interface software, which can be as simple as a Web browser, and the cloud's network takes care of the rest...

What cloud computing really means | Cloud Computing - InfoWorld

Cloud computing is all the rage. "It's become the phrase du jour," says Gartner senior analyst Ben Pring, echoing many of his peers. The problem is that (as with Web 2.0) everyone seems to have a different definition...

Cloud computing - Wikipedia, the free encyclopedia

Cloud computing is the delivery of computing as a service rather than a product, whereby shared resources, software, and information are provided to computers and other devices as a utility (like the electricity grid) over a network (typically the Internet).

Eclipse DemoCamps November 2011 - Eclipsepedia

From November 1-30, we are inviting individuals to organize and attend Eclipse 10th Birthday Parties around the world! Click the link to see details.

YouTube Founders Aim to Revamp Delicious - NYTimes.com

Chad Hurley and Steve Chen have some experience with turning a small Web site into Internet gold. In 2006 they sold their scrappy start-up YouTube to Google for $1.65 billion. Jim Wilson/The New York Times The Delicious office in San Mateo, Calif. It now has around 15 employees, mostly engineers. More recently they picked an unlikely candidate to be their next Web sensation: a Yahoo castoff.
Locations of visitors to this page


Codetown on Facebook

© 2014   Created by Michael Levin.

Badges  |  Report an Issue  |  Terms of Service