mantendo um soquete java aberto?

Eu estou fazendo um programa / jogo que irá atualizar automaticamente. Eu tenho a parte de atualização, mas não a verificação da versão. Eu teria pensado que seria bem fácil. Aqui está o que eu fiz. Eu escrevi um atualizador para o jogo, e eu escrevi um servidor. o servidor inicia um encadeamento toda vez que um cliente / atualizador se conecta. o segmento lida com tudo. o atualizador do jogo lê um arquivo chamadoversion.txt e que fornece o número da versão (padrão 0.0.1) e envia para o servidor. o servidor recebe a versão eSystem.out.println(); se a versão corresponder e se eu alterar a versão, ela alterará a saída. então essa parte funciona. mas isso é tanto quanto vai. a segunda parte do processo é que o servidor envia apenas um arquivo de texto chamadoNPS Game.txt (ele envia qualquer coisa, mas o txt era fácil de testar) e o cliente substitui a versão antiga desse arquivo pela nova que acabou de ser enviada. O problema é que eu continuo recebendo um erro que diz que o soquete está fechado. Eu tentei usarsocket.setKeepAlive(true); mas isso não mudou nada (eu coloco isso no cliente e no servidor). aqui está o código:

servidor:

package main;

import java.io.*;
import java.net.*;

import javax.swing.JOptionPane;

public class Server {
static ServerSocket serverSocket = null;
static Socket clientSocket = null;
static boolean listening = true;

public static void main(String[] args) throws IOException {
    try {
        serverSocket = new ServerSocket(6987);
    } catch (IOException e) {
        ServerThread.showmsg("Could not use port: 6987");
        System.exit(-1);
    }

    ServerThread.showmsg("server- initialized");
    ServerThread.showmsg("server- waiting...");

    while (listening)
        new ServerThread(serverSocket.accept()).start();
}
}

thread do servidor:

package main;

import java.io.*;
import java.net.Socket;
import java.net.SocketException;

import javax.swing.JOptionPane;

public class ServerThread extends Thread {
Socket socket;
ObjectInputStream in;
ObjectOutputStream out;
String version = "0.0.1";

public ServerThread(Socket socket) {
    super("Server Thread");
    this.socket = socket;
}

public void run() {
    showmsg("server- Accepted connection : " + socket);
    getVersion();
    sendFile();
}

public void getVersion() {
    try {
        ObjectInputStream ois = new ObjectInputStream(
                socket.getInputStream());
        try {
            String s = (String) ois.readObject();
            if (s.equals(version)) {
                System.out.println("server- matched version :)");
            } else {
                System.out.println("server- didnt match version :(");
                System.exit(0);
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        ois.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

public void sendFile() {
    // sendfile
    File myFile = new File("C:\\Programming\\NPS\\Files\\bin\\NPS Game.txt");
    byte[] mybytearray = new byte[(int) myFile.length()];
    FileInputStream fis;
    try {
        fis = new FileInputStream(myFile);
        BufferedInputStream bis = new BufferedInputStream(fis);
        bis.read(mybytearray, 0, mybytearray.length);
        OutputStream os = socket.getOutputStream();
        showmsg("server- Sending...");
        os.write(mybytearray, 0, mybytearray.length);
        os.flush();
        socket.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

public static void showmsg(String s) {
    JOptionPane.showMessageDialog(null, s);
}
}

e o cliente / atualizador:

package main;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

import javax.swing.JOptionPane;

import org.omg.CORBA.portable.InputStream;

public class Connections {
String IP, port;
String message = "";
Socket socket;

public Connections(boolean server, boolean updating, String IP, String port) {
    this.IP = IP;
    this.port = port;
    try {
        socket = new Socket(IP, Integer.parseInt(port));
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    if (!server) {
        if (updating) {
            try {
                sendVersion();
                updating();
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else {
            client();
        }
    }
    if (server) {

    }
}

public void sendVersion() throws IOException {

    FileReader fileReader = new FileReader(
            "C:\\Program Files\\AVTECH\\NPS\\Files\\bin\\version.txt");
    BufferedReader bufferedReader = new BufferedReader(fileReader);

    String stringRead = bufferedReader.readLine();

    bufferedReader.close();

    ObjectOutputStream oos = new ObjectOutputStream(
            socket.getOutputStream());
    oos.writeObject(stringRead);
    oos.flush();
    oos.close();
}

public void updating() throws IOException {
    int filesize = 6022386; // filesize temporary hardcoded

    int bytesRead;
    int current = 0;

    showmsg("client- connected");

    // receive file
    byte[] byteArray = new byte[filesize];
    java.io.InputStream inStream = socket.getInputStream();
    FileOutputStream fileOutStream = new FileOutputStream(
            "C:\\Program Files\\AVTECH\\NPS\\Files\\bin\\NPS Game.txt");
    BufferedOutputStream buffOutStream = new BufferedOutputStream(
            fileOutStream);
    bytesRead = inStream.read(byteArray, 0, byteArray.length);
    current = bytesRead;

    do {
        bytesRead = inStream.read(byteArray, current,
                (byteArray.length - current));
        if (bytesRead >= 0)
            current += bytesRead;
    } while (bytesRead > -1);

    buffOutStream.write(byteArray, 0, current);
    buffOutStream.flush();
    buffOutStream.close();
    inStream.close();
    socket.close();
}

public static void showmsg(String s) {
    JOptionPane.showMessageDialog(null, s);
}
}

Eu não sei o que há de errado com isso, mas é realmente frusturante. Se alguém puder ajudar ficariamos agradecidos. algumas coisas que eu fiz: google todos os tipos de perguntas, tentei implementarsocket.setKeepAlive(true);. Além disso, eu pensei que poderia ser de nota, no thread do servidor, logo acima da linhaBufferedInputStream bis = new BufferedInputStream(fis);, Eu colocoSystem.out.println(socket.isClosed); e isso retornou verdadeiro. isso é tudo o que eu tenho. desde já, obrigado!

questionAnswers(1)

yourAnswerToTheQuestion