客户端(php):
send.php
[php]
服务端(java):
myapp.java
[java]
import java.io.*;
import java.net.*;
import java.util.date;
import java.sql.*;
public class myapp
{
private int x;
public myapp()
{
x = 0;
}
public static void main(string args[]) {
int i = 1, port = 1024;
serversocket server=null;
socket client = null;
try{
server=new serversocket(port);
system.out.println(web server is listening on port + server.getlocalport());
for(;;){
client=server.accept();
//接受客户机的连接请求
new webthread(client,i).start();
i++;
}
}catch(exception e){system.out.println(e);}
}
}
webthread.java
[java]
import java.io.*;
import java.net.*;
import java.util.date;
class webthread extends thread{
socket socket;//连接web浏览器的socket字
int counter;//计数器
public webthread(socket cl,int c){
socket=cl;
counter=c;
}
public void run()//线程体
{
try
{
datainputstream inputstream = null;
try
{
inputstream = new datainputstream(new bufferedinputstream(socket.getinputstream()));
}catch(exception e)
{
}
try
{
string savepath = e:\\;
int buffersize = 8192;
byte[] buf = new byte[buffersize];
string filename = new string();
filename = inputstream.readline();
string savefilepath = new string();
savefilepath = savepath + \\ + filename;
dataoutputstream fileout = new dataoutputstream(new bufferedoutputstream(new bufferedoutputstream(new fileoutputstream(savefilepath))));
system.out.println(文件长名为: + filename);
while (true)
{
int read = 0;
if (inputstream != null)
{
read = inputstream.read(buf);
}
if (read == -1) {
break;
}
//system.out.println(buf.tostring());
fileout.write(buf, 0, read);
}
system.out.println(接收完成,文件存为 + savefilepath + \n);
fileout.flush();
fileout.close();
inputstream.close();
} catch (exception e) {
system.out.println(接收消息错误 + e.tostring() + \n);
return;
}
}catch(exception e){
}
}
}
作者:junqing124
http://www.bkjia.com/phpjc/478073.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/478073.htmltecharticle客户端(php): send.php [php] ?php $fp = fsockopen(127.0.0.1, 1024, $errno, $errstr, 10); $filename = 2012_07_23.zip; //要发送的文件 fwrite($fp, $filename . \r\n); //写入文...