Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Another method you might be able to use is with the OpenThought Web Application Environment. OpenThought allows you to communicate with the server, and update the browser window, without actually reloading the webpage.

This would allow you to build your chat room, without needing seperate frames for each component. So, lets say we have a textarea where the chat message goes called "chatwindow", and a textarea where the user types in their message called "newtext", with an associated submit button right next to it. The way it would work then is the user would type in their new text into the "newtext" textarea, and hit submit. The page doesn't refresh -- instead, the data the user typed in is sent to the server, where you can do any amount of processing on it, and then respond back to the browser. In this case, your response might be to update the "chatwindow" textarea with the latest text, while clearing out the "newtext" textarea.

The code to make that work would look something like:
The HTML: <form name='chat'> <textarea name='chatwindow'></textarea> <br/><br/> <textarea name='newtext'></textarea> <input type='button' name='sendtext' value='Send!' onClick="parent.SendParameters('chatserver.pl','newtext', 'run_mode +=sendchatmessage')"> <br/> </form> And on the server side, we have a subroutine within a Perl script whic +h looks like: sub sendchatmessage { my $self = shift; # Retrieve the text message sent to us from the browser my $chatmsg = $self->OP->param->get_incoming('fields')->{'newtext' +}; # Perhaps we want to log all messages log_message( $chatmsg ); # Get the last 10 messages which have been sent to # the chat server (including the one we just logged) my $messages = get_last_ten(); # Prepare to send data back to the browser. # Each hash key represents a field in our HTML my $field_data = { chatwindow => $messages, # Put the last 10 messages in the cha +t window newtext => "", # Blank out the newtext field }; # Send the data back to the browser. # This puts the appropriate data into the browser, # and puts the focus on the newtext field return $self->param('OpenThought')->serialize({ fields => $field_data, focus => "newtext", }); }

In the above, the functions "log_message()" and "get_last_ten()" are hypothetical subs that you would write as part of your chat program. Everything else exists in the framework as seen.

Thats the skeleton of what you would need in order to make this work using OpenThought. See the demo app that comes with the distribution for an example of an entire working application. There's also a lot of documentation which comes with the module.

You can find OpenThought at openthought.net. The release thats out now works well, but I highly recommend grabbing the version currently in CVS. There is about to be a new release, and all sorts of neat goodies have been added and/or fixed.

Good luck!
-Eric

--
Lucy: "What happens if you practice the piano for 20 years and then end up not being rich and famous?"
Schroeder: "The joy is in the playing."

In reply to Re: CGI & HTML Frames by andreychek
in thread CGI & HTML Frames by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (7)
As of 2024-04-18 11:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found