Android Open Source - android_opengles Web Socket Listener






From Project

Back to project page android_opengles.

License

The source code is released under:

MIT License

If you think the Android project android_opengles listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.java_websocket;
/* w  w  w . j  av  a 2  s.c o  m*/
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;

import org.java_websocket.drafts.Draft;
import org.java_websocket.exceptions.InvalidDataException;
import org.java_websocket.framing.Framedata;
import org.java_websocket.handshake.ClientHandshake;
import org.java_websocket.handshake.Handshakedata;
import org.java_websocket.handshake.ServerHandshake;
import org.java_websocket.handshake.ServerHandshakeBuilder;

/**
 * Implemented by <tt>WebSocketClient</tt> and <tt>WebSocketServer</tt>.
 * The methods within are called by <tt>WebSocket</tt>.
 * Almost every method takes a first parameter conn which represents the source of the respective event.
 */
public interface WebSocketListener {

  /**
   * Called on the server side when the socket connection is first established, and the WebSocket
   * handshake has been received. This method allows to deny connections based on the received handshake.<br>
   * By default this method only requires protocol compliance.
   * 
   * @param conn
   *            The WebSocket related to this event
   * @param draft
   *            The protocol draft the client uses to connect
   * @param request
   *            The opening http message send by the client. Can be used to access additional fields like cookies.
   * @return Returns an incomplete handshake containing all optional fields
   * @throws InvalidDataException
   *             Throwing this exception will cause this handshake to be rejected
   */
  public ServerHandshakeBuilder onWebsocketHandshakeReceivedAsServer( WebSocket conn, Draft draft, ClientHandshake request ) throws InvalidDataException;

  /**
   * Called on the client side when the socket connection is first established, and the WebSocketImpl
   * handshake response has been received.
   * 
   * @param conn
   *            The WebSocket related to this event
   * @param request
   *            The handshake initially send out to the server by this websocket.
   * @param response
   *            The handshake the server sent in response to the request.
   * @throws InvalidDataException
   *             Allows the client to reject the connection with the server in respect of its handshake response.
   */
  public void onWebsocketHandshakeReceivedAsClient( WebSocket conn, ClientHandshake request, ServerHandshake response ) throws InvalidDataException;

  /**
   * Called on the client side when the socket connection is first established, and the WebSocketImpl
   * handshake has just been sent.
   * 
   * @param conn
   *            The WebSocket related to this event
   * @param request
   *            The handshake sent to the server by this websocket
   * @throws InvalidDataException
   *             Allows the client to stop the connection from progressing
   */
  public void onWebsocketHandshakeSentAsClient( WebSocket conn, ClientHandshake request ) throws InvalidDataException;

  /**
   * Called when an entire text frame has been received. Do whatever you want
   * here...
   * 
   * @param conn
   *            The <tt>WebSocket</tt> instance this event is occurring on.
   * @param message
   *            The UTF-8 decoded message that was received.
   */
  public void onWebsocketMessage( WebSocket conn, String message );

  /**
   * Called when an entire binary frame has been received. Do whatever you want
   * here...
   * 
   * @param conn
   *            The <tt>WebSocket</tt> instance this event is occurring on.
   * @param blob
   *            The binary message that was received.
   */
  public void onWebsocketMessage( WebSocket conn, ByteBuffer blob );

  public void onWebsocketMessageFragment( WebSocket conn, Framedata frame );

  /**
   * Called after <var>onHandshakeReceived</var> returns <var>true</var>.
   * Indicates that a complete WebSocket connection has been established,
   * and we are ready to send/receive data.
   * 
   * @param conn
   *            The <tt>WebSocket</tt> instance this event is occuring on.
   */
  public void onWebsocketOpen( WebSocket conn, Handshakedata d );

  /**
   * Called after <tt>WebSocket#close</tt> is explicity called, or when the
   * other end of the WebSocket connection is closed.
   * 
   * @param conn
   *            The <tt>WebSocket</tt> instance this event is occuring on.
   */
  public void onWebsocketClose( WebSocket ws, int code, String reason, boolean remote );

  /** called as soon as no further frames are accepted */
  public void onWebsocketClosing( WebSocket ws, int code, String reason, boolean remote );

  /** send when this peer sends a close handshake */
  public void onWebsocketCloseInitiated( WebSocket ws, int code, String reason );

  /**
   * Called if an exception worth noting occurred.
   * If an error causes the connection to fail onClose will be called additionally afterwards.
   * 
   * @param ex
   *            The exception that occurred. <br>
   *            Might be null if the exception is not related to any specific connection. For example if the server port could not be bound.
   */
  public void onWebsocketError( WebSocket conn, Exception ex );

  /**
   * Called a ping frame has been received.
   * This method must send a corresponding pong by itself.
   * 
   * @param f
   *            The ping frame. Control frames may contain payload.
   */
  public void onWebsocketPing( WebSocket conn, Framedata f );

  /**
   * Called when a pong frame is received.
   **/
  public void onWebsocketPong( WebSocket conn, Framedata f );

  /**
   * Gets the XML string that should be returned if a client requests a Flash
   * security policy.
   * @throws InvalidDataException thrown when some data that is required to generate the flash-policy like the websocket local port could not be obtained.
   */
  public String getFlashPolicy( WebSocket conn ) throws InvalidDataException;

  /** This method is used to inform the selector thread that there is data queued to be written to the socket. */
  public void onWriteDemand( WebSocket conn );

