netty if i don't close the channel in exceptionCaught callback of ChannelInboundHandlerAdapter ,can cause problems?
I use open jdk 1.8 in ubuntu , i run my jar in ubuntu server and after a while i get a big number of close wait ,and in my log i have error of connection timed out , is this because i didn't close the channel on exceptionCaught of netty ??
the code i use:
bossGroup = new NioEventLoopGroup();
workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast("frameDecoder",
new DelimiterBasedFrameDecoder(Integer.MAX_VALUE, Delimiters.lineDelimiter()));
ch.pipeline().addLast(new GpsMessageHandler());
}
})
.option(ChannelOption.SO_BACKLOG, 128).option(ChannelOption.SO_REUSEADDR, true)
.childOption(ChannelOption.SO_KEEPALIVE, true).childOption(ChannelOption.TCP_NODELAY, true)
.option(ChannelOption.SO_SNDBUF, 1024*256)
.option(ChannelOption.SO_RCVBUF, 1024*256)
.childOption(ChannelOption.SO_SNDBUF, 1024*256)
.childOption(ChannelOption.SO_RCVBUF, 1024*256);
boolean bdConnectee = true;
if (bdConnectee) {
WebApp webAppDaemon = new WebApp();
webAppDaemon.start();// cmds de l'app web
logger.info("waiting...");
TimeOut.execute();
ChannelFuture f = b.bind(port).await();
f.channel().closeFuture().syncUninterruptibly();
}
}
catch (Exception e) {
logger.error(e);
}
finally {
workerGroup.shutdownGracefully();
bossGroup.shutdownGracefully();
}
do you know?
how many words do you know
See also questions close to this topic
-
Read each name in Array list to create seperate object for
I have a file that has student names, age, and an id number. I have a student class that holds the everything above for each student object. I stored all the names, id numbers. and age separately in an array list. Now im trying to assign the info to create a student object.
public class Student { private String lName; private int idNumber; private int age; public Student() { lName = ""; idNumber = 0; age = 0; } public Student(String l, int i, int a) { lName = l; idNumber = i; age = a; } public void setName(String last) { lName = last; } public String getName() { return lName; } public void setIdNum(int num) { idNumber = num; } public int getIdNum() { return idNumber; } public void setAge(int a) { age = a; } public int getAge() { return age; } }
My Text File looks something like this: This info is stored in parallel array lists. I don't quite get how to implement this into an object to pass it into my second contractor method.
Josh 2134 19 Smith 5256 21 Rogers 9248 19 Andrew 7742 20
Here's what I've tried;
public static void main(String[] args) { String file = "studentData.txt"; Scanner reader = new Scanner(file); ArrayList<String> lastNames = lNames(file); ArrayList<Integer> idNumbers = idNum(file); ArrayList<Integer> ageList = ages(file); Scanner input = new Scanner(System.in); Student s1 = new Student(); // confused about how to implement this constructor with the textile info for (int i = 0; i<idNumbers.size(); i++) { Student user = new Student(lastNames.get(i), idNumbers.get(i), ageList.get(i)); } //user enters idNumber to display age System.out.println("Enter ID Number"); //exception handling to be added int idNum = input.nextInt(); for (int i = 0; i<idNumbers.size(); i++) { if (idNum == idNumbers.get(i)) { s1.setAge(ageList.get(i)); System.out.println(s1.getAge()); } } }
-
Using EdittextPreference for Goto search
sorry for my poor English. I want to use EditTextPreference in my bottom nav like the pic below, ![screenshot][1]
I have recycleview xml in my project with in many sub cardview layouts(which is scrollable) and I want to create item in the bottom nav which is called "Goto". When the "Goto" item is clicked i want it to pop-up like the screenshot. And when user enters a number(according to the cardviews i.e if the number of cardview is 40 user must enter 1-40) I want to search the cardview by its ID. Thank you and I hope u got it, If u have any questions let me know [1]: https://i.stack.imgur.com/grK8P.jpg
My xml format look like this. As you see in the blow since the cardviews are huge in number it is not cool to scroll all the way down that is why i need Goto item in the bottom nav to search it by its ID when the user click number in the EditTextPreference as u see in the screenshot. i.e The screenshot is not from my app
<LinearLayout> <LinearLayout> <androidx.cardview.widget.CardView> <RealtiveLayout> <Textview/> <RealtiveLayout> </androidx.cardview.widget.CardView> </LinearLayout> <LinearLayout> <androidx.cardview.widget.CardView> <RealtiveLayout> <Textview/> <RealtiveLayout> </androidx.cardview.widget.CardView> </LinearLayout> <LinearLayout> <androidx.cardview.widget.CardView> <RealtiveLayout> <Textview/> <RealtiveLayout> </androidx.cardview.widget.CardView> </LinearLayout> <LinearLayout> <androidx.cardview.widget.CardView> <RealtiveLayout> <Textview/> <RealtiveLayout> </androidx.cardview.widget.CardView> </LinearLayout> .. .. .. .. many more..
-
How to get remaining time of the day in java?
I would like to calculate the time remaining for next day 00:00:00 from the current date time.
For e.g. time difference between 2
022-05-07T05:49:41.883807900Z
and2022-05-08T00:00:00Z
Expected answer:
18:10:19
or 65419 (in seconds).How can I achieve this with efficiently using java 8?
-
Socket.IO cannot establish a connection
I use socket.io-client for Javascript server on JAVA and when I enter address 'ws://10.201.223.67:9902/' the request is not by 'ws' but by 'http'.
Although I understand it should just come back 0
It keeps trying to connect.To connect using my own written hook
export function useSocketIO(url: string) { const ioRef = useRef<Socket>(); const [connected, setConnected] = useState(false); useEffect(() => { ioRef.current = io(url, { transportOptions: { polling: { extraHeaders: { Authorization: `Bearer ${APIAuth.accessToken}`, }, }, }, }); ioRef.current.on('connect', () => { console.log('WS Connected to', url); setConnected(() => true); }); ioRef.current.on('disconnect', () => { console.log('WS disconnected'); setConnected(() => false); }); return () => { console.log('WS destroyed'); ioRef.current?.close(); }; }, [url]); return { io: ioRef.current, connected, }; }
-
Steps involved in making a TCP connection
I am 18 and about to go to college for CS, I know nothing about socket programming in C.
I read the man pages on sockets, can you tell me if I got the steps right?
Server Steps:
create a socket with
socket()
create an address with a struct [presumably using some kind of
sockaddr
struct variant]bind the socket to the address with
bind()
listen for a connection with
listen()
accept the connection, and move the connection to another socket using
accept()
to free up the original "listening" socketuse
read()
andwrite()
to communicate over the new socket
Client Steps:
create a socket with
socket()
specify the address of the server we want to connect to [presumably using some
sockaddr
struct variant]connect the socket to the address using
connect()
use
read()
andwrite()
to communicate over the socket
-
Find the coordinates returned by the server after send commands GPS Tracker (TK303 etc)
I sent commands to the server according to the following links and data was returned that I do not know how to find the coordinates.
Link 1: GPS103 Tracker Listening Application in C#
Link 2: sending commands to tk103 gps tracker
Returned data:
imei:XXXXXXXXXXXXXXX,tracker,220506170600,,F,230600.00,A,3541.45559,N,05122.93316,E,,;
I also did not find the exact source for sending the commands to the server. Example I found: How to send commands via GPRS to GPS Tracker (TK103, GT02, GT06, TK102 etc)
-
Websocket with special characters
I am using websocket with client nodejs and server golang (net library) via tcp. I am read data sent from client but many special chars. Some one can help me about that?
Data received:
\u0016\u0003\u0001\u0002\u0000\u0001\u0000\u0001\ufffd\u0003\u0003x\ufffd_\ufffdj\ufffd\ufffd\ufffd\ufffdȬ{\ufffd \ufffdI\u003c9\u000bC1YŲ\ufffdVp\u0017\ufffd\u000e`\ufffd \ufffd\ufffd\ufffd\u0017\ufffd\ufffd=\\u0002\ufffd~,\u0011\ufffdn\ufffd\ufffdY\u0010\ufffd\u001c\ufffdw\u000f\ufffd\ufffd(hfK\ufffd\ufffd\u0000 \u001a\u001a\u0013\u0001\u0013\u0002\u0013\u0003\ufffd+\ufffd/\ufffd,\ufffd0̨̩\ufffd\u0013\ufffd\u0014\u0000\ufffd\u0000\ufffd\u0000/\u00005\u0001\u0000\u0001\ufffd\ufffd\ufffd\u0000\u0000\u0000\u0000\u0000\u0014\u0000\u0012\u0000\u0000\u000fvenus.localhost\u0000\u0017\u0000\u0000\ufffd\u0001\u0000\u0001\u0000\u0000"
This func use to accept tcp
func (s *WebsocketServer) Serve() { if s.running { return } s.running = true for _, lsn := range s.lsnList { for i := 0; i < s.accepts; i++ { go func(lsn2 *net.TCPListener) { var ( conn *net.TCPConn err error ) for { if conn, err = AcceptTCP(lsn2); err != nil { // if listener close then return log.Error("listener.Accept(\"%s\") error(%v)", lsn2.Addr().String(), err) return } if err = conn.SetKeepAlive(s.c.Keepalive); err != nil { log.Error("conn.SetKeepAlive() error(%v)", err) return } if err = conn.SetReadBuffer(s.c.ReceiveBuf); err != nil { log.Error("conn.SetReadBuffer() error(%v)", err) return } if err = conn.SetWriteBuffer(s.c.SendBuf); err != nil { log.Error("conn.SetWriteBuffer() error(%v)", err) return } go s.establishWebsocketConnection(conn) } }(lsn) } } } func (s *WebsocketServer) establishWebsocketConnection(conn net.Conn) { var ( // conn2 = NewBufferedConnSize(conn, 66560) req *websocket.Request websocketConn *websocket.Conn err error ) rr := bufio.NewReader(conn) if req, err = websocket.ReadRequest(rr); err != nil || req.RequestURI != "/apiws" { conn.Close() if err != io.EOF { log.Errorf("websocket.ReadRequest(rr) error(%v)", err) } return } else { wr := bufio.NewWriter(conn) websocketConn, err = websocket.Upgrade(conn, rr, wr, req) if err != nil { log.Errorf("websocket.Upgrade(rr) error(%v)", err) conn.Close() return } } codec, err := NewCodecByName(s.c.ProtoName, websocketConn) tcpConn := NewTcpConnection2(s.c.ServerName, websocketConn, s.c.SendChanSize, codec, true, s) // log.Info("establishTcpConnection...") defer func() { if err := recover(); err != nil { log.Error("tcp_server handle panic: %v\n%s", err, debug.Stack()) tcpConn.Close() } }() s.onNewConnection(tcpConn) for { tcpConn.conn.SetReadDeadline(time.Now().Add(time.Minute * 6)) msg, err := tcpConn.Receive() if err != nil { log.Error("conn: %s recv error: %v", tcpConn, err) return } if msg == nil { log.Error("recv a nil msg by conn: %s", tcpConn) continue } if s.callback != nil { // log.Info("onConnectionDataArrived - conn: %s", conn) if err := s.callback.OnConnectionDataArrived(tcpConn, msg); err != nil { } } } }
Function from websocket file, I print data here like above
func ReadRequest(r *bufio.Reader) (req *Request, err error) { var ( b []byte ok bool ) req = &Request{reader: r} if b, err = req.readLine(); err != nil { return } log.Errorf("websocket.ReadRequest: %s", string(b)) if req.Method, req.RequestURI, req.Proto, ok = parseRequestLine(string(b)); !ok { return nil, fmt.Errorf("malformed HTTP request %s", b) } if req.Header, err = req.readMIMEHeader(); err != nil { return } req.Host = req.Header.Get("Host") return req, nil } func (r *Request) readLine() ([]byte, error) { var line []byte for { l, more, err := r.reader.ReadLine() if err != nil { return nil, err } // Avoid the copy if the first call produced a full line. if line == nil && !more { return l, nil } line = append(line, l...) if !more { break } } return line, nil }
Please help me
-
Why so many Debug Logs with "setHandshakeSuccess" in vertx / quarkus?
we are evaluating quarkus and deployed one prototype with the log level DEBUG and just let it run for a few days. Our Logstash collapsed because of a
java.lang.ArithmeticException
and while investigating we saw so manysetHandshakeSuccess
logs from the new quarkus-web-service.
To be exact: 2600 logs every 5 minutes.No one even uses the web service. It should be running idle and not produce so many logs.
Can anyone tell us whether this is normal behavior?Example Log:
"message": "[id: 0x9869d583, L:/XX.XXX.XXX.XXX:8181 - R:/XX.XXX.X.XXX:49892] HANDSHAKEN: protocol:TLSv1.3 cipher suite:TLS_AES_256_GCM_SHA384" "SourceClassName": "io.netty.handler.ssl.SslHandler", "Thread": "vert.x-eventloop-thread-1",
The port number at the end of the second ip varies but there is no network traffic.
Does this message only mean that quarkus is checking ALL OF the available ports for traffic?quarkus.platform.version = 2.8.1.Final
-
why webFlux is too slow?
when in my project,my boss require us to use webflux as server, but we only run sync code,to my disappionted, any request will take 2~10 seconds to response, in jvisualvm, I find the reactor-tcp-epoll is too busy,the http-nio-7777-exec is ok, so ,I was confused, any one know the correct case ?
-
CorruptedFrameException while using websocket
we are using web socket and I guess it is successful because I can see the handshake messages and connection logs but I am getting below warning continuously, not sure what I am missing while establishing web socket connection
io.netty.channel.DefaultChannelPipeline - An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception. io.netty.handler.codec.CorruptedFrameException: data frame using reserved opcode 7 at io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder.protocolViolation(WebSocket08FrameDecoder.java:412)
I guess getting this warning at the time of flushing the message -
channelPipeline.addLast("flush", new FlushHandler(256, true));
How can I avoid this exception? or How can I handle this exception?