Java, Hyperterminal, File Transfer

Discussion in 'Java' started by JP, Oct 20, 2004.

  1. JP

    JP Guest

    Hi,

    I *really* need some help with a particular task I'm trying to
    accomplish...

    In essense, I want to dial up a number, bring up a terminal window,
    type in username, password, and then send a text file. There is a form
    that I need to fill out with info, and then I need to select a file
    and send it.

    I can do all this in Hyperterminal, but that's not what I want to do.
    I need to do this in Java, hopefully... and I've read the javax.comm
    things over and over, but I didn't really see how I'd populate a form
    or send a file using javax.comm package... if anyone has any sample
    code that'd be really great!

    Thank you very much!

    James
     
    JP, Oct 20, 2004
    #1
    1. Advertisements

  2. JP

    Rhino Guest

    Displaying a form or a series of forms which prompt users for information is
    not terribly hard. Doing a file transfer is not difficult either. I've done
    both in the same servlet.

    A couple of years ago, I created a simple prototype which asks users for
    information, then creates a zip file containing several files, one of which
    is a spontaneously-generated file containing a random "key". The servlet
    then takes the user to a download page where they can download this file. I
    didn't use javax.comm at all as far as I can recall. Would the code for that
    prototype help you? Or would a servlet solution not appeal to you?

    For what it's worth, I've never tried to dial a phone number or bring up a
    terminal window in my own code; I tend to use existing tools like telnet or
    sshwin for that ;-) However, if my prototype would help you, I'd be happy to
    send you the code, although it won't be as useful if you don't have a
    servlet container like Tomcat set up since you won't be able to execute the
    code or step through it with a debugger to see how it works.

    Is this a school assignment or are you doing real work, either for yourself
    or an employer?

    Rhino
     
    Rhino, Oct 20, 2004
    #2
    1. Advertisements

  3. JP

    Paul Lutus Guest

    This is not an automatic code creation machine. Please post your code and
    ask specific questions.
     
    Paul Lutus, Oct 20, 2004
    #3
  4. JP

    G Winstanley Guest

    But it seems that you might be an automaton Paul. Almost every post I see
    here from you is simply complaining that people don't post code. OP is
    asking for generic advice on solving a problem, which is a very valid reason
    for using this NG. He obviously requires direction rather than criticism.

    But I digress. My experience with javax.comm has been fairly unconstructive,
    but I had headaches with serial port timings for a specific device. My
    advice, James, would be to search Google (and other sources) as much as
    possible for related projects which use the JavaCOMM package. It doesn't
    seem to be as widely-used as I originally thought it might, which leads me
    to believe that many people have tried and then gone to other solutions.

    As for dialing, I've heard many people asking about it, but very few with
    answers. It's possible you will have some luck by looking at the JTAPI area
    of Sun's Java site.

    Stan
     
    G Winstanley, Oct 21, 2004
    #4
  5. JP

    Paul Lutus Guest

    And that problem is solved by having people post their code along with their
    code creation questions. The reply I gave, by the way, is hardly limited to
    me. All the regulars offer the same advice.
    Which criticism was that? Point it out.
    / ...
    And it would be tremendously beneficial if the OP were to post the code that
    causes the problem, along with any error message he sees. How does he know
    he has a problem? His code doesn't work. Where is the code?
     
    Paul Lutus, Oct 21, 2004
    #5
  6. JP

    JP Guest

    Sure, I understand.

    Here's a routine. The premise is that a connection to a remote
    computer has been established via modem and a phone line, and the
    remote computer has a form where a user needs to populate the
    destination username, and a subject, and then attach a file for
    sending. We are NOT connecting via the INTERNET. There is NO URL or
    anything like that. The connection is made by using the modem to DIAL
    A PHONE NUMBER into a remote computer... and then communicate with the
    remote computer and hopefully send a text file from the local box
    through the modem, using zmodem protocol...

    THIS BELOW DOES NOT WORK because I don't know how to send a file.

    ....
    outputStream = serialPort.getOutputStream();
    inputStream = serialPort.getInputStream();
    ....
    public void sendFile(){
    try {
    outputStream.write(username.getBytes()); //To:
    wait(2000);
    outputStream.write(TAB_KEY); //tab
    outputStream.write(65); //Subject: // A
    wait(2000);
    outputStream.write(TAB_KEY); //tab
    outputStream.write(TAB_KEY); //tab
    String filename = "C:\temp\test.txt"; // file name has
    been altered.
    outputStream.write(filename.getBytes()); //file name //A

    outputStream.write(ENTER_KEY); //
    while (true){
    inputStream.read();
    wait(50000);
    }
    } catch (IOException e) {
    System.out.println(e);
    e.printStackTrace();
    }
    }

    1) Are we correct to assume that by writing into the outputStream of
    the serialport object (through a combination of alphanumerics and
    tabs/enters, etc) we are in fact populating the form?
    2) How do we send a file? After we populate the form with a username,
    a subject line, and a file name, we then need to submit a file. In
    HyperTerminal, we do this by "Send/Receive File" functions... we need
    to write this obviously... do we just write ATSZ into the modem? What
    about the form that we read from the inputStream?

    Thanks in advance,

    James
     
    JP, Oct 21, 2004
    #6
  7. JP

    Paul Lutus Guest

    JP wrote:

    / ...
    The problem you face is that you have a single bidirectional serial stream
    for all communications with the client. You need to send command/display
    data as well as file data along this path.

    There are several apporoaches to solving this problem. Some are already
    written, but you can write your own. The latter might be a better approach.

    Suggestion. For all command/display information, send lines containing a
    label and text (name/value pairs). If the name specifies a form element,
    the value goes there. If the name specifies a command setting, the value is
    applied accordingly.

    For a file transfer, use a name of:

    file:(path/name):length (linefeed)

    On receipt of this command, the client will switch to a file download mode
    for the number of bytes specified in "length". When the file download is
    finished, the client will reply:

    checksum:(checksum) (linefeed)

    This will indicate that the file was received and the server can check the
    value of the checksum against the original file.

    Plenty has been left out of this brief summary, like dealing with dropped
    bytes and coping with errors. But it is best to use an 8-bit serial
    configuration, to simplify the file transfer requirement. Even this can be
    gotten around, but things get much more complex using less than 8-bit
    serial data.
     
    Paul Lutus, Oct 21, 2004
    #7
  8. JP

    G Winstanley Guest

    It was an indirect criticism of not posting any code, thereby not enabling
    anyone to help. It's simply not the case that a problem *requires* code
    submission to be answered usefully.
    I agree with this sentiment, but it's quite possible he has no code yet and
    is probing the community to find out if he can shortcut the process before
    writing code which has already been written by another. If code has already
    been written then I totally agree that posting it helps a great deal.
    Looking at the OP's post I find nothing that explicitly references that h
    has already written any code, so asking to see it so bluntly seems
    pointless.

    My minor gripe is that often I see complaints of no code, or perhaps
    requests for code, when in many cases it is simply not appropriate. For many
    who have a fair amount of coding experience this is fine as they will
    already have tried something which aims to fit the bill, but many are simply
    seeking advice before a potential coding disaster and they are in the NG to
    learn. (I know, try coding first and see where it gets you, but not everyone
    subscribed to that policy.) Anyhow, this is not the place to quibble such
    minor issues. We're all here to gain knowledge and help others. To put it
    simply...not every problem requires posted code.

    Stan

    P.S. JTides looks interesting. I'll take a closer look when I get a chance.
    Could come in useful for scuba diving trips.
     
    G Winstanley, Oct 21, 2004
    #8
  9. JP

    JP Guest

    Hello again,

    I just read through some more info and found out that apparently there
    are zmodem implementations in Java available, except I have to
    purchase them... I am not sure if purchasing is an option at this
    point, does anyone know of a free implementation of zmodem file
    transfer protocol that's in Java?

    If not, how about just some general ideas as to how I can implement
    zmodem protocol? Or is this a non-trivial task?

    Thank you,

    James
     
    JP, Oct 22, 2004
    #9
  10. JP

    Paul Lutus Guest

    That is not a criticism, unless all teaching is criticism in disguise.
    It is the case in this case.
     
    Paul Lutus, Oct 23, 2004
    #10
  11. JP

    JP Guest

    Hi,

    So does anyone have any insights to this file-transfer problem??

    Thank you,

    James
     
    JP, Nov 9, 2004
    #11
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.