import java.io.*;
import java.net.*;
import java.util.*;
import java.sql.*;
import javax.swing.*;
import java.lang.*;
public class PooledRemoteFileServer extends Thread {//2002-08-22
protected int maxConnections;
protected int listenPort;
protected ServerSocket serversocket=null;
private Vector clientSocketVect=new Vector(); //2002-08-22
private Vector handlethread = new Vector();
public PooledRemoteFileServer(int aListenPort, int maxConnections) {
listenPort = aListenPort;
this.maxConnections = maxConnections;
}
public void acceptConnections(){
try {
serversocket = new ServerSocket(listenPort, maxConnections);
Socket incomingConnection = null;
Frame1.b_run = true; //2002-08-22
while(true) {
incomingConnection = serversocket.accept();
clientSocketVect.add(incomingConnection); //2002-08-22
handleConnection(incomingConnection);
}
}
catch (Exception e){
System.out.println(e.getMessage());
}
}
public void shutOff() {
try {
Socket psock = null;
PooledConnectionHandler temphandler=null;
//清空所有socket
for (int i=0;i<clientSocketVect.size();i++) {
psock = (Socket)clientSocketVect.get(i); // 2002-08-08
psock.close(); // 2002-08-08
psock = null; // 2002-08-08
}
clientSocketVect.clear();
serversocket.close();
serversocket = null;
//清空所有线程
for(int j=0;j<handlethread.size();j++)
{
temphandler=(PooledConnectionHandler)handlethread.get(j);
temphandler=null;
}
handlethread.clear();
}
catch(IOException excpt) {
System.err.println("Failed I/O: "+ excpt);
}
}
public void setUpHandlers() {
for (int i = 0; i < maxConnections; i++) {
PooledConnectionHandler currentHandler = new PooledConnectionHandler();
handlethread.add(currentHandler);
new Thread(currentHandler, "Handler " + i).start();
}
}
protected void handleConnection(Socket connectionToHandle) {
PooledConnectionHandler.processRequest(connectionToHandle);//线程池处理
} // 2002-08-22
public void run() {
this.setUpHandlers();
this.acceptConnections();
}
// 2002-08-22
}
import java.net.*;
import java.util.*;
import java.sql.*;
import javax.swing.*;
import java.lang.*;
public class PooledRemoteFileServer extends Thread {//2002-08-22
protected int maxConnections;
protected int listenPort;
protected ServerSocket serversocket=null;
private Vector clientSocketVect=new Vector(); //2002-08-22
private Vector handlethread = new Vector();
public PooledRemoteFileServer(int aListenPort, int maxConnections) {
listenPort = aListenPort;
this.maxConnections = maxConnections;
}
public void acceptConnections(){
try {
serversocket = new ServerSocket(listenPort, maxConnections);
Socket incomingConnection = null;
Frame1.b_run = true; //2002-08-22
while(true) {
incomingConnection = serversocket.accept();
clientSocketVect.add(incomingConnection); //2002-08-22
handleConnection(incomingConnection);
}
}
catch (Exception e){
System.out.println(e.getMessage());
}
}
public void shutOff() {
try {
Socket psock = null;
PooledConnectionHandler temphandler=null;
//清空所有socket
for (int i=0;i<clientSocketVect.size();i++) {
psock = (Socket)clientSocketVect.get(i); // 2002-08-08
psock.close(); // 2002-08-08
psock = null; // 2002-08-08
}
clientSocketVect.clear();
serversocket.close();
serversocket = null;
//清空所有线程
for(int j=0;j<handlethread.size();j++)
{
temphandler=(PooledConnectionHandler)handlethread.get(j);
temphandler=null;
}
handlethread.clear();
}
catch(IOException excpt) {
System.err.println("Failed I/O: "+ excpt);
}
}
public void setUpHandlers() {
for (int i = 0; i < maxConnections; i++) {
PooledConnectionHandler currentHandler = new PooledConnectionHandler();
handlethread.add(currentHandler);
new Thread(currentHandler, "Handler " + i).start();
}
}
protected void handleConnection(Socket connectionToHandle) {
PooledConnectionHandler.processRequest(connectionToHandle);//线程池处理
} // 2002-08-22
public void run() {
this.setUpHandlers();
this.acceptConnections();
}
// 2002-08-22
}
protected Socket connection;
int recno=-999;
private static int iOnLine = 0; //2002-08-23
protected static List pool = new LinkedList();
String loginuser="";
public PooledConnectionHandler() {
}
//把文件和目录填入列表中
public static void lookindir(File f,Vector pDirs,Vector pFiles) {
if(f.isDirectory()==true) {
pDirs.add(f);
File[] children = f.listFiles();
for(int i=0;i<children.length;i++) {
lookindir(children[i],pDirs,pFiles);
}
}
else if(f.isFile()==true) {
pFiles.add(f);
}
}
//处理客户上传
public String findaserial(String ENDDOMAIN,String ENDUSER) {
String iniFileName="";
String dbusername="";
String dbpassword="";
String dbserverip="";
String sqlstring="";
Connection conn = null;
ResultSet rs = null;
String aserial="";
iniFileName=System.getProperty("user.dir");
if(iniFileName.substring(iniFileName.length()-1).equals(System.getProperty("file.separator"))!=true)
iniFileName =iniFileName + System.getProperty("file.separator");
iniFileName =iniFileName+"opt"+System.getProperty("file.separator")+"server.ini";
xpInifile pini = new xpInifile(iniFileName);
dbusername=pini.getvalue("dbopt","dbusername").trim();
dbpassword=pini.getvalue("dbopt","dbpassword").trim();
dbserverip=pini.getvalue("dbopt","dbserverip").trim();
String DBDriver="org.gjt.mm.mysql.Driver";
String ConnStr="jdbc:mysql://"+dbserverip+":3306/FileServer";
try {
try {
Class.forName(DBDriver);
conn = DriverManager.getConnection(ConnStr,dbusername,dbpassword);
sqlstring ="select * from T_RECEIVESERIAL where ENDDOMAIN='"+
ENDDOMAIN.trim()+"' And ENDUSER='"+ENDUSER.trim()+"'"+" and STATUS=0";
// new String(ENDDOMAIN.getBytes("GBK"),"ISO-8859-1")+"\'"+" and ENDUSER=\'"+
// new String(ENDUSER.getBytes("GBK"),"ISO-8859-1")+"\' and STATUS=0";
rs=conn.createStatement().executeQuery(sqlstring);
rs.next();
aserial=rs.getString("SERIAL").trim();
rs.close();
conn.close();
}
catch(Exception e) {
System.out.println(e.getMessage());
}
}
finally {
return aserial;
}
}
public boolean haveDownloadcontent(String ENDDOMAIN,String ENDUSER) {
String iniFileName="";
String dbusername="";
String dbpassword="";
String dbserverip="";
String sqlstring="";
Connection conn = null;
ResultSet rs = null;
Statement stmt=null;
recno=0; iniFileName=System.getProperty("user.dir");
if(iniFileName.substring(iniFileName.length()-1).equals(System.getProperty("file.separator"))!=true)
iniFileName =iniFileName + System.getProperty("file.separator");
iniFileName =iniFileName+"opt"+System.getProperty("file.separator")+"server.ini"; xpInifile pini = new xpInifile(iniFileName);
dbusername=pini.getvalue("dbopt","dbusername").trim();
dbpassword=pini.getvalue("dbopt","dbpassword").trim();
dbserverip=pini.getvalue("dbopt","dbserverip").trim();
String DBDriver="org.gjt.mm.mysql.Driver";
String ConnStr="jdbc:mysql://"+dbserverip+":3306/FileServer"; try {
try {
Class.forName(DBDriver);
conn = DriverManager.getConnection(ConnStr,dbusername,dbpassword);
sqlstring ="select count(*) as mycount from T_RECEIVESERIAL where ENDDOMAIN='"+
ENDDOMAIN.trim()+"'"+" and ENDUSER='"+ENDUSER.trim()+"'";
//new String(ENDDOMAIN.getBytes("GBK"),"ISO-8859-1")+"'"+" and ENDUSER='"+
//new String(ENDUSER.getBytes("GBK"),"ISO-8859-1")+"' and STATUS=0";
stmt=conn.createStatement();
rs=stmt.executeQuery(sqlstring);
//rs.next();
recno=rs.getInt("mycount");
rs.close();
stmt.close();
conn.close();
}
catch(Exception e) {
System.out.println(e.getMessage());
}
}
finally {
return recno>0;
}
}
//写序列给客户
public void writerecserialtoclient(ObjectOutputStream objOut,String recserial) {
String iniFileName="";
String dbusername="";
String dbpassword="";
String dbserverip="";
String sqlstring="";
Connection conn = null;
ResultSet rs = null;
t_recserial t_recserialbag=new t_recserial();
iniFileName=System.getProperty("user.dir");
if(iniFileName.substring(iniFileName.length()-1).equals(System.getProperty("file.separator"))!=true)
iniFileName =iniFileName + System.getProperty("file.separator");
iniFileName =iniFileName+"opt"+System.getProperty("file.separator")+"server.ini";
xpInifile pini = new xpInifile(iniFileName);
dbusername=pini.getvalue("dbopt","dbusername").trim();
dbpassword=pini.getvalue("dbopt","dbpassword").trim();
dbserverip=pini.getvalue("dbopt","dbserverip").trim();
String DBDriver="org.gjt.mm.mysql.Driver";
String ConnStr="jdbc:mysql://"+dbserverip+":3306/FileServer";
try {
try {
Class.forName(DBDriver);
conn = DriverManager.getConnection(ConnStr,dbusername,dbpassword);
sqlstring ="select * from T_RECEIVESERIAL where SERIAL=\'"+recserial+"\'";
rs=conn.createStatement().executeQuery(sqlstring);
rs.next();
t_recserialbag.STARTDOMAIN=rs.getString("STARTDOMAIN").trim();
t_recserialbag.STARTUSER=rs.getString("STARTUSER").trim();
t_recserialbag.ENDDOMAIN=rs.getString("ENDDOMAIN").trim();
t_recserialbag.ENDUSER=rs.getString("ENDUSER").trim();
t_recserialbag.AMOUNT=rs.getInt("AMOUNT");
t_recserialbag.SERIALNO=recserial.trim();
rs.close();
conn.close();
objOut.reset();
objOut.writeObject(t_recserialbag);
objOut.flush();
}
catch(Exception e) {
System.out.println(e.getMessage());
}
}
finally { }
}