LogoLogo
v7.0.0
v7.0.0
  • TotalCross Overview
  • TotalCross Javadoc
  • TotalCross Changelog
  • Roadmap
  • Documentation
    • Getting Started
      • First embedded project with TotalCross
    • Components
      • Accordion
      • Aligned Labels
      • Button
      • Check
      • ComboBox
      • Dynamic Scroll
      • Edit
      • Floating Button
      • Gpiod
      • Grid
      • GridContainer
      • Image
      • ImageControl
      • ImageList
      • Label
      • Material Icons
      • Material Window
      • MessageBox
      • Multi Edit
      • Progress Bar
      • Progress Box
      • Radio
      • Radio Group
      • Scroll Container
      • Side Menu
      • Slider
      • Sliding Window
      • Spin List
      • Spinner
      • Switch
      • Tabbed Container
      • Velocimeter
    • APIs
      • API Overview
      • API Rest
      • Asynchronous Task
      • Camera
      • Control
        • Main Window
        • Window
        • Container
      • GPS
      • HTTPS and SSL
      • JSON
      • Maps
        • Maps - Deprecated
        • Static Map
      • Material Design Standards
      • Ninepath
      • Notifications
      • PrinterManager
      • Push Notification Firebase
      • Scanner
      • SOAP
      • Socket
      • SocketServer
      • SQLite Encryption
      • QR Code Generator
      • totalcross.sys
      • Youtube API
    • Creating an Issue
    • Contributing
      • Branch workflow
      • Writing documentation
    • Guides
      • App Architecture
        • Suggested Architecture
        • Why do Design Patterns help with the application's organization?
          • MVC Architecture Pattern
          • Template Pattern
          • Data Persistence: DAO Pattern.
        • Separation of concepts: What is the best way to create UI interfaces?
        • Positioning
          • Manual Positioning
        • Relative Positioning
        • Best practices to improve project maintenance
      • Device Simulator
      • Package your app from scratch
        • TotalCross SDK
        • Environment Variables in IDE
          • Eclipse
          • IntelliJ
        • Deploy your app with a dependecy TC
        • Deploy iOS
          • Using Development certificate to test your apps
      • Understanding TotalCross for Linux ARM
      • Running C++ applications with TotalCross
      • Web Services
    • Miscelaneous
      • Java JDK 8
      • Maven
      • Installing Visual Studio Code
    • FAQ
      • IMEI in Android 10
Powered by GitBook
On this page
  • Overview
  • Constructors
  • References

Was this helpful?

  1. Documentation
  2. APIs

SocketServer

Overview

This class implements server sockets. A server socket waits for requests to come in over the network. It may then accept the incoming TCP/IP connection and perform some operation based on that request, possibly returning a result to the requester.

ServerSocket constructors:

Constructors

Type

Name

Description

constructor

ServerSocket(int port)

Attempts to open a server socket at the specified port number. By default, the maximum number of simultaneous connections allowed is DEFAULT_BACKLOG and the default timeout for accept is DEFAULT_SOTIMEOUT, and the server is not bound to any specific local address. The port number must be between 0 and 65535.

constructor

ServerSocket(int port, int timeout)

Same as the above, but you may also specify the timeout value, in milliseconds, for the accept operation. This value must be a positive value, or 0 to wait forever.

constructor

ServerSocket(int port, int timeout, String addr)

Same as the above, but you may also specify a local address, which the server should bind to. If the argument addr has a null value, it is ignored and the server is not bind to any address.

constructor

ServerSocket(int port, int timeout, int backlog, String addr)

Same as the above, but you may also specify the maximum number of simultaneous connections allowed with the argument backlog, which must have a positive value.

You may retrieve the address and port values of this ServerSocket with getHost() and getLocalPort( ).

After creating a server socket, you may use the method accept() to wait for incoming connections. This method blocks the thread for the amount of time specified by the timeout value passed to the constructor, returning a null value when the timeout is over, or until a connection request is received and accepted, returning a socket instance representing the new connection.

The returned object is always a valid Socket instance, that may be used to transfer data between this server and the client that requested the connection, and that should be closed when no longer needed.

You should never use blocking operations on threads handling events and/or the graphical interface, otherwise the user won’t be able to interact with the application. Take a look at the source code of the sample ServerSocketTest.

Finally, you may use the method close() to close this server socket, releasing any associated resources.

Remember to close any sockets associated to this server socket before closing it. Otherwise all open sockets will throw an IOException.

References

PreviousSocketNextSQLite Encryption

Last updated 5 years ago

Was this helpful?

For more details, check out totalcross.net.ServerSocket .

JavaDoc