Reputation: 1
Good evening, I know almost nothing about programming, but when compiling an application "that apparently was ready" I come across this error:
Error Log
[16/05/2024 06:54:06] Exception in thread "Network Thread" [16/05/2024 06:54:06] java.lang.NoSuchMethodError: java.nio.ByteBuffer.flip()Ljava/nio/ByteBuffer;
[16/05/2024 06:54:06] at br.com.mundoerinia.engine.nio.MessageQueue.receiveFromSocket(MessageQueue.java:144)
[16/05/2024 06:54:06] at br.com.mundoerinia.engine.nio.MessageQueue.process(MessageQueue.java:130)
[16/05/2024 06:54:06] at br.com.mundoerinia.engine.nio.NetworkThread.run(NetworkThread.java:111)
file code
package engine.nio;
import java.io.IOException;
import java.net.Socket;
import java.net.SocketAddress;
import java.nio.BufferOverflowException;
import java.nio.ByteBuffer;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.SocketChannel;
import java.util.ArrayList;
import infra.util.Log;
import engine.networkserver.NetWorkUtils;
import engine.utils.IgnisTimer;
public class MessageQueue implements NetworkInterface {
private static int SEND_BUFFER_SIZE = 20000;
public static int CONNECTION_TIMEOUT = 3000;
private static int KEEP_ALIVE_TIMEOUT = 3000;
private SocketChannel socketChannel;
private NetWorkBufferEncoder bufferEncoder;
private NetWorkBufferDecoder bufferDecoder;
private ByteBuffer receiveBuffer = ByteBuffer.allocate(NetWorkUtils.getMaxPacketSize());
private ByteBuffer sendBuffer = ByteBuffer.allocate(SEND_BUFFER_SIZE);
private ArrayList<byte[]> sendList = new ArrayList<byte[]>();
private long lLastPacketTime = Long.MAX_VALUE;
private long lLastKeepAliveTime = IgnisTimer.currentTimeMillis();
private long lConnectionTime = IgnisTimer.currentTimeMillis();
private int iTotalBytesSent = 0;
private int iTotalBytesReceived = 0;
private long lLastFrameTime = 0;
private boolean bIsConnected = true;
private boolean bSendKeepAlive = false;
/** construtor */
public MessageQueue(SocketChannel channel) throws IOException {
socketChannel = channel;
Socket socket = channel.socket();
socket.setTcpNoDelay(true);
socket.setKeepAlive(true);
bufferEncoder = new NetWorkBufferEncoder(this);
bufferDecoder = new NetWorkBufferDecoder(this);
}
public void process() {
if (bIsConnected) {
receiveFromSocket();
sendToSocket();
} else {
disconnect();
}
lLastFrameTime = IgnisTimer.currentTimeMillis();
}
private void sendToSocket() {
try {
synchronized (sendBuffer) {
int iBytesToSend = sendBuffer.position();
if (iBytesToSend > 0) {
lLastKeepAliveTime = IgnisTimer.currentTimeMillis();
sendBuffer.flip();
socketChannel.socket().setSendBufferSize(iBytesToSend);
int iBytesSent = socketChannel.write(sendBuffer);
sendBuffer.compact();
if (iBytesSent > 0) {
lLastPacketTime = IgnisTimer.currentTimeMillis();
iTotalBytesSent += iBytesSent;
} else
checkConnectionTimeout();
} else
if (!addSendList())
checkKeepAliveTimeout();
}
} catch (ClosedChannelException cce) {
bIsConnected = false;
} catch (IOException ioe) {
bIsConnected = false;
} catch (Exception e) {
bIsConnected = false;
}
}
private void receiveFromSocket() {
try {
int iBytesRead = socketChannel.read(receiveBuffer);
if (iBytesRead > 0) {
receiveBuffer.flip();
byte[] newData = new byte[iBytesRead];
receiveBuffer.get(newData, 0, iBytesRead);
bufferDecoder.gotNewDataFromSocket(newData);
receiveBuffer.clear();
iTotalBytesReceived += iBytesRead;
}
} catch (ClosedChannelException cce) {
bIsConnected = false;
Log.error(cce, "Conexão terminando por ClosedChannelException !!!");
} catch (IOException ioe) {
bIsConnected = false;
Log.error(ioe, "Conexão terminando por IOException");
} catch (Exception e) {
bIsConnected = false;
Log.error(e, "Conexão terminando por Exception");
}
}
public void addEncodedMessage(byte[] b) {
synchronized (sendBuffer) {
ensureBufferCapacity(b.length);
try {
while (!sendList.isEmpty()) {
sendBuffer.put((byte[]) sendList.get(0));
sendList.remove(0);
}
sendBuffer.put(b, 0, b.length);
} catch (BufferOverflowException e) {
sendList.add(b);
} catch (Exception e) {
}
}
}
private void checkConnectionTimeout() {
if (IgnisTimer.currentTimeMillis() > lLastPacketTime + CONNECTION_TIMEOUT) {
disconnect();
}
}
private void checkKeepAliveTimeout() {
if (bSendKeepAlive)
if (IgnisTimer.currentTimeMillis() > lLastKeepAliveTime + KEEP_ALIVE_TIMEOUT)
bufferEncoder.encodeAndSend(NetWorkBufferDecoder.KEEP_ALIVE_PCKT, null);
}
public void disconnect() {
try {
socketChannel.close();
} catch (IOException ioe) {
}
NetworkThread.instance.endConnection(this);
bIsConnected = false;
}
public void ensureBufferCapacity(int size) {
if (size > sendBuffer.capacity()) {
try {
byte[] bufferBytes = sendBuffer.array();
ByteBuffer newBuffer = ByteBuffer.allocate(size);
newBuffer.put(bufferBytes, 0, sendBuffer.position());
sendBuffer = newBuffer;
} catch (BufferOverflowException e) {
}
}
}
private boolean addSendList() {
boolean added = false;
try {
while (!sendList.isEmpty()) {
sendBuffer.put((byte[]) sendList.get(0));
sendList.remove(0);
added = true;
}
} catch (BufferOverflowException e) {
}
return added;
}
public void enableKeepAlive() {
bSendKeepAlive = true;
}
public boolean sendMessage(byte[] b) {
bufferEncoder.encodeAndSend(b);
return true;
}
public byte[] popMessage() {
return bufferDecoder.popMessage();
}
public String getClientAddress() {
SocketAddress sa = socketChannel.socket().getRemoteSocketAddress();
if (sa != null)
return sa.toString();
return "MessageQueue -> not connected !!!";
}
public SocketAddress getRemoteSocketAddress() {
return socketChannel.socket().getRemoteSocketAddress();
}
public int getConnectionTimeSecs() {
return (int) ((IgnisTimer.currentTimeMillis() - lConnectionTime) / 1000);
}
public long getConnectionTimeMillis() {
return IgnisTimer.currentTimeMillis() - lConnectionTime;
}
public long getConnectionStartTime() {
return lConnectionTime;
}
public int getTotalBytesSent() {
return iTotalBytesSent;
}
public int getTotalBytesReceived() {
return iTotalBytesReceived;
}
public NetWorkBufferEncoder getEncoder() {
return bufferEncoder;
}
public boolean isConnected() {
return bIsConnected;
}
public void setLastFrameTime(long time) {
lLastFrameTime = time;
}
public long lastFrameTime() {
return (lLastFrameTime);
}
}
If anyone can help me with this, I would be immensely grateful! Thank you very much for the time guys! and excuse my English, I use Google Translate! =x
OBS.: My Topic was closed because there is an open topic explaining how to solve it, but I don't know how to solve it, if anyone can tell me how to do it, literally thank you!
Upvotes: 0
Views: 21