@ -8,18 +8,18 @@ class UDPServerReuse {
public static void main ( String args [ ] ) throws Exception {
public static void main ( String args [ ] ) throws Exception {
int udpPort = 36037 ;
int udpPort = 36037 ;
@SuppressWarnings ( "resource" )
@SuppressWarnings ( "resource" )
DatagramSocket server Socket = new DatagramSocket ( null ) ;
DatagramSocket datagram Socket = new DatagramSocket ( null ) ;
/ / erlaubt das Wiederverwenden des Ports , mehrere Server - Prozesse können gleichen Port nutzen
/ / erlaubt das Wiederverwenden des Ports , mehrere Server - Prozesse können gleichen Port nutzen
server Socket. setReuseAddress ( true ) ;
server Socket. bind ( new InetSocketAddress ( udpPort ) ) ;
datagram Socket. setReuseAddress ( true ) ;
datagram Socket. bind ( new InetSocketAddress ( udpPort ) ) ;
byte [ ] receiveData = new byte [ 1024 ] ;
byte [ ] receiveData = new byte [ 1024 ] ;
byte [ ] sendData = new byte [ 1024 ] ;
byte [ ] sendData = new byte [ 1024 ] ;
System . out . println ( "UDP Server started. Waiting for incoming requests... (reuseAddress=" + server Socket. getReuseAddress ( ) + ", timeout=" + server Socket. getSoTimeout ( ) + ", buffersize=" + server Socket. getReceiveBufferSize ( ) + ")" ) ;
System . out . println ( "UDP Server started. Waiting for incoming requests... (reuseAddress=" + datagram Socket. getReuseAddress ( ) + ", timeout=" + datagram Socket. getSoTimeout ( ) + ", buffersize=" + datagram Socket. getReceiveBufferSize ( ) + ")" ) ;
while ( true ) {
while ( true ) {
DatagramPacket receivePacket = new DatagramPacket ( receiveData , receiveData . length ) ;
DatagramPacket receivePacket = new DatagramPacket ( receiveData , receiveData . length ) ;
server Socket. receive ( receivePacket ) ;
datagram Socket. receive ( receivePacket ) ;
String sentence = new String ( receivePacket . getData ( ) , 0 , receivePacket . getLength ( ) ) ;
String sentence = new String ( receivePacket . getData ( ) , 0 , receivePacket . getLength ( ) ) ;
InetAddress IPAddress = receivePacket . getAddress ( ) ;
InetAddress IPAddress = receivePacket . getAddress ( ) ;
@ -30,7 +30,7 @@ class UDPServerReuse {
String capitalizedSentence = sentence . toUpperCase ( ) ;
String capitalizedSentence = sentence . toUpperCase ( ) ;
sendData = capitalizedSentence . getBytes ( ) ;
sendData = capitalizedSentence . getBytes ( ) ;
DatagramPacket sendPacket = new DatagramPacket ( sendData , sendData . length , IPAddress , clientSrcPort ) ;
DatagramPacket sendPacket = new DatagramPacket ( sendData , sendData . length , IPAddress , clientSrcPort ) ;
server Socket. send ( sendPacket ) ;
datagram Socket. send ( sendPacket ) ;
}
}
}
}
}
}