Java

Moderators: zibadian
Number of threads: 7818
Number of posts: 18218

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
send information from applet to server Posted by andre666 on 16 Oct 2010 at 8:34 AM
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.


Report
Re: send information from applet to server Posted by Josh Code on 3 Nov 2010 at 11:06 PM
I have an idea that I'm confident would work but it is a bit complicated. I'll explain the idea here:

Get the server to handle a file upload.

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.

Get the applet to send the image data as a file upload

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:
POST /imageuploadhandler.php HTTP/1.1
Encoding: multipart/form-data



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:
javaatwork



Report
Re: send information from applet to server Posted by Josh Code on 20 Nov 2010 at 5:39 PM
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.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.