| 1 | /** |
| 2 | * Jexer - Java Text User Interface |
| 3 | * |
| 4 | * License: LGPLv3 or later |
| 5 | * |
| 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. |
| 9 | * |
| 10 | * Copyright (C) 2015 Kevin Lamonte |
| 11 | * |
| 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. |
| 16 | * |
| 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. |
| 21 | * |
| 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 |
| 26 | * 02110-1301 USA |
| 27 | * |
| 28 | * @author Kevin Lamonte [kevin.lamonte@gmail.com] |
| 29 | * @version 1 |
| 30 | */ |
| 31 | package jexer.net; |
| 32 | |
| 33 | import java.io.InputStream; |
| 34 | import java.io.IOException; |
| 35 | import java.io.OutputStream; |
| 36 | import java.net.InetAddress; |
| 37 | import java.net.ServerSocket; |
| 38 | import java.net.Socket; |
| 39 | |
| 40 | /** |
| 41 | * This class provides a ServerSocket that return TelnetSocket's in accept(). |
| 42 | */ |
| 43 | public final class TelnetServerSocket extends ServerSocket { |
| 44 | |
| 45 | // ServerSocket interface ------------------------------------------------- |
| 46 | |
| 47 | /** |
| 48 | * Creates an unbound server socket. |
| 49 | */ |
| 50 | public TelnetServerSocket() throws IOException { |
| 51 | super(); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Creates a server socket, bound to the specified port. |
| 56 | */ |
| 57 | public TelnetServerSocket(final int port) throws IOException { |
| 58 | super(port); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Creates a server socket and binds it to the specified local port |
| 63 | * number, with the specified backlog. |
| 64 | */ |
| 65 | public TelnetServerSocket(final int port, |
| 66 | final int backlog) throws IOException { |
| 67 | |
| 68 | super(port, backlog); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Create a server with the specified port, listen backlog, and local IP |
| 73 | * address to bind to. |
| 74 | */ |
| 75 | public TelnetServerSocket(final int port, final int backlog, |
| 76 | final InetAddress bindAddr) throws IOException { |
| 77 | |
| 78 | super(port, backlog, bindAddr); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Listens for a connection to be made to this socket and accepts it. The |
| 83 | * method blocks until a connection is made. |
| 84 | */ |
| 85 | @Override |
| 86 | public Socket accept() throws IOException { |
| 87 | Socket socket = super.accept(); |
| 88 | return new TelnetSocket(socket); |
| 89 | } |
| 90 | |
| 91 | } |