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.

Views: 1940

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

Happy 10th year, JCertif!

Notes

Welcome to Codetown!

Codetown is a social network. It's got blogs, forums, groups, personal pages and more! You might think of Codetown as a funky camper van with lots of compartments for your stuff and a great multimedia system, too! Best of all, Codetown has room for all of your friends.

When you create a profile for yourself you get a personal page automatically. That's where you can be creative and do your own thing. People who want to get to know you will click on your name or picture and…
Continue

Created by Michael Levin Dec 18, 2008 at 6:56pm. Last updated by Michael Levin May 4, 2018.

Looking for Jobs or Staff?

Check out the Codetown Jobs group.

 

Enjoy the site? Support Codetown with your donation.



InfoQ Reading List

How to Tame Technical Debt in Software Development

According to Marijn Huizenveld, discipline is key to preventing accumulating technical debt. In order to be disciplined you should make it difficult to ignore the debt. Heuristics like fixing small issues immediately, agreeing on a timebox for improvement, and making messy things look messy, can help tame technical debt.

By Ben Linders

xAI Opens Grok as an Open-Source Model

Elon Musk announced that xAI would make its AI chatbot Grok open source, and now the release is accessible on GitHub and Hugging Face. This move enables researchers and developers to expand upon the model, influencing how xAI evolves Grok in the face of competition from tech giants like OpenAI, Meta, Google, Microsoft, and others.

By Daniel Dominguez

Presentation: Portfolio Analysis at Scale: Running Risk and Analytics on 15+ Million Portfolios Every Day

William Chen discusses the importance of trimming your computational graph, storing data in multiple formats, leveraging open source, and considering multiple dimensions of modularization.

By William Chen

Redis Switches to SSPLv1: Restrictive License Sparks Fork by Former Maintainers

Redis has recently announced a change in their license by transitioning from the open-source BSD to the more restrictive Server Side Public License (SSPLv1). The move has promptly led to a fork initiated by former maintainers and reignited discussions surrounding the sustainability of open-source initiatives.

By Renato Losio

DigitalOcean Introduces CPU-based Autoscaling for its App Plaform

DigitalOcean has launched automatic horizontal scaling for its App Platform PaaS, aiming to free developers from the burden of scaling services up or down based on CPU load all by themselves.

By Sergio De Simone

© 2024   Created by Michael Levin.   Powered by

Badges  |  Report an Issue  |  Terms of Service