aspose file tools*
The moose likes Applets and the fly likes send socket from applet to servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "send socket from applet to servlet" Watch "send socket from applet to servlet" New topic
Author

send socket from applet to servlet

Gauri Deshmukh
Greenhorn

Joined: Dec 25, 2004
Posts: 12
HI,
I have an applet which creates a socket to a server . I want to be able to send this socket to a servlet. I am sending a string from the applet to the servlet (using writeObject) but that doesn't work for sending the socket . I keep getting a "not serializable" error. I set the requestProperty as follows:
servletConnection2.setRequestProperty("Content-Type","application/octet-stream");

How can I send a socket from applet to a servlet.
thanks in advance.
G.
[ January 06, 2005: Message edited by: Gauri Deshmukh ]
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8964
    
    9

Can't be done. The simple answer is that java.net.Socket does not implement java.io.Serializable and therefore cannot be serialized (see the . Java Tutorial: Object Serialization for more about that).
The more in-depth answer is that a socket is not a resource like a file which can be read in and transmitted. It is an operating system abstraction of a very real, physical thing: the network cable plugged into the back of your computer. What you are trying to do is like trying to stuff one end of your network cable in an envelope and mail it to a friend. It won't get far!


[How To Ask Questions On JavaRanch]
Gauri Deshmukh
Greenhorn

Joined: Dec 25, 2004
Posts: 12
HI Joe,

I have another question, can I send the port number (for the local socket) from the applet to servlet and retrieve the actual socket on the servlet side?
Let me know.
Thanks,
G.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8964
    
    9

Bind to a local port in the applet and send the port number to the server like you were above? I don't see any problem.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: send socket from applet to servlet