Intial commit
This commit is contained in:
39
tcl-dp/examples/conference/README
Normal file
39
tcl-dp/examples/conference/README
Normal file
@@ -0,0 +1,39 @@
|
||||
|
||||
Tcl-DP: N-way Text-based Conferencing Example
|
||||
|
||||
This example creates a conference application, similar to CB radio,
|
||||
where anyone can speak and everyone hears.
|
||||
|
||||
room.tcl -- the conferencing server, a room where conference
|
||||
may take place.
|
||||
|
||||
enter.tcl -- the conferencing client, that enters a room.
|
||||
|
||||
After setting up the room and after clients have entered that room,
|
||||
clients can type "say string," as in "say hello world!," to talk to
|
||||
other participants. The server will repeat the message to all clients.
|
||||
|
||||
--------------------------------------------------------------------
|
||||
|
||||
To run a conferencing server...
|
||||
|
||||
Run wish.
|
||||
Type "source room.tcl" and answer the questions.
|
||||
|
||||
--------------------------------------------------------------------
|
||||
|
||||
To start a conferencing client...
|
||||
|
||||
Run wish.
|
||||
Type "source enter.tcl" and answer the questions.
|
||||
Type "help" for on-line help.
|
||||
|
||||
--------------------------------------------------------------------
|
||||
|
||||
Experiment and run the conferencing client several times, to
|
||||
represent many people in a conference.
|
||||
|
||||
--------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
85
tcl-dp/examples/conference/enter.tcl
Normal file
85
tcl-dp/examples/conference/enter.tcl
Normal file
@@ -0,0 +1,85 @@
|
||||
|
||||
#
|
||||
# enter.tcl -- Tcl/Tk script for conference client.
|
||||
#
|
||||
|
||||
# Get information from user.
|
||||
#
|
||||
|
||||
package require dp 4.0
|
||||
|
||||
set host localhost;
|
||||
set port 9943;
|
||||
set name Bubba
|
||||
|
||||
# Become an RPC client of the conference server. Store the
|
||||
# file handle that represents the RPC connection in the
|
||||
# global variable server;
|
||||
#
|
||||
|
||||
set server [dp_MakeRPCClient $host $port]
|
||||
|
||||
# The conference server will occasionally RPC a Hear
|
||||
# command to us when we need to hear a message from some speaker.
|
||||
#
|
||||
|
||||
proc Hear {speaker message} \
|
||||
{
|
||||
puts stdout "$speaker --> $message";
|
||||
}
|
||||
|
||||
# Commands available to user, who invokes these commands from stdin.
|
||||
#
|
||||
|
||||
proc help {} \
|
||||
{
|
||||
puts stdout "Conferencing Commands: ";
|
||||
puts stdout "\thelp";
|
||||
puts stdout "\twho";
|
||||
puts stdout "\tsay ?message?";
|
||||
puts stdout "\tbye or quit or leave";
|
||||
}
|
||||
|
||||
proc who {} \
|
||||
{
|
||||
global server;
|
||||
|
||||
# RPC to the conference server to get the list of all its client names;
|
||||
#
|
||||
puts stdout [dp_RPC $server set names];
|
||||
}
|
||||
|
||||
proc say {args} \
|
||||
{
|
||||
global server;
|
||||
|
||||
# Tell the conference server, by RPC, what I want to said to all clients.
|
||||
# The conference server will repeat my message to all clients, by RPC,
|
||||
# for them to Hear.
|
||||
#
|
||||
dp_RPC $server Say $args;
|
||||
}
|
||||
|
||||
# To leave, we just exit, and the file is automatically closed. The
|
||||
# conference server will automatically clen up on his end.
|
||||
proc leave {} {exit}
|
||||
proc bye {} {exit};
|
||||
proc quit {} {exit}
|
||||
|
||||
# On startup, automatically enter the conference.
|
||||
#
|
||||
|
||||
proc enter {} \
|
||||
{
|
||||
global server;
|
||||
global name;
|
||||
|
||||
# Tell the conference server, by RPC, that I'm Entering the conference.
|
||||
#
|
||||
dp_RPC $server Enter $name;
|
||||
puts stdout "Entered conference.";
|
||||
}
|
||||
|
||||
enter;
|
||||
|
||||
|
||||
81
tcl-dp/examples/conference/room.tcl
Normal file
81
tcl-dp/examples/conference/room.tcl
Normal file
@@ -0,0 +1,81 @@
|
||||
|
||||
#
|
||||
# room.tcl -- Tcl/Tk script for conferencing server;
|
||||
#
|
||||
|
||||
package require dp 4.0
|
||||
|
||||
set port 9943;
|
||||
|
||||
# The following command creates an RPC server socket on
|
||||
# the given port.
|
||||
#
|
||||
|
||||
dp_MakeRPCServer $port
|
||||
|
||||
# names -- list of room occupants
|
||||
# files -- list of active rpc files
|
||||
#
|
||||
|
||||
set names {};
|
||||
set files {};
|
||||
|
||||
# The following are procedures available through RPC to
|
||||
# clients of the conferencing server.
|
||||
#
|
||||
|
||||
proc Enter {name} \
|
||||
{
|
||||
# Before any RPC command (such as this Enter) gets evaluated,
|
||||
# the global variable dp_rpcFile is set to the file handle
|
||||
# of the RPC connection currently being serviced.
|
||||
#
|
||||
global names;
|
||||
global files;
|
||||
global dp_rpcFile;
|
||||
|
||||
# Remember the name and the associated RPC file handle
|
||||
# of the client who just entered the room;
|
||||
#
|
||||
lappend names $name;
|
||||
lappend files $dp_rpcFile;
|
||||
|
||||
# Arrange to remove the information from the names and files list
|
||||
# when the connection is closed.
|
||||
dp_atclose $dp_rpcFile append "Leave $name $dp_rpcFile"
|
||||
}
|
||||
|
||||
# The following command is invoked automatically when a file is closed
|
||||
# This can happend because a server dies unexpectedly. The callback is
|
||||
# created by the "dp_atclose" call above. The two parameters give the
|
||||
# rpc file and the name of the person.
|
||||
#
|
||||
proc Leave {n f} \
|
||||
{
|
||||
global names;
|
||||
global files;
|
||||
|
||||
set files [ldelete $files $f]
|
||||
set names [ldelete $names $n]
|
||||
}
|
||||
|
||||
proc Say {message} \
|
||||
{
|
||||
global names;
|
||||
global files;
|
||||
global dp_rpcFile;
|
||||
|
||||
# Figure out the client who said the message;
|
||||
#
|
||||
set speaker [lindex $names [lsearch $files $dp_rpcFile]];
|
||||
|
||||
# Tell all clients to Hear the message from the speaker;
|
||||
#
|
||||
foreach client $files \
|
||||
{
|
||||
dp_RPC $client Hear $speaker $message;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user