469,275 Members | 1,802 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,275 developers. It's quick & easy.

port listen/send

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?
Sep 16 '05 #1
1 6366
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
Sep 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by D. André Dhondt | last post: by
2 posts views Thread by jasonsgeiger | last post: by
3 posts views Thread by ZAAN | last post: by
1 post views Thread by samuelsam | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.