port listen/send

Discussion in 'Javascript' started by 1388-2/HB, Sep 16, 2005.

  1. 1388-2/HB

    1388-2/HB Guest

    Is JavaScript able to send/listen for data on a specific port? I'm seeking
    a solution to real time data interaction with my web server that doesn't
    require refreshing the page. I.e., a chat room, where the data can be
    broadcast from the server arbitrarily and displayed by the client
    browser(s). To accomplish the data transmission can I use JS, or do I need
    to augment my client-side platform to something like Java, et al?
    1388-2/HB, Sep 16, 2005
    #1
    1. Advertising

  2. 1388-2/HB

    Erwin Moller Guest

    1388-2/HB wrote:

    > Is JavaScript able to send/listen for data on a specific port? I'm
    > seeking a solution to real time data interaction with my web server that
    > doesn't
    > require refreshing the page. I.e., a chat room, where the data can be
    > broadcast from the server arbitrarily and displayed by the client
    > browser(s). To accomplish the data transmission can I use JS, or do I
    > need to augment my client-side platform to something like Java, et al?


    Hi,

    Javascript is not suited/able to directly open sockets and such actions.
    However, you can relatively easy accomplish the same functionality by
    incorperating a server into your application.
    eg: JS can use a hidden frame to load/read info that comes from a server.
    You can also use the XMLHTTPRequest-object to circumvent the hidden frame.

    You need a serverside scriptinglanguage (like PHP) to produce information
    you want.

    A rude setup would look something like this:
    2 frames, 1 hidden. (named displayFrame and communicationFrame)
    Let JS load another page in the hidden communicationFrame: getInfo.php

    This page contains the following info:
    <html>
    <body onLoad="sendInfo();">
    <script type="text/javascript">
    function sendInfo(){
    // The following info is produced dynamically on the server

    parent.frames.displayframe.receiveInfo("This text comes from some
    database or from some chatengine.");

    }
    </script>
    </body>
    </html>


    and in the displayframe you have a function receiveInfo that receives a
    string and does something with that.

    Now write some logic that refreshes the hidden frame every 10 seconds or
    something like that.

    I wrote application like this, it is fun, but the responsiveness is much
    lower than can be achieved using an applet and Java, because of all the
    overhead and loading.

    Anyway: I hope this gets you going. :)

    Good luck!

    Reagrds,
    Erwin Moller
    Erwin Moller, Sep 17, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jonah Olsson
    Replies:
    1
    Views:
    667
    Jonah Olsson
    Oct 7, 2004
  2. Ahan Hsieh
    Replies:
    1
    Views:
    2,236
    David W. Burhans
    Nov 4, 2003
  3. =?ISO-8859-1?Q?Daniel_G=F3mez?=

    how to listen to port 53 (DNS)

    =?ISO-8859-1?Q?Daniel_G=F3mez?=, May 30, 2004, in forum: Java
    Replies:
    3
    Views:
    7,285
    Mark Thornton
    May 30, 2004
  4. Donny
    Replies:
    13
    Views:
    658
    Donny
    Aug 5, 2004
  5. Gerald Klix
    Replies:
    0
    Views:
    1,259
    Gerald Klix
    Oct 26, 2005
Loading...

Share This Page