java - Using a Session interface in another class -


I have a web application. I am using a websocket API to handle websockets, for that part here Code is

  package comm2.hello; Import java.io.IOException; Import java.util.ArrayList; Import javax.websocket.OnClose; Import javax.websocket.OnOpen; Import javax.websocket.Session; Import javax.websocket.server.ServerEndpoint; Import org.apache.catalina.session. *; @ServerEndpoint (value = "/ echo") public class wschat {Private Stable ArrayList & lt; Session & gt; SessionList = New Array's & lt; Session & gt; (); Open @On (session session) {session session. Try session (session); // asynchronous communication session .getBasicRemote (). SendText ("Hello"); } Grip (IOException E) {}} Public Zero (string text, session session) throws IOException {session.getBasicRemote (). SendText (text); }}  

If I'm trying another Java class then call the send method to send a message using the following code.

  Package Comics; Import java.io.IOException; Import java.util.ArrayList; Import javax.websocket.Session; Import javax.websocket.Session; Import comm2.hello *; Main section of the public square throws IOException ({String [] arguments) {// Todo auto generated method stub wschat HK = new wschat (); String text = "hello"; // session should not be null, but it is not sure whether it is session session = zero; H.send (text, session); }}  

As you can see, I have session variable main.java in the class null That would always cause a tap pointer error because I'm not sure what to do with the session , nobody knows that What is the session variable to get started in main.java ?


Comments