  public InetSocketAddress getLocalSocketAddress( WebSocket conn );
  public InetSocketAddress getRemoteSocketAddress( WebSocket conn );
}




Java Source Code List

com.example.android.wifidirect.DeviceDetailFragment.java
com.example.android.wifidirect.DeviceListFragment.java
com.example.android.wifidirect.FileTransferService.java
com.example.android.wifidirect.WiFiDirectActivity.java
com.example.android.wifidirect.WiFiDirectBroadcastReceiver.java
com.example.android.wifidirect.discovery.ChatManager.java
com.example.android.wifidirect.discovery.ClientSocketHandler.java
com.example.android.wifidirect.discovery.GroupOwnerSocketHandler.java
com.example.android.wifidirect.discovery.WiFiChatFragment.java
com.example.android.wifidirect.discovery.WiFiDirectBroadcastReceiver.java
com.example.android.wifidirect.discovery.WiFiDirectServicesList.java
com.example.android.wifidirect.discovery.WiFiP2pService.java
com.example.android.wifidirect.discovery.WiFiServiceDiscoveryActivity.java
com.example.opengles.CubeRenderer.java
com.example.opengles.Cube.java
com.example.opengles.MainActivity.java
com.example.opengles.Planet.java
com.example.opengles.SolarSystemRenderer.java
com.example.opengles.SquareRenderer.java
com.example.opengles.Square.java
com.nfg.sdk.NFGameServer.java
com.nfg.sdk.NFGame.java
com.nfg.wifidirect3p.ChatActivity.java
com.nfg.wifidirect3p.WifiDirect3PActivity.java
fi.iki.elonen.HelloServer.java
fi.iki.elonen.HelloServer.java
fi.iki.elonen.IWebSocketFactory.java
fi.iki.elonen.InternalRewrite.java
fi.iki.elonen.InternalRewrite.java
fi.iki.elonen.NanoHTTPD.java
fi.iki.elonen.NanoHTTPD.java
fi.iki.elonen.NanoWebSocketServer.java
fi.iki.elonen.ServerRunner.java
fi.iki.elonen.ServerRunner.java
fi.iki.elonen.SimpleWebServer.java
fi.iki.elonen.SimpleWebServer.java
fi.iki.elonen.TempFilesServer.java
fi.iki.elonen.TempFilesServer.java
fi.iki.elonen.WebServerPluginInfo.java
fi.iki.elonen.WebServerPluginInfo.java
fi.iki.elonen.WebServerPlugin.java
fi.iki.elonen.WebServerPlugin.java
fi.iki.elonen.WebSocketException.java
fi.iki.elonen.WebSocketFrame.java
fi.iki.elonen.WebSocketResponseHandler.java
fi.iki.elonen.WebSocket.java
fi.iki.elonen.debug.DebugServer.java
fi.iki.elonen.debug.DebugServer.java
fi.iki.elonen.samples.echo.DebugWebSocketServer.java
fi.iki.elonen.samples.echo.DebugWebSocket.java
fi.iki.elonen.samples.echo.EchoSocketSample.java
org.java_websocket.AbstractWrappedByteChannel.java
org.java_websocket.SSLSocketChannel2.java
org.java_websocket.SocketChannelIOHelper.java
org.java_websocket.WebSocketAdapter.java
org.java_websocket.WebSocketFactory.java
org.java_websocket.WebSocketImpl.java
org.java_websocket.WebSocketListener.java
org.java_websocket.WebSocket.java
org.java_websocket.WrappedByteChannel.java
org.java_websocket.client.AbstractClientProxyChannel.java
org.java_websocket.client.WebSocketClient.java
org.java_websocket.drafts.Draft_10.java
org.java_websocket.drafts.Draft_17.java
org.java_websocket.drafts.Draft_75.java
org.java_websocket.drafts.Draft_76.java
org.java_websocket.drafts.Draft.java
org.java_websocket.exceptions.IncompleteHandshakeException.java
org.java_websocket.exceptions.InvalidDataException.java
org.java_websocket.exceptions.InvalidFrameException.java
org.java_websocket.exceptions.InvalidHandshakeException.java
org.java_websocket.exceptions.LimitExedeedException.java
org.java_websocket.exceptions.NotSendableException.java
org.java_websocket.exceptions.WebsocketNotConnectedException.java
org.java_websocket.framing.CloseFrameBuilder.java
org.java_websocket.framing.CloseFrame.java
org.java_websocket.framing.FrameBuilder.java
org.java_websocket.framing.FramedataImpl1.java
org.java_websocket.framing.Framedata.java
org.java_websocket.handshake.ClientHandshakeBuilder.java
org.java_websocket.handshake.ClientHandshake.java
org.java_websocket.handshake.HandshakeBuilder.java
org.java_websocket.handshake.HandshakeImpl1Client.java
org.java_websocket.handshake.HandshakeImpl1Server.java
org.java_websocket.handshake.HandshakedataImpl1.java
org.java_websocket.handshake.Handshakedata.java
org.java_websocket.handshake.ServerHandshakeBuilder.java
org.java_websocket.handshake.ServerHandshake.java
org.java_websocket.server.DefaultSSLWebSocketServerFactory.java
org.java_websocket.server.DefaultWebSocketServerFactory.java
org.java_websocket.server.WebSocketServer.java
org.java_websocket.util.Base64.java
org.java_websocket.util.Charsetfunctions.java