WebSocketSocket/server/src/main/java/com/moparisthebest/websocket/server/WebSocketSocketApplication....

55 lines
2.1 KiB
Java

/*
* WebSocketSocket implements a custom java.net.Socket over top of a
* WebSocket, and also a server component that accepts a WebSocket
* connection and connects to a host/port.
* Copyright (C) 2016 Travis Burtrum (moparisthebest)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package com.moparisthebest.websocket.server;
import java.io.IOException;
import java.util.logging.Logger;
import org.glassfish.grizzly.Grizzly;
import org.glassfish.grizzly.http.HttpRequestPacket;
import org.glassfish.grizzly.websockets.ProtocolHandler;
import org.glassfish.grizzly.websockets.WebSocket;
import org.glassfish.grizzly.websockets.WebSocketApplication;
import org.glassfish.grizzly.websockets.WebSocketListener;
public class WebSocketSocketApplication extends WebSocketApplication {
private static final Logger logger = Grizzly.logger(WebSocketSocketApplication.class);
/**
* Creates a customized {@link WebSocket} implementation.
*
* @return customized {@link WebSocket} implementation - {@link SocketWebSocket}
*/
@Override
public WebSocket createSocket(ProtocolHandler handler,
HttpRequestPacket request,
WebSocketListener... listeners) {
try {
return new SocketWebSocket(handler, request, listeners);
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
}