package com.github.noxan.aves.server;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketTimeoutException;

import com.github.noxan.aves.net.Connection;
import com.github.noxan.aves.net.SocketConnection;

public class SocketServer implements Server, Runnable {
    private String host;
    private int port;

    private ServerSocket server;

    public SocketServer() {
	this("0.0.0.0", 1666);
    }

    public SocketServer(String host, int port) {
	this.host = host;
	this.port = port;
    }

    @Override
    public void start() {
	try {
	    server = new ServerSocket();
	    server.setSoTimeout(1000);
	    server.bind(new InetSocketAddress(host, port));
	} catch (IOException e) {
	    e.printStackTrace();
	}
    }

    @Override
    public void run() {
	while (true) {
	    try {
		Socket socket = server.accept();
		Connection connection = new SocketConnection(this, socket);
	    } catch (SocketTimeoutException e) {
	    } catch (IOException e) {
		e.printStackTrace();
	    }
	}
    }

    @Override
    public String getHost() {
	return host;
    }

    @Override
    public int getPort() {
	return port;
    }
}

@@ -188,16 +188,64 @@
 ception;
+%0Aimport java.util.HashSet;%0Aimport java.util.Set;
 %0A%0Aimport
@@ -439,16 +439,58 @@
  port;%0A%0A
+    private Set%3CConnection%3E connections;%0A%0A
     priv
@@ -642,16 +642,16 @@
 = host;%0A
-
 %09this.po
@@ -657,24 +657,66 @@
 ort = port;%0A
+%09connections = new HashSet%3CConnection%3E();%0A
     %7D%0A%0A    @

add connection hash set to socketserver to store all connections