Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

sending file over socket stream

public class Server {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = null;

        try {
            serverSocket = new ServerSocket(4444);
        } catch (IOException ex) {
            System.out.println("Can't setup server on this port number. ");
        }

        Socket socket = null;
        InputStream in = null;
        OutputStream out = null;
        
        try {
            socket = serverSocket.accept();
        } catch (IOException ex) {
            System.out.println("Can't accept client connection. ");
        }
        
        try {
            in = socket.getInputStream();
        } catch (IOException ex) {
            System.out.println("Can't get socket input stream. ");
        }

        try {
            out = new FileOutputStream("M:	est2.xml");
        } catch (FileNotFoundException ex) {
            System.out.println("File not found. ");
        }

        byte[] bytes = new byte[16*1024];

        int count;
        while ((count = in.read(bytes)) > 0) {
            out.write(bytes, 0, count);
        }

        out.close();
        in.close();
        socket.close();
        serverSocket.close();
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: licenceurl 
Java :: bipredicate in java 
Java :: komplettes array ausgeben java 
Java :: how to find length of string array java 
Java :: download a website as string kotlin 
Java :: int p=10, q; switch(p) { case1: q=p*2; break; case2: q=p+2; break; case3: q=p-2; break; } 
Java :: reversing an integer with overflow handled 
Java :: has places api got deprecated??? 
Java :: retrofit interface 
Java :: how to get visibility of element android 
Java :: java this keyword 
Java :: java get if contains else 0 
Java :: getarguments().getstring updates android 
Java :: remove minimum element from stack java 
Java :: adding matrix 
Java :: priority queue is empty java 
Java :: RTC_WAKEUP 
Java :: Jax-RS POST annotation 
Java :: Returning methods 
Java :: how to print multi dimension array in java using for each loop 
Java :: what is the use of the tolowercase in java 
Java :: What is the name of the Android function that is used to update the UI (user interface) from a background thread? 
Java :: boolean parse jtextfield 
Java :: resultset previous 
Java :: take string , double and int value from useer using java 
Java :: how do i get DefaultTableModel rows sum in column in java 
Java :: How to Register a Custom Auto-Configuration? 
Java :: firemonkey android ini file read 
Java :: For loop in selenium java li 
Java :: Buscando Objeto do Array 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =