0
멀티 캐스트를 오랫동안 보내려고합니다. 문자열을 보낼 수 있기 때문에 연결이 작동해야합니다.UDP 멀티 캐스트를 통해 오래 보내십시오.
이 내 서버 측 코드 :
currentServerStatusId = Server.getServerStatusVersionId();
buf = ByteBuffer.allocate(8).putLong(currentServerStatusId).array(); //long should be 8 bytes in Java
InetAddress group = InetAddress.getByName(multicastAddress);
DatagramPacket packet = new DatagramPacket(buf, buf.length, group, port);
socket.send(packet);
이것은 (수신기) 클라이언트 측에이 나에게 BufferUnderflowException을 제공
byte[] buf = new byte[256];
serverIpPacket = new DatagramPacket(buf, buf.length);
System.out.println("waiting to receive");
multicastSocket.receive(serverIpPacket);
receivedIp = serverIpPacket.getAddress().getHostAddress();
currentServerStatusId = ByteBuffer.allocate(8).put(serverIpPacket.getData()).getLong();
//new String(serverIpPacket.getData(), 0, serverIpPacket.getLength());
System.out.println("received current ServerStatusId: " + currentServerStatusId);
. 수신자/클라이언트 측의 할당 방법에서 크기를 8에서 16으로 두 배로 늘리면 분명히 작동합니다. 하지만 대신 내 시험 값의 0을 (68763 같은)
모든. – EJP