Socket in a web page - possible?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Martin

    #1

    Socket in a web page - possible?

    I would like to serve out a web page (intranet only - no internet)
    that has the ability to open a client-side socket that connects to a
    server-side socket on another computer. This connection is used to
    send data to be displayed using DHTML on the web page (as opposed to
    refreshing the entire page).

    I have this working where the client is running Internet Explorer in
    Windows (the client-side socket is an ActiveX DLL). I would like to
    get this to work from a Mozilla browser running in Linux. The ActiveX
    stuff, of course, will not work there.

    Is there something I can use in a Javascript that will work in Linux?

    TIA
  • Martin Honnen

    #2
    Re: Socket in a web page - possible?



    Martin wrote:
    [color=blue]
    > I would like to serve out a web page (intranet only - no internet)
    > that has the ability to open a client-side socket that connects to a
    > server-side socket on another computer. This connection is used to
    > send data to be displayed using DHTML on the web page (as opposed to
    > refreshing the entire page).
    >
    > I have this working where the client is running Internet Explorer in
    > Windows (the client-side socket is an ActiveX DLL). I would like to
    > get this to work from a Mozilla browser running in Linux. The ActiveX
    > stuff, of course, will not work there.
    >
    > Is there something I can use in a Javascript that will work in Linux?[/color]

    Mozilla has XMLHttpRequest since Netscape 6/pre Mozilla 1.0 times, it
    has a SOAP API since Mozilla 1.0 and it has a high-level web service API
    since Mozilla 1.4, see

    All ways to send data to a HTTP server and receive data back with script
    without any need to refresh an HTML window/frame document
    --

    Martin Honnen
    http://JavaScript.FAQTs.com/

    Comment

    • Michael Winter

      #3
      Re: Socket in a web page - possible?

      On Wed, 11 Feb 2004 10:17:31 -0700, Martin <martinvalley@c omcast.net>
      wrote:
      [color=blue]
      > I would like to serve out a web page (intranet only - no internet)
      > that has the ability to open a client-side socket that connects to a
      > server-side socket on another computer. This connection is used to
      > send data to be displayed using DHTML on the web page (as opposed to
      > refreshing the entire page).
      >
      > I have this working where the client is running Internet Explorer in
      > Windows (the client-side socket is an ActiveX DLL). I would like to
      > get this to work from a Mozilla browser running in Linux. The ActiveX
      > stuff, of course, will not work there.
      >
      > Is there something I can use in a Javascript that will work in Linux?[/color]

      No, but you can use a Java applet, as long as the server that it connects
      to is the same machine that serves the applet (a security measure).

      Ask in comp.lang.java for more information.

      Mike

      --
      Michael Winter
      M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

      Comment

      • Brian Genisio

        #4
        Re: Socket in a web page - possible?

        Martin wrote:
        [color=blue]
        > I would like to serve out a web page (intranet only - no internet)
        > that has the ability to open a client-side socket that connects to a
        > server-side socket on another computer. This connection is used to
        > send data to be displayed using DHTML on the web page (as opposed to
        > refreshing the entire page).
        >
        > I have this working where the client is running Internet Explorer in
        > Windows (the client-side socket is an ActiveX DLL). I would like to
        > get this to work from a Mozilla browser running in Linux. The ActiveX
        > stuff, of course, will not work there.
        >
        > Is there something I can use in a Javascript that will work in Linux?
        >
        > TIA[/color]

        I know you can do something like this in Java. (Not JavaScript...
        different technology). I have done something where the Java applet
        connects to a port (not 80) on the server that the page came from. I am
        pretty sure you can get Java to talk to the DOM... though I have never
        tried. Java is more platform independant, but still not guaranteed on
        all browsers.

        Brian

        Comment

        • Douglas Crockford

          #5
          Re: Socket in a web page - possible?

          > I would like to serve out a web page (intranet only - no internet)[color=blue]
          > that has the ability to open a client-side socket that connects to a
          > server-side socket on another computer. This connection is used to
          > send data to be displayed using DHTML on the web page (as opposed to
          > refreshing the entire page).
          >
          > I have this working where the client is running Internet Explorer in
          > Windows (the client-side socket is an ActiveX DLL). I would like to
          > get this to work from a Mozilla browser running in Linux. The ActiveX
          > stuff, of course, will not work there.
          >
          > Is there something I can use in a Javascript that will work in Linux?[/color]

          Yes. I have used <iframe> in IE and Mozilla to do this very thing.

          Comment

          • Jim Buzbee

            #6
            Re: Socket in a web page - possible?

            In article <48ok20tt348dtv 08ot4pap5oondrd kg69d@4ax.com>,
            Martin <martinvalley@c omcast.net> wrote:[color=blue]
            >I would like to serve out a web page (intranet only - no internet)
            >that has the ability to open a client-side socket that connects to a
            >server-side socket on another computer. This connection is used to
            >send data to be displayed using DHTML on the web page (as opposed to
            >refreshing the entire page).
            >
            >I have this working where the client is running Internet Explorer in
            >Windows (the client-side socket is an ActiveX DLL). I would like to
            >get this to work from a Mozilla browser running in Linux. The ActiveX
            >stuff, of course, will not work there.
            >
            >Is there something I can use in a Javascript that will work in Linux?
            >
            >TIA[/color]

            This page describes a portable method (IE and Mozilla) that works for me:



            Jim

            --
            --------------------------------------------------------------------------------
            Jim Buzbee "I was gratified to be able to
            jbuzbee@nyx.net answer promptly, and I did. I
            http://batbox.org said I didn't know." Mark Twain

            Comment

            • Martin

              #7
              Re: Socket in a web page - possible?

              I greatly appreciate the responses to my question - thanks.

              I tried using a Java Applet but it seems to be a major overkill for
              what I'm trying to do. With an applet, my entire concept changes from
              being a web page to being an applet screen. The Java plugin has to be
              installed on each client machine (that was a big hassle on my test
              Linux machine); and I'd have to learn how to use the Java SDK; etc.,
              etc.

              I looked at the "iframe" that was suggested. I found a web site that
              had a working example of that and verified that it does work on both
              the IE/Windows and on the Mozilla/Linux clients. Like the applet
              concept, it appears that it would do the job but it's still more than
              what I actually need.

              I think the same thing is true of the HTTPRequest approach. That is,
              it will do what I want to do but it's too much for what I need to do.

              Can anyone tell me if it's possible (practical / realistic) to simply
              open a socket as the client side of a connection (on a Linux machine)
              thru which a small amount of data can be sent to the web page? This is
              the approach I'm using now with the Windows machines; I'd just like to
              get this to work on Linux boxes.

              I downloaded a Javascript from
              http://www.phpfreaks.com/phpmanual/p...f.sockets.html but have not
              been able to get it to work yet. I don't know if it's even "workable".

              Any thoughts?

              Comment

              • Michael Winter

                #8
                Re: Socket in a web page - possible?

                On Wed, 11 Feb 2004 17:00:18 -0700, Martin <martinvalley@c omcast.net>
                wrote:
                [color=blue]
                > I downloaded a Javascript from
                > http://www.phpfreaks.com/phpmanual/p...f.sockets.html but have not
                > been able to get it to work yet. I don't know if it's even "workable".[/color]

                That's PHP, not JavaScript, and it's server-side, not client-side.

                Mike

                --
                Michael Winter
                M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

                Comment

                • Martin

                  #9
                  Re: Socket in a web page - possible?

                  On Thu, 12 Feb 2004 00:04:11 GMT, Michael Winter
                  <M.Winter@bluey onder.co.invali d> wrote:
                  [color=blue]
                  >On Wed, 11 Feb 2004 17:00:18 -0700, Martin <martinvalley@c omcast.net>
                  >wrote:
                  >[color=green]
                  >> I downloaded a Javascript from
                  >> http://www.phpfreaks.com/phpmanual/p...f.sockets.html but have not
                  >> been able to get it to work yet. I don't know if it's even "workable".[/color]
                  >
                  >That's PHP, not JavaScript, and it's server-side, not client-side.
                  >
                  >Mike[/color]

                  Example 2 says its client-side.

                  As to PHP vs Javascript, I'm clueless. Can this be done with
                  Javascript?

                  Comment

                  • Michael Winter

                    #10
                    Re: Socket in a web page - possible?

                    On Wed, 11 Feb 2004 18:26:33 -0700, Martin <martinvalley@c omcast.net>
                    wrote:
                    [color=blue]
                    > On Thu, 12 Feb 2004 00:04:11 GMT, Michael Winter
                    > <M.Winter@bluey onder.co.invali d> wrote:
                    >[color=green]
                    >> On Wed, 11 Feb 2004 17:00:18 -0700, Martin <martinvalley@c omcast.net>
                    >> wrote:
                    >>[color=darkred]
                    >>> I downloaded a Javascript from
                    >>> http://www.phpfreaks.com/phpmanual/p...f.sockets.html but have not
                    >>> been able to get it to work yet. I don't know if it's even "workable".[/color]
                    >>
                    >> That's PHP, not JavaScript, and it's server-side, not client-side.[/color]
                    >
                    > Example 2 says its client-side.[/color]

                    It says it's a TCP/IP client. That is not the same as client-side. Even
                    so, it is still written in PHP which can only be interpreted server-side.
                    [color=blue]
                    > As to PHP vs Javascript, I'm clueless. Can this be done with
                    > Javascript?[/color]

                    No. You'll have to use one of the other suggestions in this thread.

                    Mike

                    --
                    Michael Winter
                    M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

                    Comment

                    • Brian Genisio

                      #11
                      Re: Socket in a web page - possible?

                      Martin wrote:
                      [color=blue]
                      > I looked at the "iframe" that was suggested. I found a web site that
                      > had a working example of that and verified that it does work on both
                      > the IE/Windows and on the Mozilla/Linux clients. Like the applet
                      > concept, it appears that it would do the job but it's still more than
                      > what I actually need.[/color]

                      Hmmmm.... If IFRAME will work for you, I hardly consider it to be
                      overkill. It is more portable than what you are currently doing with a
                      client-side socket, using a Win32 DLL.

                      Note that you had to use a platform specific mechanism, for sockets,
                      because the browser did not support sockets natively. This means that
                      every other browser (Netscape/Mozilla/Opera/Safari/Konquerer/etc) will
                      all have to have their own platform specific mechanism... yuck.

                      IFRAMEs are part of the HTML standard, so if you can get it working with
                      IFRAMEs, I would highly suggest doing so. It is less overkill than an
                      ActiveX DLL.
                      [color=blue]
                      > I downloaded a Javascript from
                      > http://www.phpfreaks.com/phpmanual/p...f.sockets.html but have not
                      > been able to get it to work yet. I don't know if it's even "workable".
                      >[/color]

                      Just a note... PHP is a scripting language, just like Javascript is.
                      The difference is that PHP is a server-side scripting environment
                      (similar to ASP or CGI). Basically, you write a script, that the server
                      executes BEFORE it sends it to the browser. (The server needs to know
                      how to read PHP) The output of the script must be HTML/Javascript or an
                      image, or something that a browser can recognize.

                      By using sockets in PHP, on the server, you can have your PHP script
                      connect to something, like a database, or some service on another
                      server, to get data that it formats into HTML, and dynamically sends to
                      the client. In that sense, it is a client to the service it is getting
                      it's data from, but as far as the web browser is concirned, it is still
                      on the server... so PHP cannot be used to create sockets on the web
                      browser side of things.

                      I hope this helps a bit. If you can get your application working with
                      the IFRAME object, I recommend that is what you use.

                      Brian

                      Comment

                      • Martin

                        #12
                        Re: Socket in a web page - possible?

                        >I hope this helps a bit. If you can get your application working with[color=blue]
                        >the IFRAME object, I recommend that is what you use.
                        >
                        >Brian[/color]

                        Brian / Michael:

                        Thanks for the further explanations.

                        I didn't realize that PHP was so far off from what I needed. I won't
                        bother persuing that any further.

                        It does look like the iFrame approach might be my best option.

                        One thing I don't understand about it yet is: can I "push" data out
                        from the server to the iFrame target? In my situation, there are
                        events occurring on the server that create data that I want to display
                        on the browser's current screen. I don't want the user to have to do
                        anything to get that data. All I'm doing on the client side (in the
                        version I have working) is updating the contents and colors of several
                        cells in a table that is already displayed.

                        In the example that I played with (that I mentioned previously), I had
                        to click a button to request some data to be sent from their server.
                        Is something like that REQUIRED or is that just the way this
                        particular example was set up?

                        Thanks again for any additional comments.

                        Martin

                        Comment

                        • Brian Genisio

                          #13
                          Re: Socket in a web page - possible?

                          Martin wrote:
                          [color=blue][color=green]
                          >>I hope this helps a bit. If you can get your application working with
                          >>the IFRAME object, I recommend that is what you use.
                          >>
                          >>Brian[/color]
                          >
                          >
                          > Brian / Michael:
                          >
                          > Thanks for the further explanations.
                          >
                          > I didn't realize that PHP was so far off from what I needed. I won't
                          > bother persuing that any further.
                          >
                          > It does look like the iFrame approach might be my best option.
                          >
                          > One thing I don't understand about it yet is: can I "push" data out
                          > from the server to the iFrame target? In my situation, there are
                          > events occurring on the server that create data that I want to display
                          > on the browser's current screen. I don't want the user to have to do
                          > anything to get that data. All I'm doing on the client side (in the
                          > version I have working) is updating the contents and colors of several
                          > cells in a table that is already displayed.
                          >
                          > In the example that I played with (that I mentioned previously), I had
                          > to click a button to request some data to be sent from their server.
                          > Is something like that REQUIRED or is that just the way this
                          > particular example was set up?
                          >
                          > Thanks again for any additional comments.
                          >
                          > Martin[/color]


                          Using the IFRAME approach, it is like having a separate page embedded
                          inside the actual page. The IFRAM can be hidden, so it only exists as
                          an interface for you, and the user never sees it.

                          Here is what you do:

                          On the main page, get your request ready, but do not actually make it
                          from the main page. Instead, tell the IFRAME to make the request.
                          Since the user never see's the IFRAME, he will never see the waiting.
                          Now, the IFRAME can take a long time to respond. When it finally does,
                          stating that the request is done, your main page can know this, and
                          alert the user.

                          You can also tell the IFRAME to check for new data, which will return
                          quickly. Parse the data out of the IFRAME DOM, and do what you need in
                          the main frame.

                          It is not a pushing method, but it is close enough to get what you need.

                          Brian


                          Comment

                          • Robert

                            #14
                            Re: Socket in a web page - possible?

                            Here is a concise discription of iFrame. While on the Apple site, it
                            does cover the Windows implementation.




                            I haven't used iFrame but could you use an event timer in you javascript
                            to refresh you html code via dhtml?

                            Robert

                            Comment

                            Working...