java - Only getting the same udp packets -


I am a newbie in Java and I just have 2 programs that use UDP packets (Client and Server). The client gets the integer from the user and sends that number to the server. The server then reduces the integer to 2 and sends it back to the client. Until the client receives a non-positive number from the server, the messages will need to move further. The problem is that I get the same number. Does anyone know how to solve this? Do I need many loops? import java.io.IOException; Import java.net.DatagramPacket; Import java.net.DataagramSocket; Import java.net.InetAddress; Import java.nio.biteBuffer; Import java.util.Scanner; Public class client {public static zero main (string [] args throws IOException {DatagramSocket DS = new datagram (socket); System.out.println ("insert number:"); Scanner = new scanner (System.in); Int num = s.nextInt (); Int port = 1 999; Byte [] byteSend = Byte Buffer.Olock (4) .putir (num). Array (); InetAddress address = InetAddress.getByName ("localhost"); Byte [] byte resizing = new byte [4]; Datagram Packet DPRECE = New Datagram Packet (Byte Recept, Byte Resave Lamp); DatagateteDepend = new datagram packet (byte send, byte sand.line, address, port); If (num & lt; = 0) {ds.close (); } Else {for (int i = 0; i

server class

  import java.net.DatagramPacket; Import java.net.DataagramSocket; Import java.net.InetAddress; Import java.nio.biteBuffer; Public class server {public static zero main (string [] args throws exceptions {DatagramSocket dg = new DatagramSocket (1999); While {true} {System.out.println ("listening"); Byte [] byte resizing = new byte [4]; Datagate DP = new datagram packet (byte rescue, byte receave lamp); dg.receive (DP); Int num = ByteBuffer.wrap (dp.getData ()). GetInt (); InetAddress address = dp.getAddress (); Int port = dp.getPort (); Int numResult = num - 2; Byte [] byte send = bytefuffer.alocet (4) .IPIINt (node ​​result). Array (); DatagateteDepend = new datagram packet (byte send, byte sand.line, address, port); System.out.println ("Received Number:" + num); System.out.println ("Number now reduced:" + numResult); dg.send (dpSend); }}}   

The client output comes when 6 is entered:

Insert number:

6 numbers received: 4

Received Number: 4

Received Number: 4

The output of the server comes as follows:

Hearing = "Text">

Customer keeps sending the same number. You never update dpSend

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -