This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Socket connection between servlets and applets

 
chris p
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 273
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18014
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
chris p
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic