Data sent from server in "onopen" not received from client

Fermé
kawtar_kaoutar Messages postés 54 Date d'inscription jeudi 3 juillet 2014 Statut Membre Dernière intervention 29 juin 2015 - Modifié par kawtar_kaoutar le 23/06/2015 à 03:26
 Utilisateur anonyme - 23 juin 2015 à 06:34
Hi everyone
I'm using websockets for developping a chat application with jee, I'm using java in backend and javascript in frontend. and when opening the websocket and want to get the id session from the server and use it in my client page.

Here is the code i was tried:

Server side:


@ServerEndpoint("/echo")
public class LiveStream {

@OnOpen
public void onOpen(Session session) {
try {
session.getBasicRemote().sendText(session.getId());
} catch (IOException ex) {
}

session.setMaxBinaryMessageBufferSize(1024 * 512);

}

@OnMessage
public void processVideo(byte[] imageData, Session session) {
try {
ByteBuffer buf = ByteBuffer.wrap(imageData);
Set set;
set = session.getOpenSessions();
System.out.println(set.size() + " this is the number of opened sessions");
Iterator it = set.iterator();
while (it.hasNext()) {
Session s = (Session) it.next();
if(s!=session){
s.getBasicRemote().sendBinary(buf);
}
}

} catch (IOException ex) {
} catch (Throwable ioe) {
System.out.println("Error sending message " + ioe.getMessage());
}
}

@OnClose
public void whenClosing(Session session) {
System.out.println("Goodbye !");
sessions.remove(session);
}

}


Client side:


<script>

window.onload = function () {
ws = new WebSocket("ws://localhost:8080/application/echo");
ws.onopen = function (event) {
if (event.data === undefined) return;
id = event.data;
document.getElementById('texxt').value += id;
};

ws.onmessage = function (msg) {
url = window.URL.createObjectURL(msg.data);
};

}


The problem is that the id session is not received from the server and in client side, event.data===undefined. and I have to access to id_session of each user to use it later.

I need your help please ans thank you
A voir également:

1 réponse

Utilisateur anonyme
23 juin 2015 à 06:34
Hello this forum is french speak langage.
So you have two possibility: ask your question in french or going to the international version of the forum http://en.kioskea.net/forum/programming-3.

I close this subject.
0