Codetown ::: a software developer's community
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:
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:
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
* 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.
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.
Created by Michael Levin Dec 18, 2008 at 6:56pm. Last updated by Michael Levin May 4, 2018.
Check out the Codetown Jobs group.
The 18th annual QCon San Francisco conference was held at the Hyatt Regency San Francisco in San Francisco, California. This five-day event, organized by C4Media, consists of three days of presentations and two days of workshops. Day Two, scheduled on November 19th, 2024, included a keynote address by Lizzie Matusov and presentations from four conference tracks.
By Michael RedlichRecently, the GitHub Octoverse 2024 report revealed that Python has surpassed JavaScript as the most popular language on GitHub, primarily driven by its dominance in fields like data science, machine learning, and scientific computing. Generative AI continued its significant prominence in software development, with a substantial increase in contributions to generative AI projects on GitHub.
By Aditya KulkarniThe 18th annual QCon San Francisco conference was held at the Hyatt Regency San Francisco in San Francisco, California. This five-day event, organized by C4Media, consists of three days of presentations and two days of workshops. Day One, scheduled on November 18th, 2024, included a keynote address by Khawaja Shams and presentations from four conference tracks.
By Michael RedlichChinese researchers fine-tuned Llama-3.2-11B to improve its ability to solve multimodal reasoning problems by going beyond the direct-response or chain-of-thought (coT) approaches to reason step by step in a structured way. Named LLava-CoT, the new model outperforms its base model and proves better than larger models, including Gemini-1.5-pro, GPT-4o-mini, and Llama-3.2-90B-Vision-Instruct.
By Sergio De SimoneMicrosoft has launched Fabric API for GraphQL, moving the data access layer from public preview to general availability (GA). This release introduces several enhancements, including support for Azure SQL and Fabric SQL databases, saved credential authentication, detailed monitoring tools, and integration with CI/CD workflows.
By Robert Krzaczyński© 2024 Created by Michael Levin. Powered by