Created
August 17, 2011 23:56
-
-
Save showsky/1152958 to your computer and use it in GitHub Desktop.
socket send file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedInputStream; | |
import java.io.BufferedOutputStream; | |
import java.io.File; | |
import java.io.FileOutputStream; | |
import java.net.Socket; | |
public class Client { | |
public static void main(String[] args) throws Exception { | |
Socket server = new Socket("192.168.1.100", 10000); | |
File filename = new File("xxx.ppt"); | |
FileOutputStream output = new FileOutputStream(filename); | |
BufferedOutputStream b_output = new BufferedOutputStream(output); | |
BufferedInputStream input = new BufferedInputStream(server.getInputStream()); | |
int len; | |
while((len = input.read()) != -1) { | |
b_output.write(len); | |
} | |
input.close(); | |
b_output.close(); | |
server.close(); | |
System.out.println("end"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedInputStream; | |
import java.io.BufferedOutputStream; | |
import java.io.File; | |
import java.io.FileInputStream; | |
import java.io.ObjectOutputStream.PutField; | |
import java.net.ServerSocket; | |
import java.net.Socket; | |
import javax.imageio.stream.FileImageOutputStream; | |
import javax.print.attribute.standard.MediaSize.Other; | |
public class Server { | |
public static void main(String[] args) throws Exception { | |
ServerSocket service = new ServerSocket(10000); | |
File filename = new File("FT732-009.ppt"); | |
FileInputStream input = new FileInputStream(filename); | |
BufferedInputStream b_input = new BufferedInputStream(input); | |
Socket pc = service.accept(); | |
System.out.println(pc.getInetAddress()); | |
BufferedOutputStream output = new BufferedOutputStream(pc.getOutputStream()); | |
int len; | |
while((len = b_input.read()) != -1) { | |
output.write(len); | |
} | |
System.out.println("end"); | |
output.flush(); | |
output.close(); | |
input.close(); | |
pc.close(); | |
service.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment