File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Socket connection between servlets and applets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Socket connection between servlets and applets" Watch "Socket connection between servlets and applets" New topic
Author

Socket connection between servlets and applets

chris p
Greenhorn

Joined: Oct 16, 2001
Posts: 6
hey guys,
i'm currently trying to create a little web application for my school to assist with the live internet broadcast of speakers that they run.
i understand that it is possible to create a socket level connection between a servlet and an applet, but i cannot find any documentation on how to do so. i know a decent amount about servlets and a decent amout about applets, but i know little technically about having the two communicate. could someone please explain how i would do this? any code snipets would be much appreciated.
Bal Sharma
Ranch Hand

Joined: Sep 19, 2001
Posts: 273
Hey Chris:
I think you need a book JAVA Developer's Guide to Servlets and JSP by Bill Brogden. I bought this book thinking it only focus on Servlet and JSP, nah! I was wrong. Chapter 12 of this book Applet - to - Servlet Communication that what you wanted. I have not read yet that chapter. I am pulling my hair on ch3 CHATROOM to understand session tracking. I do not know when I will have decent amount of servlets understanding.
Good Luck. BK

i know a decent amount about servlets and a decent amout about applets, ... i know little technically about having the two communicate. could someone please explain how i would do this? any code snipets would be much appreciated.

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16012
    
  19

The magic word is URLConnection. If your applet creates one of these, it can internally send and receive web requests. If you use straight sockets you end up having to do the grunt work yourself (among other things, URLConnections make working with sessions easier). Also, anything that uses TCP/IP ports other than standard http (or https) ports won't make it through most firewalls.
Beyond that, you really need to go to a good book on Java Network programming. Or at least a book with a good chapter on this kind of stuff.


Customer surveys are for companies who didn't pay proper attention to begin with.
chris p
Greenhorn

Joined: Oct 16, 2001
Posts: 6
yeah, the reason i want to use sockets is so that i can use the mvc notifier model. i have a back-end object model, and i'm using the servlet as the controller, and the applets as the view. i was hoping to just send the updates to and from the clients as nessecary. Also i'm banking on the fact that the ports are closed on the firewall, i don't want people outside the network using it. That's why i want to use sockets. I just don't know how.
I know that an applet can make a url connection to a servlet, but after that, how do i make a bi-directional socket level connection between the two. I already have a socket level protocol drawn out. I just need to know how to establish the connection.
Thanks again.
ps. bal, i havn't gotten a chance to look at that book yet, but thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Socket connection between servlets and applets