I have to say that my question might sound very shallow vague, I can't explain it well enough I think. But I will try!
I have a hardware box running on Linux and using C implementation to handle the functionality of the box. I can connect the box to my Laptop via Ethernet, on the Laptop I create higher Layer input for the box.
How can I put this input through to the box?
I might need some light-weight implementation of a proxy, right?
What would be a fast and easy way to do that?
additional information:
On Java side I create ASN1 structures and encode them. These structures I want to pass via Ethernet into my little box, which will send out the data via wlan. Oh man, I realise that my knowledge maybe isn't enough to explain that problem. Ok... Hmm, I am done with encoding the ASN1 structures, but from that point I have no idea how to go on. Somehow there must be a way to indicate to the box that new data is passed through and the box should send it out. maybe like a remote proxy, calling methods in Java but they are executed as C-methods inside the box. Basically a transfer system is needed to pass information out of a Java environment into a C environment over Ethernet. Wooo, possible?
Thanks in advance.
nyyrikki
Since the input will go through Ethernet, I assume data will be encapsulated within packets.
I have no idea what your input data looks like, but I suggest using the Jpcap (available here : http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/).
Once you've messed around a bit with the API, it is really easy to learn and use.
I've personnaly used it a couple of times, and I have created a "Router" which acted as an ARP proxy. This lets me think you could use this library to achieve what you've explained.
Hope this helps!
Long time no see :)
I finally ended up using sockets, works well.
Thanks anyways, nyyrikki
Related
I would like to invoke a paste operation with my java application. Is this possible without using Robot?
For example, the application would invoke a paste operation every so often, so when I am writing in notepad, I would see the contents of my clipboard.
JAVA APP Notepad
clipboard.paste() --------> clipboardContents
It sounds as if you're trying to use Java to interact or partially drive another application (such as Windows NotePad) and paste to that application, and if so there are several possible solutions, one being use of Robot, another having Java make operating system calls, though this can't be done directly with just core Java and would require use of either JNI, JNA or other platform-specific non-core utility programs such as AutoIt (if this is for Windows).
Why are you dead set on not using Robot? Can you explain your needs in greater detail?
Edit
regarding your comment:
I want to explore alternatives to Robot, as my client irrationally rejects Robot.
Since this appears to be for a Windows platform, you might consider exploring the Windows API and the API for whatever non-Java program you're trying to drive (if one exists), and then using JNA to interact with it. The Windows User32.dll would allow you to get the Window handle (hWnd) of the application that you're trying to drive, which may be necessary for this to work.
It's hard to give more specific advice without more specific information from you about your problem though.
Edit 2
regarding your comments:
I would like the app to be platform independent.
Well, Robot comes to mind then. You might want to have a sit-down with your client to find out what they dislike so much about Robot, and then gently explain that it might offer the best path towards a platform-independent solution.
Are there examples for JNA and/or JNI? I'm not familiar with either.
Yes there are lots of examples on this and other sites, and Google will help you find out more. JNA is a bit easier to work with as it doesn't require you to create a C bridge program, but it can be a little slower than JNI, and doesn't work directly with C++ code (as far as I know).
Edit 3
regarding your comments:
I have a serial port listener (java app). I need to provide its contents onto a web browser. Clipboard seemed to be a way to do it.
And this is why it's so important for you to provide the context of your problem rather than what you think your code solution should be.
Communicating between applications is not an easy thing to do, and often Java is not the best tool for this since as it is designed to be as platform agnostic as possible, it does not provide tools that allow for easy integration with low-level OS functions. I don't know the best way to solve your problem, but my intuition tells me that using clipboard may not be the way to go. Much may depend on which web browser you're talking about, whether it has some sort of API that allows for interface with other programs, things I know little about. Also where is your program sitting? On the user's computer? Have you considered using a Java web browser library of some type, creating your own specialized web browser program, and obtaining the data directly from your serial port listener (again, I have not done this myself, but have seen it described on SO)?
I don't understand how bridging to a C program will help me.
I'm not suggesting this. This would only be needed if you used JNI, something I avoid since JNA is much easier (at least for me).
What is the best way to send "messages" from PHP script to Java program in real time. PHP script and Java programs are both working at the same work station with OS Windows. Maybe some kind of client/server? The main feature is real time; that's why I don't want to use files.
PS: I'm going to send logger messages (php) and display (java) them at OS system tray tooltip.
PPS: I'm real noob in Java; it will be my first Java program. :)
Thank you.
You could use sockets (probably UDP, but depends on your needs). This way, if in the future you will need to put scripts and Java programs on different machines, you'll be able to do that without modifing the code.
In addition, once you established a communication protocol between client and server, this solution is language independent. So it's easy switch from PHP to another scripting language (the same for Java).
This depend on how heavy weight your application is.
If it is your first program and it is just a little project, a possibility is to open a socket on the server, connect to it with a client and send the data as a string, make your php program the client and java program the server.
Their are things that you can borrow to avoid doing everything on the low level. But they will add weight to your program, for example using a JSON/XML parser to serialize(make the messages into bytes readable on both side) the message instead of using your own format.
Or, use a framework like JAX-RS to quickly and easily (for people familar with it, you may need some time to understand it because it is quite different from writing plain java program) to build a little web service like professionals would do.
Possibilities are:
Send your data as a POST to jsp page.
Make your java code read your php logs.
use queuing systems like RabbitMQ, AciveMQ, Redis etc.
For simplicity use a database table as exchange medium.
It is also easier to debug.
(It is asynchrone, one side, PHP or Java, may be down. Performance is fast, as DB-Server will keep as much in memory.)
I need a server. A simple one, to control a couple of computers. There are already a couple of programs in the lab, that perform some calculation and monitor tasks. They are executed on these computers. So I need a server to control them - to see the real time data from these computers, I want these programs to upload the calculation data to the server, upload also some files, that come together with this data. So the server needs to have a simple database. I also want to alter some of the calculation parameters in the realtime.
Because, you see, I'm a little tired of opening each computer with the terminal, looking at the process, get the files from each of the computers by ftp, put these files in the corresponding folder on the file storage, writing the schedule, when each program should continue it's work.
Maybe there is some middleware, that I can use for such needs? It should be simple and extensible. i thought of writing such server from scratch, it is not a big problem, but I have a severe time shortage and many other things to do.
And it would be cool, that this server would be developer-friendly. So I could just take it's API and write whatever I need.
I'm using Java, so it would be great, that this server would also "understand" Java. ;-) RMI is cool, but because of the network architecture, I'd prefer to use plain TCP/IP for these needs. Becacuse there is always problem with setting up RMI, when there computers are in differed subnetworks.
Thank you very much for your support in advance! Please help me, otherwise my girlfriend would break up with me, because I don't see her often spending most of my time at the lab... ;-(
I am almost finishing a software like that (actually 3 softwares) the server, the clients and the admin that logs into the server and command the clients.
My problem was specific so I had to go for a custom build from scratch (TCP/IP sockets). Its not hard, just write down the protocol.
If RMI doenst help you, then you must consider making your own proto, and you could exten and add new features later.
Maybe Google Protocol Buffers would help you to build your proto
http://code.google.com/p/protobuf/
Hmm, the two that spring to mind are Jetty and Glassfish. Depends a lot on what you need to do and how you want to go about it. Both are java based.
This seems like a problem for which Bundle-Bee was created for.
I've got a big problem with IBM HACL for accessing a server which speaks 3270 protocol. The library keeps crashing, and our JNI wrapper is actually a bug-fixing layer for the poorly-implemented and poorly-documented library (and I suspect we have introduced new bugs with it too). Moreover, in our company, everybody knows Java, and could maintain the software if we didn't have the JNI-Layer and the IBM class library.
We have to use the C++ class library, because the IBM Java library is unusable: we get every non-printable character translated, and we lose all control characters along the way.
Now the question is: can we ditch this library and implement our solution in Java completely (we'd like to avoid using another library from another vendor)? Is the protocol well documented? Is the implementation of 3270-over-ssl really so complex?
Thanks.
https://www.rfc-editor.org/rfc/rfc1041
so i guess its documented (assuming i hit the right doc)
couldnt find a java implementation though, you'd need to code it over telnet, or maybe SSH
I am unfamiliar with the differences between 3270 and 5250 data streams, but there is a 5250 implementation in Java in the tn5250j project available from http://tn5250j.sourceforge.net/
It might be usable for you?
(also there is a 3270 screen scraping project at http://freehost3270.sourceforge.net/ but it appears to be abandoned).
freehost3270 doesn't look as abandoned as it might appear - CVS has changes from 2 years ago. There is always an arguement that good code won't need to be changed that often in any case if the requirements have not altered. There have been complimentary comments wrt to the codebase. If you don't particularly want to work with other vendors products then working with this code/project seems to be your best option.
Freehost is not good code. Do not even bother trying it. There is a reason that it seems dead. JIN TN3270 is better but is incomplete. Ideally you want to find the API that your company's Emulator software uses. I am still searching for one for ours.
Another option would be h3270. It is a Java front-end to the x3270 suite of tools.
Does anybody know how to receive (how to know that you received) out-of-band data with Java sockets? In particular I've read the documentation for sendUrgentData and setOOBInline which states that:
Note, only limited support is provided for handling incoming urgent data. In particular, no notification of incoming urgent data is provided and there is no capability to distinguish between normal data and urgent data unless provided by a higher level protocol.
But I'm still hoping that somebody has a solution :-)
More details:
I'm sending serialized objects trough the socket and I'm not really seeing how I can find a "random" OOB byte inserted in the stream (other than the fact that Java will give me an exception when I'll try to deserialize the object).
Tomcat has a maintained implementation of JNI socket which can read urgent packets in a OOB manner.
It looks like Java, up to Java 6 (I didn't investigate Java 7 since I don't know if they've decided for sure what will go in or not) and it looks like Java does not provide any support at all for reading urgent TCP information in an out-of-band manner. And it looks like this is a deliberate choice, thus far.
However, I did find one user who implemented his own solution, using JNI, to successfully read urgent data out of stream. This hack is very old and may or may not work on recent JDK's. I have not tried this myself! Your milage may vary. :) But hopefully this will help you.