ConnectionBroker - /* ConnectionBroker is a network server...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
/* ConnectionBroker is a network server program that "brokers" connections between pairs of users on the network. It keeps a list of clients who have registered themselves as available for connection. Anyone who connects to the server must give one of the following commands (indicated by the first charcter that is transmitted to the server): REGISTER: The connecting user is added to the list of available clients. Any remaining characters on the line after the REGISTER command are stored as info for the client. The client is assigned a unique ID number. The client waits for a partner to be connected. Note that a client can only have one partner. The client should not send any data, except for a close command, until it has a partner. When it gets a partner, it will be notified by a message that begins with the CONNECTED character. (Any data that is sent before connection is ignored.) CONNECT: The remaining data on the line after the CONNECT command must be an ID number. A connection is made between the client who sent the CONNECT command and the waiting client with the specified ID number, if any. The server will then relay data between the two clients until one side or the other closes the connection. Note that a message begining with the CLOSE character is interpreted as closing the connection. If the connection cannot be made, then the server replies with a line begining with the NOT_AVAILABLE character. If the connection is made, then a line beginning with the CONNECTED character is sent to both partners in the connection. SEND_CLIENT_LIST: The server responds by sending info about all the waiting clients. Each line begins with the CLIENT_INFO character, followed by the client's ID, a space, and the client's info. After all the info has been sent, a line beginning with the END_CLIENT_INFO character is sent to mark the end of the transmission. The port on which the server listens can be specified as a command-line parameter. If none is specified, then the DEFAULT_PORT is used. Note that since the ConnectionBroker relays data between the two partners in a connection, the partners can be applets on Web pages downloaded from the computer where the server is running. */ *
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
import java.io.*; import java.net.*; import java.util.Vector; i public class ConnectionBroker { p /* Characters that can occur as the first char on a transmitted or received line of data. See the comment at the top of this file for more info on how these are used. */ static final char REGISTER = '['; // Characters sent as commands static final char CONNECT = '='; // by a client to server. static final char SEND_CLIENT_LIST = ':';
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/15/2010 for the course CSC 115 taught by Professor Jackson during the Spring '09 term at University of Victoria.

Page1 / 7

ConnectionBroker - /* ConnectionBroker is a network server...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online