Tcppic image upload stand-alone

Source: Internet
Author: User

Package com.tz.util.screen;

Import Java.io.FileInputStream;
Import Java.io.FileOutputStream;
Import Java.io.InputStream;
Import Java.io.OutputStream;
Import Java.net.ServerSocket;
Import Java.net.Socket;

/**
* Image upload
* Customer Service side
* 1. Service Endpoint
* 2. Read the image data from the customer service side
* 3. Send data to server via socket output stream
* 4. Read the service side feedback information
* 5. Close
* @author Administrator
*
*/

public class Tcppic {

 public static void Main (string[] args) throws Exception, Exception {
  socket s=new Socket (" 192.168.1.254 ", 10007);
  
  fileinputstream fis=new fileinputstream ("1.bmp");
  outputstream Out=s.getoutputstream ();
  byte[] Buf=new byte[1024];
  int len=0;
  while ((Len=fis.read (BUF))!=-1) {
   out.write (buf,0,len);
  }
  //tells the server to finish writing
  s.shutdownoutput ();
  inputstream In=s.getinputstream ();
  byte[] Bufin=new byte[1024];
  int Num=in.read (Bufin);
  system.out.println (New String (Bufin,0,num));
  fis.close ();
  s.close ();
 }

}
/**
* Service Side
*/
Class picserver{
public static void Main (string[] args) throws Exception {
ServerSocket ss=new ServerSocket (10007);
Socket s=ss.accept ();
InputStream In=s.getinputstream ();
FileOutputStream fos=new FileOutputStream ("server.bmp");
Byte[] Buf=new byte[1024];
int len=0;
while ((Len=in.read (BUF))!=-1) {
Fos.write (Buf,0,len);
}
OutputStream Out=s.getoutputstream ();
Out.write ("Upload succeeded". GetBytes ());
Fos.close ();
S.close ();
Ss.close ();
}
}

Tcppic image upload stand-alone

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.