Class Socket

java.lang.Object
com.codename1.io.Socket

public final class Socket extends Object
Class implementing the socket API
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    This interface can be invoked to stop listening on a server socket
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    connect(String host, int port, SocketConnection sc)
    Connect to a remote host
    static com.codename1.io.Socket.Close
    Connect to a remote host
    static String
    Returns the hostname or ip address of the device if available/applicable
    static boolean
    Returns true if server sockets are supported in this port, if this method returns false invocations of listen will always fail
    static boolean
    Returns true if sockets are supported in this port, false otherwise
    listen(int port, Class scClass)
    Listen to incoming connections on port

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    Modifier and Type
    Method
    Description
    protected Object
     
    boolean
    Indicates whether some other object is "equal to" this one.
    final Class
    Returns the runtime class of an object.
    int
    Returns a hash code value for the object.
    final void
    Wakes up a single thread that is waiting on this object's monitor.
    final void
    Wakes up all threads that are waiting on this object's monitor.
    Returns a string representation of the object.
    final void
    Causes current thread to wait until another thread invokes the method or the method for this object.
    final void
    wait(long timeout)
    Causes current thread to wait until either another thread invokes the method or the method for this object, or a specified amount of time has elapsed.
    final void
    wait(long timeout, int nanos)
    Causes current thread to wait until another thread invokes the method or the method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.
  • Method Details

    • isSupported

      public static boolean isSupported()

      Returns true if sockets are supported in this port, false otherwise

      Returns

      true if sockets are supported in this port, false otherwise

    • isServerSocketSupported

      public static boolean isServerSocketSupported()

      Returns true if server sockets are supported in this port, if this method returns false invocations of listen will always fail

      Returns

      true if server sockets are supported in this port, false otherwise

      Deprecated
    • connect

      public static void connect(String host, int port, SocketConnection sc)

      Connect to a remote host

      Parameters
      • host: the host

      • port: the connection port

      • sc: callback for when the connection is established or fails

    • connectWithClose

      public static com.codename1.io.Socket.Close connectWithClose(String host, int port, SocketConnection sc)

      Connect to a remote host

      Parameters
      • host: the host

      • port: the connection port

      • sc: callback for when the connection is established or fails

    • listen

      public static Socket.StopListening listen(int port, Class scClass)

      Listen to incoming connections on port

      Parameters
      • port: the device port

      • scClass: @param scClass class of callback for when the connection is established or fails, this class will be instantiated for every incoming connection and must have a public no argument constructor.

      Returns

      StopListening instance that allows the the caller to stop listening on a server socket

      Deprecated
    • getHostOrIP

      public static String getHostOrIP()

      Returns the hostname or ip address of the device if available/applicable

      Returns

      the hostname or ip address of the device if available/applicable