Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

send information from applet to server

andre666andre666 Posts: 1Member
Hello,

I want to write an applet for painting and I want to send the
result-picture to the server where the applet-code is stored.
But I have no idea how to do that. Does anyone know's an example
or can give me a hint.

thank's.


Comments

  • Josh CodeJosh Code Posts: 675Member
    I have an idea that I'm confident would work but it is a bit complicated. I'll explain the idea here:

    [b]Get the server to handle a file upload.
    [/b]
    Set up a server side script on the server. How you do this will depend on the server supporting server-side technology like PHP or something else. If you are familiar with handling a file upload using PHP, that is basically all you'd need.

    [b]Get the applet to send the image data as a file upload[/b]

    Any applet can send HTTP requests to the server as long as it is the same domain that the applet is in. For example, the applet at http://example.com/applet.html can send requests to example.com but it can't send to example2.com due to security limitations.

    The java.net.URL class can be used for sending GET-method requests but for simulating a file upload, you'll have to use POST. To do that, you can use java.io.Socket to connect with the server and implement the HTTP request yourself. The request header can be quite simple like:
    [code]
    POST /imageuploadhandler.php HTTP/1.1
    Encoding: multipart/form-data

    [/code]

    The body of the request would have to be encoded in a special format using parameters handled by your imageuploadhandler script. I made a web server a while ago with file upload support but can't remember all the formatting rules for multipart/form-data. I remember each parameter being split into multiple properties. The file contents is given with a marker at the beginning and marker at the end. The file size, file name are all separated. If you are serious about this, I suggest using Wireshark to take a look at messages from regular web browser file uploads so you can see how to replicate them.


    This might be a similar implementation of a similar idea that could avoid the complicated steps above:
    [link=http://www.javaatwork.com/]javaatwork[/link]



  • Josh CodeJosh Code Posts: 675Member
    Crucial to solving your problem is starting out with the ability to write server side scripts that can get work down on the back end. If you don't have these skills, I doubt there exists any solution to your problem.

    Another idea that is simpler than the file upload is to represent the image as vector data. If you collect the data on the server in a database, you could use small requests to just update the server on actions performed by the user. By keeping the messages small, you can pack the information into parameters of a GET request.

    When you need to rasterize the image, you could use some server side image drawing routines like PHP's GD and image functions.
Sign In or Register to comment.