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