Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Jakarta WebSocket » Problem with @ClientEndpoint
Problem with @ClientEndpoint [message #1851036] Fri, 25 March 2022 10:32 Go to next message
Seto Mising name is currently offline Seto Mising nameFriend
Messages: 4
Registered: December 2009
Junior Member
Hi. I want to get the instance who called connectToServer in the client endpoint.

I can achieve it by the programmatic way.
public class BilibiliLiveClientEndpoint extends Endpoint {

public BilibiliLiveClientEndpoint(BilibiliLive bilibiliLive) {
    this.bilibiliLive = bilibiliLive;

session = ContainerProvider.getWebSocketContainer().connectToServer(new BilibiliLiveClientEndpoint(this), ClientEndpointConfig.Builder.create().build(), new URI(URL));


But I can't find a way to achieve it by the annotation way.
@ClientEndpoint
public class BilibiliLiveClientEndpointAnnotated {

@OnOpen
public void onOpen(Session session) {
    try {
        BilibiliLive bilibiliLive = BilibiliLiveJakarta.sessionBilibiliLiveJakartaMap.get(session);

session = ContainerProvider.getWebSocketContainer().connectToServer(BilibiliLiveClientEndpointAnnotated.class, new URI(URL));
sessionBilibiliLiveJakartaMap.put(session, this);

It seems that the only way to index the instance who called connectToServer is by session. But the session is not returned if the onOpen method is not completed. so the bilibiliLive instance is null.

Is there a way to achieve it by the annotation way? Thank you.
Re: Problem with @ClientEndpoint [message #1851083 is a reply to message #1851036] Sun, 27 March 2022 15:10 Go to previous message
Seto Mising name is currently offline Seto Mising nameFriend
Messages: 4
Registered: December 2009
Junior Member
For the programmatic way, I can also use the EndpointConfig.getUserProperties().put() to add custom properties to transfer the instance inside. But there's no way for the annotation way.

[Updated on: Sun, 27 March 2022 15:11]

Report message to a moderator

Goto Forum:
  


Current Time: Tue Sep 24 19:02:54 GMT 2024

Powered by FUDForum. Page generated in 0.04350 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top