package edu.govschool.govchat.socket;

// For input/output streams
import java.io.*;
// For built-in sockets
import java.net.*;
// For Platform.runLater()
import javafx.application.Platform;

/**
 * Generic socket to extend for use in GovChat.
 * Based on Oracle documentation.
 * Abstract classes must have their abstract methods implemented in a subclass,
 * which will happen in <code>GCClientSocket</code> and 
 * <code>GCServerSocket</code>. We define this 'generic' socket, however, 
 * because both the client and server sockets share a lot of the same code.
 * @author Mr. Davis
 */
public abstract class GCGenericSocket implements GCSocketListener
{
    // For testing purposes, we'll use a default port of 2000.
    // It is defined here in the superclass because both the
    // client and server need to agree on the port.
    public static final int DEFAULT_PORT = 2000;
    
    // The port we'll be using
    public int port;
    // The Socket connection we'll be using
    // `protected` means that we and our subclasses can access this property, 
    // no classes outside us.
    protected Socket socketConncetion = null;
    // Streams to perform I/O
    private BufferedWriter output = null;
    private BufferedReader input = null;
    // Flag to see if our setup has completed
    private boolean ready = false;
    // Thread to setup our connection
    private Thread setupThread;
    // Thread to read message from our connection
    private Thread readerThread;
}
@@ -1480,9 +1480,1881 @@
 Thread;%0A
+    %0A    /**%0A     * Empty constructor.%0A     * Creates a new %3Ccode%3EGCGenericSocket%3C/code%3E on port 2000.%0A     */%0A    public GCGenericSocket()%0A    %7B%0A        this(DEFAULT_PORT);%0A    %7D%0A    %0A    /**%0A     * Default constructor.%0A     * Creates a new %3Ccode%3EGCGenericSocket%3C/code%3E on the given port.%0A     * @param port the port to bind to%0A     */%0A    public GCGenericSocket(int port)%0A    %7B%0A        this.port = port;%0A    %7D%0A    %0A    /**%0A     * Setup a connection in the background.%0A     * Later, %3Ccode%3EonCloseUpdate(boolean)%3C/code%3E will be called if this method%0A     * successfully completes.%0A     */%0A    public void connect()%0A    %7B%0A        try %7B%0A            // Open the socket connection in the background and setup our I/O %0A            // streams%0A            setupThread = new SocketSetupThread();%0A            setupThread.start();%0A            // Start the thread that will listen for message on the input stream%0A            // in the background%0A            readerThread = new SocketReaderThread();%0A            readerThread.start();%0A        %7D catch (Exception e) %7B%7D // You dun goofed!%0A    %7D%0A    %0A    /**%0A     * Setup our initial connection in the background.%0A     * Normally, our entire application would have to wait until the connection%0A     * occurred before continuing. However, since we will be doing it in a %0A     * %3Ccode%3EThread%3C/code%3E, it will happen in the background.%0A     */%0A    private class SocketSetupThread extends Thread%0A    %7B%0A        @Override%0A        public void run()%0A        %7B%0A            %0A        %7D%0A    %7D%0A    %0A    /**%0A     * Listen for messages in the background.%0A     * Again, our application would seem to freeze while waiting for messages.%0A     * We need to try to read from the input stream in the background.%0A     */%0A    private class SocketReaderThread extends Thread%0A    %7B%0A        @Override%0A        public void run()%0A        %7B%0A            %0A        %7D%0A    %7D%0A
 %7D

Add stubs for private setup and reader thread classes in GCGenericSocket, as well as an implementation for connect() showing usage.