Я следовал этому уроку: https://javaee.github.io/grizzly/quickstart.html (он содержит 4 файла: ClientFilter, EchoClient, EchoFilter, EchoServer)
Цель этого туто - во-первых, чтобы сервер отобразил имя своего класса.Этот шаг прошел хорошо. Вторым шагом является отображение ввода с помощью EchoClient.java. Этот шаг отправляет ошибку, которую я не знаю, как исправить.Сервер не работал.
вот файл:
package grizzly.tuto;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.logging.Logger;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.glassfish.grizzly.Connection;
import org.glassfish.grizzly.Grizzly;
import org.glassfish.grizzly.filterchain.FilterChainBuilder;
import org.glassfish.grizzly.filterchain.TransportFilter;
import org.glassfish.grizzly.nio.transport.TCPNIOTransport;
import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder;
import org.glassfish.grizzly.utils.StringFilter;
/**
* The simple client, which sends a message to the echo server
* and waits for response
*/
public class EchoClient {
private static final Logger logger = Grizzly.logger(EchoClient.class);
public static void main(String[] args) throws IOException,
ExecutionException, InterruptedException, TimeoutException {
Connection connection = null;
// Create a FilterChain using FilterChainBuilder
FilterChainBuilder filterChainBuilder = FilterChainBuilder.stateless();
// Add TransportFilter, which is responsible
// for reading and writing data to the connection
filterChainBuilder.add(new TransportFilter());
// StringFilter is responsible for Buffer <-> String conversion
filterChainBuilder.add(new StringFilter(Charset.forName("UTF-8")));
// ClientFilter is responsible for redirecting server responses to the standard output
filterChainBuilder.add(new ClientFilter());
// Create TCP transport
final TCPNIOTransport transport =
TCPNIOTransportBuilder.newInstance().build();
transport.setProcessor(filterChainBuilder.build());
try {
// start the transport
transport.start();
// perform async. connect to the server
Future<Connection> future = transport.connect(EchoServer.HOST,
EchoServer.PORT);
// wait for connect operation to complete
connection = future.get(10, TimeUnit.SECONDS);
assert connection != null;
System.out.println("Ready... (\"q\" to exit)");
final BufferedReader inReader = new BufferedReader(new InputStreamReader(System.in));
do {
final String userInput = inReader.readLine();
if (userInput == null || "q".equals(userInput)) {
break;
}
connection.write(userInput);
} while (true);
} finally {
// close the client connection
if (connection != null) {
connection.close();
}
// stop the transport
transport.shutdownNow();
}
}
}
вот журнал:
Исключение впоток "основной" java.util.concurrent.ExecutionException: java.net.ConnectException: соединение отклонено в org.glassfish.grizzly.impl.SafeFutureImpl $ Sync.innerGet (SafeFutureImpl.java:363) в org.glassfish.grizzly.impl.SafeFutureImpl.get (SafeFutureImpl.java:264) at grizzly.tuto.EchoClient.main (EchoClient.java:54) Причина: java.net.ConnectException: Соединение отклонено в java.base / sun.nio.ch.SocketChannelImpl.checkConnect(Собственный метод) по адресу java.base / sun.nio.ch.SocketChannelImpl.finishConnect (SocketChannelImpl.java:779) по адресу org.glassfish.grizzly.nio.transport.TCPNIOConnectorHandler.onConnectedAsync (TCPNIOConnector.g2) at2jjjj..grizzly.nio.transport.TCPNIOConnectorHandler $ 1.connected (TCPNIOConnectorHandler.java:158) в org.glassfish.grizzly.nio.transport.TCPNIOConnection.onConnect (TCPNIOConnection.java:258) в org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent (TCPNIOTransport.java:530) в org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent (AbstractIOStrategy.java:112) в org.glassfish.grizzly.strategies.WavaerrateII: 117) в org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.executeIoEvent (WorkerThreadIOStrategy.java:103) в org.glassfish.grizzly.strategies.AbstractIOStrategy.executeIoEvent (AbstractIOStrategy.j.g.gio.89)SelectorRunner.iterateKeyEvents (SelectorRunner.java:415) по адресу org.glassfish.grizzly.nio.SelectorRunner.iterateKeys (SelectorRunner.java:384) по адресу org.glassfish.grizzly.nio.SelectorRunner.doSelect (SelectorRunner) или SelectorRunner..glassfish.grizzly.nio.SelectorRunner.run (SelectorRunner.java:279) в org.glassfish.grizzly.threadpool.AbstractThreadPool $ Worker.doWork (AbstractThreadPool.java:593) в org.glassfish.grizzly.threadpool.Abstract.run (AbstractThreadPool.java:573) в java.base / java.lang.Thread.run (Thread.java:834) `
EchoClient.java: 54 соответствует этому файлу Java - строка: connection = future.get(10, TimeUnit.SECONDS);
Информация для вас: Eclipse предупреждает, что
Соединение является необработанным типом.Ссылки на универсальный тип Connection должны быть параметризованы`
Я использую: - grizzly-framework-2.4.3.jar - JDK-11
Если у вас есть идеи, чтобы помочь или где искать, я буду признателен.спасибо