声明的变量
protected Socket fileSocket;
protected OutputStream os;
fileSocket = new Socket(host, port + 1);
os = fileSocket.getOutputStream();
并在下一个代码中使用
File file;
FileInputStream fis;
int readBytes;
try
{
if(fileSocket.isOutputShutdown())
{
fileSocket.setKeepAlive(true);//this line
}
sendToServer(message);
bufFileName = message.toCharArray();
fileName = new String(bufFileName, 6, bufFileName.length - 6);
file = new File(fileName);
fis = new FileInputStream(file);
while ((readBytes = fis.read()) != -1)
{
os.write(readBytes);
os.flush();
}
fileSocket.shutdownOutput();
fis.close();
clientUI.display("Trans complete");
我发送一个文件并关闭 fileSocket。
我想重用filesocket,但找不到合适的方法。应该采取什么方法或操作?