2 * Jexer - Java Text User Interface
4 * License: LGPLv3 or later
6 * This module is licensed under the GNU Lesser General Public License
7 * Version 3. Please see the file "COPYING" in this directory for more
8 * information about the GNU Lesser General Public License Version 3.
10 * Copyright (C) 2015 Kevin Lamonte
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 3 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this program; if not, see
24 * http://www.gnu.org/licenses/, or write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
28 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
33 import java
.io
.IOException
;
34 import java
.net
.InetAddress
;
35 import java
.net
.ServerSocket
;
36 import java
.net
.Socket
;
37 import java
.net
.SocketException
;
40 * This class provides a ServerSocket that return TelnetSocket's in accept().
42 public final class TelnetServerSocket
extends ServerSocket
{
44 // ServerSocket interface -------------------------------------------------
47 * Creates an unbound server socket.
49 * @throws IOException if an I/O error occurs
51 public TelnetServerSocket() throws IOException
{
56 * Creates a server socket, bound to the specified port.
58 * @param port the port number, or 0 to use a port number that is
59 * automatically allocated.
60 * @throws IOException if an I/O error occurs
62 public TelnetServerSocket(final int port
) throws IOException
{
67 * Creates a server socket and binds it to the specified local port
68 * number, with the specified backlog.
70 * @param port the port number, or 0 to use a port number that is
71 * automatically allocated.
72 * @param backlog requested maximum length of the queue of incoming
74 * @throws IOException if an I/O error occurs
76 public TelnetServerSocket(final int port
,
77 final int backlog
) throws IOException
{
83 * Create a server with the specified port, listen backlog, and local IP
86 * @param port the port number, or 0 to use a port number that is
87 * automatically allocated.
88 * @param backlog requested maximum length of the queue of incoming
90 * @param bindAddr the local InetAddress the server will bind to
91 * @throws IOException if an I/O error occurs
93 public TelnetServerSocket(final int port
, final int backlog
,
94 final InetAddress bindAddr
) throws IOException
{
96 super(port
, backlog
, bindAddr
);
100 * Listens for a connection to be made to this socket and accepts it. The
101 * method blocks until a connection is made.
103 * @return the new Socket
104 * @throws IOException if an I/O error occurs
107 public Socket
accept() throws IOException
{
109 throw new SocketException("Socket is closed");
112 throw new SocketException("Socket is not bound");
115 Socket socket
= new TelnetSocket();