Using subprotocols (its more websockety) in example instead

This commit is contained in:
Joakim Erdfelt 2013-05-08 12:31:48 -07:00
parent 3fa029ed88
commit c114e925ef
1 changed files with 14 additions and 4 deletions

View File

@ -37,11 +37,21 @@ public class MyAdvancedEchoCreator implements WebSocketCreator
@Override
public Object createWebSocket(UpgradeRequest req, UpgradeResponse resp)
{
String[] type = req.getParameterMap().get("type");
if ((type != null) && (type.length >= 1) && ("binary".equals(type[0])))
for (String subprotocol : req.getSubProtocols())
{
return binaryEcho;
if ("binary".equals(subprotocol))
{
resp.setAcceptedSubProtocol(subprotocol);
return binaryEcho;
}
if ("text".equals(subprotocol))
{
resp.setAcceptedSubProtocol(subprotocol);
return textEcho;
}
}
return textEcho;
// No valid subprotocol in request, ignore the request
return null;
}
}