port listen/send

1

1388-2/HB

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?
 
E

Erwin Moller

1388-2/HB said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top