Results 1 to 5 of 5

Thread: Servlets comunication with Applets

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Posts
    843

    Servlets comunication with Applets

    Hi... I am making the fomous and well known : "Chat Program"

    I want to do it with servlets and applets. I did some research and I founf that servlets take post from an HTML page to comunicate with the client. With an Applet you could send data thru a URL object and get it in the servlets like if it were a GET POST. So.. far.. I am doing ok. Now... how do I comunicate from the Servlet to the Applet?!?!?! Any ideas?

    Thank you for any help!
    "The difference between mad and genius is the success"

  2. #2
    Hyperactive Member CaptainPinko's Avatar
    Join Date
    Jan 2001
    Location
    London, Ontario, Canada
    Posts
    332
    use a HTTP socket?

    java.net.*

    look into sockets and serversockets or something of that name-like, though you may have problems b/c applets have alot of security mamager restrictions placed on them
    "There are only two things that are infinite. The universe and human stupidity... and the universe I'm not sure about." - Einstein

    If you are programming in Java use www.NetBeans.org

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Posts
    843
    Yes... I alredy did the chat program with Sockets and ServerSockets.... it works really nice.... in my computer. But in public free servers they dont let you run java pro using sockets since you have to take over a port. (even thoug there is like 36665 ports... or something like that).

    I was thinking to use the URL class to get information from the servlet now... If somebody can help me... how, for example, can I get the HTML CODE with and URL from lets say.... www.yahoo.com/something.html?

    Thank you
    "The difference between mad and genius is the success"

  4. #4
    Addicted Member
    Join Date
    Nov 2001
    Location
    Yewston, Texis
    Posts
    240
    Yep, there's a problem there because your http connection is normally used for a quick 2 way communication: applet->servlet and an immediate servle->applet response. Web servers often are able to send data to idling browsers, like traffic web pages that send an update every minute. I would think that you would be able to do a similar thing so that when a chat response finally comes in, the applet will receive the information from the servlet.

    What about the design of this thing? You will need to think about what's going to happen. If you have three users, you will have three servlet instances running (one servlet replicated three times) How will one instance of the servlet talk to another instance? One clue is you can use static variables which will have consistent values for all instances of the servlets.

    cudabean

  5. #5
    Hyperactive Member CaptainPinko's Avatar
    Join Date
    Jan 2001
    Location
    London, Ontario, Canada
    Posts
    332
    you could also use sockets that connect to ports on the loop back address: 127.0.0.1 or writing to a file, but that would be slow, but convient for one-time data (like user lists or something) not the messages themselves
    Last edited by CaptainPinko; Mar 15th, 2002 at 12:04 PM.
    "There are only two things that are infinite. The universe and human stupidity... and the universe I'm not sure about." - Einstein

    If you are programming in Java use www.NetBeans.org

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width