1 /* 2 * Copyright (c) 2011 jMonkeyEngine 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: 8 * 9 * * Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * * Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * * Neither the name of 'jMonkeyEngine' nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 package com.jme3.network; 34 35 36 /** 37 * Represents a remote connection to a server that can be used 38 * for sending and receiving messages. 39 * 40 * @version $Revision: 8938 $ 41 * @author Paul Speed 42 */ 43 public interface Client extends MessageConnection 44 { 45 /** 46 * Starts the client allowing it to begin processing incoming 47 * messages and delivering them to listeners. 48 */ start()49 public void start(); 50 51 /** 52 * Returns true if this client is fully connected to the 53 * host. 54 */ isConnected()55 public boolean isConnected(); 56 57 /** 58 * Returns a unique ID for this client within the remote 59 * server or -1 if this client isn't fully connected to the 60 * server. 61 */ getId()62 public int getId(); 63 64 /** 65 * Returns the 'game name' for servers to which this client should be able 66 * to connect. This should match the 'game name' set on the server or this 67 * client will be turned away. 68 */ getGameName()69 public String getGameName(); 70 71 /** 72 * Returns the game-specific version of the server this client should 73 * be able to connect to. 74 */ getVersion()75 public int getVersion(); 76 77 /** 78 * Sends a message to the server. 79 */ send( Message message )80 public void send( Message message ); 81 82 /** 83 * Sends a message to the other end of the connection using 84 * the specified alternate channel. 85 */ send( int channel, Message message )86 public void send( int channel, Message message ); 87 88 /** 89 * Closes this connection to the server. 90 */ close()91 public void close(); 92 93 /** 94 * Adds a listener that will be notified about connection 95 * state changes. 96 */ addClientStateListener( ClientStateListener listener )97 public void addClientStateListener( ClientStateListener listener ); 98 99 /** 100 * Removes a previously registered connection listener. 101 */ removeClientStateListener( ClientStateListener listener )102 public void removeClientStateListener( ClientStateListener listener ); 103 104 /** 105 * Adds a listener that will be notified when any message or object 106 * is received from the server. 107 */ addMessageListener( MessageListener<? super Client> listener )108 public void addMessageListener( MessageListener<? super Client> listener ); 109 110 /** 111 * Adds a listener that will be notified when messages of the specified 112 * types are received. 113 */ addMessageListener( MessageListener<? super Client> listener, Class... classes )114 public void addMessageListener( MessageListener<? super Client> listener, Class... classes ); 115 116 /** 117 * Removes a previously registered wildcard listener. This does 118 * not remove this listener from any type-specific registrations. 119 */ removeMessageListener( MessageListener<? super Client> listener )120 public void removeMessageListener( MessageListener<? super Client> listener ); 121 122 /** 123 * Removes a previously registered type-specific listener from 124 * the specified types. 125 */ removeMessageListener( MessageListener<? super Client> listener, Class... classes )126 public void removeMessageListener( MessageListener<? super Client> listener, Class... classes ); 127 128 /** 129 * Adds a listener that will be notified when any connection errors 130 * occur. If a client has no error listeners then the default behavior 131 * is to close the connection and provide an appropriate DisconnectInfo 132 * to any ClientStateListeners. If the application adds its own error 133 * listeners then it must take care of closing the connection itself. 134 */ addErrorListener( ErrorListener<? super Client> listener )135 public void addErrorListener( ErrorListener<? super Client> listener ); 136 137 /** 138 * Removes a previously registered error listener. 139 */ removeErrorListener( ErrorListener<? super Client> listener )140 public void removeErrorListener( ErrorListener<? super Client> listener ); 141 } 142 143 144