Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how to create a udp protocol for transfer a big quantity of files java

public class EchoServer extends Thread {

    private DatagramSocket socket;
    private boolean running;
    private byte[] buf = new byte[256];

    public EchoServer() {
        socket = new DatagramSocket(4445);
    }

    public void run() {
        running = true;

        while (running) {
            DatagramPacket packet 
              = new DatagramPacket(buf, buf.length);
            socket.receive(packet);
            
            InetAddress address = packet.getAddress();
            int port = packet.getPort();
            packet = new DatagramPacket(buf, buf.length, address, port);
            String received 
              = new String(packet.getData(), 0, packet.getLength());
            
            if (received.equals("end")) {
                running = false;
                continue;
            }
            socket.send(packet);
        }
        socket.close();
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: subtract two variables in java 
Java :: java scanner use all symbols as delimiter 
Java :: import r android 
Java :: Error in .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl, : java.util.zip.ZipException: invalid code -- missing end-of-block 
Java :: foreign keys in json 
Java :: how to create gravity in Java 
Java :: Caused by: java.lang.IllegalStateException: stream has already been operated upon or closed 
Java :: java random number generator 6 
Java :: what does put extra do? 
Java :: how to return custom value in api spring boot 
Java :: android set socket timeout 
Java :: val kotlin to Java 
Java :: how to know when user is done typing android 
Java :: informaticapc 
Java :: castle stones java qn 
Java :: customize the androidx.appcompat.widget.SearchView site:stackoverflow.com 
Java :: java boolean zen 
Java :: java get end of date 
Java :: java operator 
Java :: create generator hibernate 
Java :: method reference java 
Java :: javafx check if enter pressed 
Java :: This version of the Android Support plugin for IntelliJ IDEA (or Android Studio) cannot open this project, please retry with version 2020.3.1 or newer. 
Java :: JavaFX font display issue on Mac 
Java :: class BuildConfig is public, should be declared in a file named BuildConfig.java 
Java :: android studio java catch empty button 
Java :: java como comprobar que un numero es entero? 
Java :: how to open a folder in java swing project 
Java :: andriod button wont change color 
Java :: Java Public Access Modifier package two 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =