Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

send socket from applet to servlet

 
Gauri Deshmukh
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9279
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Gauri Deshmukh
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9279
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic