Java TCP communication socket uses Image Upload to bomb the server, socket Image Upload

Source: Internet
Author: User

Java TCP communication socket uses Image Upload to bomb the server, socket Image Upload

Client

Package com. swift. jinji; import java. io. fileInputStream; import java. io. IOException; import java. io. inputStream; import java. io. outputStream; import java.net. socket;/* project requirement: Use socket to write a Java program. Requirements: the client uploads files to the server, that is, the client reads local text files and sends the files to the server, the server stores the received content in a text file. */Public class UploadClient {static int I = 1024; public static void main (String [] args) throws IOException, IOException {while (true) {if (I <65535) {System. out. println (I); Socket s = new Socket ("192.168.122.35", 20000); FileInputStream FD = new FileInputStream ("d:/abc/0.jpg"); OutputStream out = s. getOutputStream (); byte [] buf = new byte [1024]; int len; while (len = Fi. read (buf ))! =-1) {// at this time, the socket stream write below does not write-1, because it stops out when it reaches-1. write (buf, 0, len);} s. shutdownOutput (); InputStream in = s. getInputStream (); len = in. read (buf); System. out. println (new String (buf, 0, len ));}}}}

The server must enable the socket of the upload and receive client.

Package com. swift. jinji; import java. io. file; import java. io. fileOutputStream; import java. io. IOException; import java. io. inputStream; import java. io. outputStream; import java.net. serverSocket; import java.net. socket; public class UploadServer {public static void main (String [] args) throws IOException {ServerSocket serverSocket = new ServerSocket (20000); while (true) {System. out. println ("waiting for client connection"); Sock Et s = serverSocket. accept (); System. out. println ("Client Connected successfully" + s); byte [] buf = new byte [1024]; int len; File destDir = new File ("d:/upload "); if (! DestDir. exists () {destDir. mkdirs ();} FileOutputStream fos = new FileOutputStream (new File (destDir, System. currentTimeMillis () + "_0.jpg"); InputStream in = s. getInputStream (); while (len = in. read (buf ))! =-1) {fos. write (buf, 0, len);} System. out. println ("111111111111111"); OutputStream out = s. getOutputStream (); out. write ("Upload successful ". getBytes (); s. close ();}}}

The result is that tens of thousands of images will be taken to the server in an instant.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.