用socket在两台机子之间传文件,在JDK1.3运行正常,在1.4下却不行,大侠帮忙!
----SockServer----
package socket;
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
public class SockServer {
/** The TCP port for the object time service. */
public static final short LISTEN_PORT = 1951;
public static void main(String[] argv) {
ServerSocket sock;
Socket clientSock;
try {
sock = new ServerSocket(LISTEN_PORT);
while (true) {
clientSock = sock.accept( );
System.out.println("Accept from " + clientSock.getInetAddress( ));
DataOutputStream dos = new DataOutputStream(new FileOutputStream("graphInfobak.dat"));
DataInputStream dis = new DataInputStream(clientSock.getInputStream());
while(dis.available()!=0){
int i = dis.read();
dos.write(i);
}
dos.flush();
dis.close();
dos.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
---SockClient---
package socket;
import java.io.*;
import java.net.Socket;
/**
* DaytimeObject - connect to the Daytime (ascii) service.
*/
public class SockClient {
/** The TCP port for the object time service. */
public static final short LISTEN_PORT = 1951;
public static void main(String[] argv) {
String hostName = null;
if (argv.length == 0) {
System.err.println("Usage: filename");
System.exit(1);
}
hostName = argv[0];
try {
Socket sock = new Socket(hostName, LISTEN_PORT);
DataOutputStream dos = new DataOutputStream(
new BufferedOutputStream(sock.getOutputStream()));
DataInputStream dis = new DataInputStream(
new BufferedInputStream(
new FileInputStream("graphInfo.dat")));
while (dis.available() != 0) {
dos.write(dis.read());
}
dos.flush();
dis.close();
dos.close();
} catch (IOException e) {
System.err.println(e);
}
}
}