客户端(PHP):
send.php
[php]
$fp = fsockopen("127.0.0.1", 1024, $errno, $errstr, 10);
$filename = '2012_07_23.zip'; //要发送的文件
fwrite($fp, $filename . "\r\n"); //写入文件名 java端用.readLine()..第一行就是文件名
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
//fwrite($fp,$contents); //小文件可以这样发,但大文件请分段
$data_size = 1024 * 1; //每次1M
$data_count = ceil( strlen($contents) / $data_size ); //有多少块数据
for( $i = 0; $i
{
$data = substr( $contents, $i * $data_size, $data_size ); //写入到传输socket
fwrite($fp,$data); www.2cto.com
}
fclose($fp);
?>
服务端(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

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

PhpStorm 맥 버전
최신(2018.2.1) 전문 PHP 통합 개발 도구

ZendStudio 13.5.1 맥
강력한 PHP 통합 개발 환경

Atom Editor Mac 버전 다운로드
가장 인기 있는 오픈 소스 편집기

SecList
SecLists는 최고의 보안 테스터의 동반자입니다. 보안 평가 시 자주 사용되는 다양한 유형의 목록을 한 곳에 모아 놓은 것입니다. SecLists는 보안 테스터에게 필요할 수 있는 모든 목록을 편리하게 제공하여 보안 테스트를 더욱 효율적이고 생산적으로 만드는 데 도움이 됩니다. 목록 유형에는 사용자 이름, 비밀번호, URL, 퍼징 페이로드, 민감한 데이터 패턴, 웹 셸 등이 포함됩니다. 테스터는 이 저장소를 새로운 테스트 시스템으로 간단히 가져올 수 있으며 필요한 모든 유형의 목록에 액세스할 수 있습니다.

WebStorm Mac 버전
유용한 JavaScript 개발 도구
