In a simple example, there is no interface but code.
Server code
Package server; import Java. io. bufferedinputstream; import Java. io. bufferedoutputstream; import Java. io. datainputstream; import Java. io. dataoutputstream; import Java. io. fileinputstream; import java.net. serversocket; import java.net. socket; public class androidserver implements runnable {private serversocket = NULL; private datainputstream is; Public void run () {If (serversocket = NULL) {try {se Rversocket = new serversocket (5926);} catch (exception e) {e. printstacktrace () ;}try {Socket socket = serversocket. accept (); is = new datainputstream (New bufferedinputstream (New fileinputstream ("D: \ test.mp4"); // upload the file to be uploaded, put inputstreamdataoutputstream OS = new dataoutputstream (New bufferedoutputstream (socket. getoutputstream (); // initialize the socket outputstreamint count; byte [] buffer = new byte [1024]; W Hile (COUNT = is. Read (buffer, 0, buffer. Length ))! =-1) {// put the file into the socket outputstream OS. write (buffer, 0, count);} OS. flush (); serversocket. close (); socket. close ();} catch (exception e) {e. printstacktrace () ;}} public static void main (string [] ARGs) {thread publish topserverthread = new thread (New androidserver (); // start the Service publish topserverthread. start ();}}
Client code
Import Java. io. bufferedoutputstream; import Java. io. datainputstream; import Java. io. dataoutputstream; import Java. io. file; import Java. io. fileoutputstream; import java.net. socket; public class test {public static void main (string [] ARGs) {try {Socket socket = new socket ("192.168.0.228", 5926); datainputstream Dis = new datainputstream (socket. getinputstream (); // obtain inputstreamdataoutputstream OS = New dataoutputstream (New bufferedoutputstream (New fileoutputstream (new file ("D: \ fuck"); // initialize outputstreamint COUNT = 0; byte [] buffer = new byte [1024]; while (COUNT = dis. read (buffer ))! =-1) {// put inputstream in socket into outputstreamos. write (buffer, 0, count);} OS. close (); socket. close (); // the upload is complete. Close socket} catch (exception e) {e. printstacktrace () ;}finally {}}}