Java Reference
In-Depth Information
@OnClose
public void closeConnection(Session session)
throws Exception {
//...
}
}
The
@ServerEndpoint
annotation defines a server type endpoint and the path
where it will be deployed. You will also notice that the API offers annotations to de-
scribethemethodtobeexecutedineachstepoftheendpointlifecycle. Thefollowing
table gives the list and the role of WebSocket endpoint lifecycle annotations.
The following table lists the WebSocket endpoint lifecycle annotations:
Annotation
Role
Designates the method to be executed at the opening of a connec-
tion
@OnOpen
@OnMessage
Designates the method to be executed when a message is received
@OnError
Designates the method to be executed in case of a connection error
@OnClose
Designates the method to be executed when the connection is
closed
Any message sent by a WebSocket client is intercepted by the
onMessage()
meth-
od, which takes the client session and the message as parameters (for other para-