GithubHelp home page GithubHelp logo

websocket-test's People

Contributors

cemartins avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

websocket-test's Issues

What about path parameters and query parameters ?

Hi Carlos !

Thanks for this POC.

I use something like this :

url = 'ws://' + window.location.host + '/ws/mypathparam/?aQueryParam=123&anotherQueryParam=abc'
ws = new WebSocket(url); 
@ServerEndpoint(value = "/ws/{aParam}")
public class myPublicClass {
[...]
@OnOpen
public void onOpen(@PathParam("aParam") String aParam, Session session, EndpointConfig config) {
Map<String, String> queryParams = getQueryMap(session.getQueryString());
        if (queryParams.containsKey("aQueryParam")) {
            theQueryParam= queryParams.get("aQueryParam");
            System.out.println(theQueryParam);
        }
[...]
 public static Map<String, String> getQueryMap(String query) {
        Map<String, String> map = Maps.newHashMap();
        if (query != null) {
            String[] params = query.split("&");
            for (String param : params) {
                String[] nameval = param.split("=");
                map.put(nameval[0], nameval[1]);
            }
        }
        return map;
    }

I was wondering how could we go with 'path parameters' and 'query Parameters' in your solution ?

help help help!!

can i only use your SpringConfigurator.java without MyApplication.java ( do not inittail by the servlet but the spring)

like this ? it seems that it doesnot workπŸ˜„

@serverendpoint(value="/ws/createfile/",configurator=SpringConfigurator.class)

Cannot store session instance in list.

I tried to store session in MyEndpoint or another helper class when connection is established in several ways.

1.     private static final Set<Session> sessions = Collections
            .synchronizedSet(new HashSet<Session>());
2. public static final List<Session> users = new ArrayList<Session>();
3. public static final Map<String,Session> clients = new ConcurrentHashMap<String,Session>();
@Override
    public void onOpen(Session session, EndpointConfig config) {
        System.out.println("websocket connection opened: " + session.getId());
        session.getAsyncRemote().sendText("connected!!");
        WSSessionUtils.put(session.getId(), session);
        WSSessionUtils.add(session);
        sessions.add(session);

        // MyPongHandler pongHandler = new MyPongHandler(session);
        // session.addMessageHandler(new MyMessageHandler(session,
        // pongHandler));
        // session.addMessageHandler(pongHandler);
    }

Then broadcast message to sessions like below.

public static void broadcast() {
        synchronized (sessions) {
            for (Session s : sessions) {
                if (s.isOpen()) {
                    try {
                        // send the article summary to all the connected clients
                        s.getBasicRemote().sendText("yo ");
                    } catch (IOException ex) {
                    }
                }
            }
        }
    }

But every time the collection of session will be empty. Can you help to have a look?

Trying to apply the PoC in a real application

Hi, I'm trying to apply the PoC you did in a real app.
My app is already configured with Spring 3.2, it had a web.xml with a servlet for the root (path /), and is configured to read @configuration too.

So, when I load the classes created in your PoC in my app, it's failing in the MyApplication trying to get the attribute "javax.websocket.server.ServerContainer" from the container.

Can you explain me how this is suppose to be populated?

I've check your project and I can't find any configuration for that.

Any help will be very much appreciated.
Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.