All communication is via a single TCP connection to/from clients/server except for HTTP used to find the server IP address and set up a connection.
The drum server has access to users and passwords and checks passwords when a connection is made (see Hello Message). In addition, the drum server has at least 2 classes of users: normal and admin. An admin can perform some special operations including Configure and send Voice messages.
Before talking directly to Drum Server, a client will make a request via HTTP, using POST to the web server for IP address, port, and secret session code for Drum Server.
The url is 'www.music.cs.cmu.edu', and the following key-value pairs are required:
username: <username> -- a drum player's id
password: <password> -- a drum player's password
After sending the request for Drum Server info, the client would receive a response containing the relevant info from the web server, if the <username> and <password> both match the ones stored in the database of web server.(Assume that Drum Server started before the client starts and stored its IP, port and secret session code in the database successfully.)
The response message consists of the following:
Status line
Headers
An empty line
HTTP message body data
IP address, port and secret session code are merged into a string, and stored in the message body data(mentioned above):
IP+'#'+port+'#'+secret_session_code -- pound is used to split information
Command numbers are:
1 = AUDIOMSG
2 = CHATMSG
3 = DRUMMSG
4 = CLOCKSYNCMSG
5 = CONFIGMSG
6 = HELLOMSG
7 = SETDELAY
8 = STARTMSG
9 = BYEMSG
10 = DIRMSG
11 = SYNCMSG
Connection state numbers are:
1 = ACCEPTED --connection built
2 = WRONGNAME -- username doesn't exist
3 = WRONGPWD -- password is wrong
4 = WRONGSSC -- secret session code is wrong
5 = WRONGSTATE -- user is not enabled
6 = FATAL -- something wrong with the drum server
When a client first connects, it sends the secret session code to the server. If the server does not get the valid secret session code as the first message from the client, it drops the connection. If it does get the correct code, it sends a Hello Message as a reply, and then a CONFIGMSG; If it doesn't, it only sends a Hello Message, containing the error number.
When a client first connects, the server sends configuration information. Changes may be made later by sending another configuration message.
A configure message will be followed immediately by a Set Delay message.
An admin can send and change configuration information with this message.
(more configuration information is needed to assign drum sounds to different drums of different players)
The audio system is used for voice communication to alert the ensemble and give instructions. Voice is one-way via TCP from an admin client to server and from the server to all the clients. Only admin clients can send a voice message to users. Voice messages are short recordings rather than continuous streams. The recordings are typically broken into packets, originally to allow streaming over UDP packets, but now this allows long audio messages to be interleaved with other messages. Packets for a single audio recording begin with "A" except the last packet which begins with "E". The voice message format is:
Chat messages are all broadcast to everyone OR sent just to the administrator. Messages are sent via TCP as follows:
msg_type (1 byte) = 2 = CHATMSG -- a message type
length (4 bytes) -- network byte order 32-bit integer, length of destination + text
destination (1 byte per char, zero terminated)
text (1 byte per char)
Messages are sent via TCP as follows:
msg_type (1 byte) = 2 = CHATMSG -- a message type
length (4 bytes) -- network byte order 32-bit integer, length of sender + destination + text
sender (1 byte per char, zero terminated) -- The user name of the sender.
destination (1 byte)
text (1 byte per char) -- the message, zero terminated (zero byte is included in the length count).
The message displayed should match one of the following styles:
1. (private from Fred): Hello
2. (from Fred to all): Hello
3. (from Fred to admins): Hello
While SETDELAY is in effect (i.e. until a beats_per_cycle of zero is sent), the server sends out time-keeping drum hits using channel 0, pitch 0 and channel 0, pitch 1 drums.
This information might be displayed to users, but since delay is controlled in the server, and the server sends "metronome" beats at the correct tempo, the data is not used by the client program to control anything.
Drum stroke messages are sent for every user drum stroke via TCP as follows:
Obsolete. The Start command tells the server to start or stop sending timekeeping drum hits. Timekeeping hits are a sequence of drum stroke messages with precise timing according to the beats per cycle and beat period to help users synchronize (experience shows that users cannot easily synchronize with each other with the long feedback loop created when drum beats are delayed one cycle.)
The Bye command tells the server to shut down. The main purpose is to flush and close the log file since there is no way to do this from the web interface. Ideally, you should say "Bye" from a client drum application logged in with admin privileges (the Bye message is ignored if it does not come from an admin) before you leave the web page showing server status.
A string is displayed to give directions.
msg_type (1 byte) = 10 = DIRMSG - a message type
length (4 bytes) -- network byte order 32-bit integer, length of text
text (1 byte per char) -- the message, zero terminated (zero byte is included in the length count).
A string is sent to give directions.
msg_type (1 byte) = 10 = DIRMSG - a message type
length (4 bytes) -- network byte order 32-bit integer, length of text
text (1 byte per char) -- the message, zero terminated (zero byte is included in the length count).
After synchronization is achieved, the client wants to know what is the state of play. This message requests the server to send information. When the server receives this message, it generates a SETDELAY message and a DIRMSG for this client.
Assume 100 players, 5 notes per second -> 500 notes per second total.
1 DRUMMSG = 16 bytes; 16 * 500 = 8000; 8000 * 8 = 64Kbps download per client. 6.4Mbps out from server.
Overhead is 4/16.
Admin sends DELAYMSG with at least 2s advanced notice. Server forwards message to clients that then schedule it to occur as scheduled. On the server side, we have notes scheduled for the future too, so these have to "see" the future schedule, especially for the solo mode where notes are muted on even measures. For now, the future state will take place immediately.