--- /dev/null
+/*
+ * XdccDownloader - NetworkAcceptor.java - Copyright © 2013 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.xdcc.ui.stdin;
+
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.SocketTimeoutException;
+import java.util.concurrent.TimeUnit;
+
+import net.pterodactylus.xdcc.core.Core;
+
+import com.google.common.util.concurrent.AbstractExecutionThreadService;
+
+/**
+ * Listens on a TCP port and feeds input and output to a {@link CommandReader}.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class NetworkAdapter extends AbstractExecutionThreadService {
+
+ /** The core being controlled. */
+ private final Core core;
+
+ /**
+ * Creates a new network acceptor.
+ *
+ * @param core
+ * The core being controlled
+ */
+ public NetworkAdapter(Core core) {
+ this.core = core;
+ }
+
+ @Override
+ protected void run() throws Exception {
+ ServerSocket serverSocket = new ServerSocket(45678);
+ serverSocket.setSoTimeout((int) TimeUnit.SECONDS.toMillis(1));
+ while (isRunning()) {
+ try {
+ Socket clientSocket = serverSocket.accept();
+ InputStream socketInputStream = clientSocket.getInputStream();
+ OutputStream socketOutputStream = clientSocket.getOutputStream();
+ final InputStreamReader socketInputStreamReader = new InputStreamReader(socketInputStream, "UTF-8");
+ final OutputStreamWriter socketOutputStreamWriter = new OutputStreamWriter(socketOutputStream, "UTF-8");
+ new CommandReader(core, socketInputStreamReader, socketOutputStreamWriter).start();
+ } catch (SocketTimeoutException ste1) {
+ /* ignore, loop. */
+ }
+ }
+ }
+
+}