Tabnine Logo
Session
Code IndexAdd Tabnine to your IDE (free)

How to use
Session
in
sockslib.server

Best Java code snippets using sockslib.server.Session (Showing top 20 results out of 315)

origin: theotherp/nzbhydra2

/**
 * Closes all sessions.
 */
protected void closeAllSession() {
  for (long key : sessions.keySet()) {
    sessions.get(key).close();
  }
}
origin: theotherp/nzbhydra2

@Override
public void onCreate(Session session) throws CloseSessionException {
  logger.info("Create SESSION[{}] for {}", session.getId(), session.getClientAddress());
}
origin: theotherp/nzbhydra2

/**
 * This method will save user in session.
 *
 * @param session Current session.
 * @param user    user.
 */
protected void authenticationSuccess(Session session, User user) {
  session.setAttribute(USER_KEY, user);
}
origin: theotherp/nzbhydra2

@Override
public void doBind(Session session, CommandMessage commandMessage) throws SocksException,
    IOException {
  ServerSocket serverSocket = new ServerSocket(commandMessage.getPort());
  int bindPort = serverSocket.getLocalPort();
  Socket socket = null;
  logger.info("Create TCP server bind at {} for session[{}]", serverSocket
      .getLocalSocketAddress(), session.getId());
  session.write(new CommandResponseMessage(VERSION, ServerReply.SUCCEEDED, serverSocket
      .getInetAddress(), bindPort));
  socket = serverSocket.accept();
  session.write(new CommandResponseMessage(VERSION, ServerReply.SUCCEEDED, socket
      .getLocalAddress(), socket.getLocalPort()));
  Pipe pipe = new SocketPipe(session.getSocket(), socket);
  pipe.setBufferSize(bufferSize);
  pipe.start();
  // wait for pipe exit.
  while (pipe.isRunning()) {
    try {
      Thread.sleep(idleTime);
    } catch (InterruptedException e) {
      pipe.stop();
      session.close();
      logger.info("Session[{}] closed", session.getId());
    }
  }
  serverSocket.close();
  // throw new NotImplementException("Not implement BIND command");
}
origin: theotherp/nzbhydra2

@Override
public void doUDPAssociate(Session session, CommandMessage commandMessage) throws
    SocksException, IOException {
  UDPRelayServer udpRelayServer =
      new UDPRelayServer(((InetSocketAddress) session.getClientAddress()).getAddress(),
          commandMessage.getPort());
  InetSocketAddress socketAddress = (InetSocketAddress) udpRelayServer.start();
  logger.info("Create UDP relay server at[{}] for {}", socketAddress, commandMessage
      .getSocketAddress());
  session.write(new CommandResponseMessage(VERSION, ServerReply.SUCCEEDED, InetAddress
      .getLocalHost(), socketAddress.getPort()));
  while (udpRelayServer.isRunning()) {
    try {
      Thread.sleep(idleTime);
    } catch (InterruptedException e) {
      session.close();
      logger.info("Session[{}] closed", session.getId());
    }
    if (session.isClose()) {
      udpRelayServer.stop();
      logger.debug("UDP relay server for session[{}] is closed", session.getId());
    }
  }
}
origin: theotherp/nzbhydra2

@Override
public void doMethod(Session session) throws SocksException, IOException {
  checkNotNull(session, "Argument [session] may not be null");
  checkNotNull(authenticator, "Please set an authenticator");
  UsernamePasswordMessage usernamePasswordMessage = new UsernamePasswordMessage();
  session.read(usernamePasswordMessage);
  logger.debug("SESSION[{}] Receive credentials: {}", session.getId(), usernamePasswordMessage
      .getUsernamePasswordCredentials());
  try {
    authenticator.doAuthenticate(usernamePasswordMessage.getUsernamePasswordCredentials(),
        session);
  } catch (AuthenticationException e) {
    session.write(new UsernamePasswordResponseMessage(false));
    throw e;
  }
  session.write(new UsernamePasswordResponseMessage(true));
}
origin: fengyouchao/sockslib

@Override
public void onClose(Session session) {
 logger.info("SESSION[{}] closed", session.getId());
}
origin: fengyouchao/sockslib

/**
 * This method will throw a {@link AuthenticationException}
 *
 * @param session Current session
 * @throws AuthenticationException {@link AuthenticationException}
 */
protected void authenticationFailed(Session session) throws AuthenticationException {
 throw new AuthenticationException(
   "Authentication failed, client from " + session.getClientAddress());
}
origin: fengyouchao/sockslib

@Override
public void doBind(Session session, CommandMessage commandMessage) throws SocksException,
  IOException {
 ServerSocket serverSocket = new ServerSocket(commandMessage.getPort());
 int bindPort = serverSocket.getLocalPort();
 Socket socket = null;
 logger.info("Create TCP server bind at {} for session[{}]", serverSocket
   .getLocalSocketAddress(), session.getId());
 session.write(new CommandResponseMessage(VERSION, ServerReply.SUCCEEDED, serverSocket
   .getInetAddress(), bindPort));
 socket = serverSocket.accept();
 session.write(new CommandResponseMessage(VERSION, ServerReply.SUCCEEDED, socket
   .getLocalAddress(), socket.getLocalPort()));
 Pipe pipe = new SocketPipe(session.getSocket(), socket);
 pipe.setBufferSize(bufferSize);
 pipe.start();
 // wait for pipe exit.
 while (pipe.isRunning()) {
  try {
   Thread.sleep(idleTime);
  } catch (InterruptedException e) {
   pipe.stop();
   session.close();
   logger.info("Session[{}] closed", session.getId());
  }
 }
 serverSocket.close();
 // throw new NotImplementException("Not implement BIND command");
}
origin: fengyouchao/sockslib

@Override
public void doUDPAssociate(Session session, CommandMessage commandMessage) throws
  SocksException, IOException {
 UDPRelayServer udpRelayServer =
   new UDPRelayServer(((InetSocketAddress) session.getClientAddress()).getAddress(),
     commandMessage.getPort());
 InetSocketAddress socketAddress = (InetSocketAddress) udpRelayServer.start();
 logger.info("Create UDP relay server at[{}] for {}", socketAddress, commandMessage
   .getSocketAddress());
 session.write(new CommandResponseMessage(VERSION, ServerReply.SUCCEEDED, InetAddress
   .getLocalHost(), socketAddress.getPort()));
 while (udpRelayServer.isRunning()) {
  try {
   Thread.sleep(idleTime);
  } catch (InterruptedException e) {
   session.close();
   logger.info("Session[{}] closed", session.getId());
  }
  if (session.isClose()) {
   udpRelayServer.stop();
   logger.debug("UDP relay server for session[{}] is closed", session.getId());
  }
 }
}
origin: fengyouchao/sockslib

@Override
public void doMethod(Session session) throws SocksException, IOException {
 checkNotNull(session, "Argument [session] may not be null");
 checkNotNull(authenticator, "Please set an authenticator");
 UsernamePasswordMessage usernamePasswordMessage = new UsernamePasswordMessage();
 session.read(usernamePasswordMessage);
 logger.debug("SESSION[{}] Receive credentials: {}", session.getId(), usernamePasswordMessage
   .getUsernamePasswordCredentials());
 try {
  authenticator.doAuthenticate(usernamePasswordMessage.getUsernamePasswordCredentials(),
    session);
 } catch (AuthenticationException e) {
  session.write(new UsernamePasswordResponseMessage(false));
  throw e;
 }
 session.write(new UsernamePasswordResponseMessage(true));
}
origin: theotherp/nzbhydra2

@Override
public void onClose(Session session) {
  logger.info("SESSION[{}] closed", session.getId());
}
origin: theotherp/nzbhydra2

/**
 * This method will throw a {@link AuthenticationException}
 *
 * @param session Current session
 * @throws AuthenticationException {@link AuthenticationException}
 */
protected void authenticationFailed(Session session) throws AuthenticationException {
  throw new AuthenticationException(
      "Authentication failed, client from " + session.getClientAddress());
}
origin: theotherp/nzbhydra2

    reply = ServerReply.GENERAL_SOCKS_SERVER_FAILURE;
  logger.info("SESSION[{}] connect {} [{}] exception:{}", session.getId(), new
      InetSocketAddress(remoteServerAddress, remoteServerPort), reply, e.getMessage());
session.write(responseMessage);
if (reply != ServerReply.SUCCEEDED) { // 如果返回失败信息,则退出该方法。
  session.close();
  return;
Pipe pipe = new SocketPipe(session.getSocket(), socket);
pipe.setName("SESSION[" + session.getId() + "]");
pipe.setBufferSize(bufferSize);
if (getSocksProxyServer().getPipeInitializer() != null) {
  } catch (InterruptedException e) {
    pipe.stop();
    session.close();
    logger.info("SESSION[{}] closed", session.getId());
origin: fengyouchao/sockslib

session.read(msg);
logger.debug("SESSION[{}] Response client:{}", session.getId(), selectedMethod.getMethodName());
session.write(new MethodSelectionResponseMessage(VERSION, selectedMethod));
session.read(commandMessage); // Read command request.
 session.write(new CommandResponseMessage(serverReply));
 logger.info("SESSION[{}] will close, because {}", session.getId(), serverReply);
 return;
origin: theotherp/nzbhydra2

  @Override
  public void onException(Session session, Exception exception) {
    logger.error("SESSION[{}] occurred error:{}, message:{}", session.getId(), exception.getClass
        ().getSimpleName(), exception.getMessage());
    exception.printStackTrace();
  }
}
origin: fengyouchao/sockslib

@Override
public void onCreate(Session session) throws CloseSessionException {
 logger.info("Create SESSION[{}] for {}", session.getId(), session.getClientAddress());
}
origin: fengyouchao/sockslib

/**
 * Closes all sessions.
 */
protected void closeAllSession() {
 for (long key : sessions.keySet()) {
  sessions.get(key).close();
 }
}
origin: fengyouchao/sockslib

/**
 * This method will save user in session.
 *
 * @param session Current session.
 * @param user    user.
 */
protected void authenticationSuccess(Session session, User user) {
 session.setAttribute(USER_KEY, user);
}
origin: fengyouchao/sockslib

  reply = ServerReply.GENERAL_SOCKS_SERVER_FAILURE;
 logger.info("SESSION[{}] connect {} [{}] exception:{}", session.getId(), new
   InetSocketAddress(remoteServerAddress, remoteServerPort), reply, e.getMessage());
session.write(responseMessage);
if (reply != ServerReply.SUCCEEDED) { // 如果返回失败信息,则退出该方法。
 session.close();
 return;
Pipe pipe = new SocketPipe(session.getSocket(), socket);
pipe.setName("SESSION[" + session.getId() + "]");
pipe.setBufferSize(bufferSize);
if(getSocksProxyServer().getPipeInitializer() != null){
 } catch (InterruptedException e) {
  pipe.stop();
  session.close();
  logger.info("SESSION[{}] closed", session.getId());
sockslib.serverSession

Javadoc

The class Session represents a session between client with SOCKS server. This class is simple encapsulation of java.net.Socket.

Most used methods

  • close
    Closes connection and removes itself from managed sessions.
  • getClientAddress
    Get remote host's IP address and port.
  • getId
    Gets session ID.
  • getSocket
    Returns socket.
  • isClose
    Returns true if the session is closed.
  • read
    Read a buffer.
  • setAttribute
  • write
    Writes bytes in output stream.

Popular in Java

  • Running tasks concurrently on multiple threads
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • scheduleAtFixedRate (ScheduledExecutorService)
  • getResourceAsStream (ClassLoader)
  • Thread (java.lang)
    A thread is a thread of execution in a program. The Java Virtual Machine allows an application to ha
  • HttpURLConnection (java.net)
    An URLConnection for HTTP (RFC 2616 [http://tools.ietf.org/html/rfc2616]) used to send and receive d
  • ByteBuffer (java.nio)
    A buffer for bytes. A byte buffer can be created in either one of the following ways: * #allocate
  • Selector (java.nio.channels)
    A controller for the selection of SelectableChannel objects. Selectable channels can be registered w
  • ConcurrentHashMap (java.util.concurrent)
    A plug-in replacement for JDK1.5 java.util.concurrent.ConcurrentHashMap. This version is based on or
  • Loader (org.hibernate.loader)
    Abstract superclass of object loading (and querying) strategies. This class implements useful common
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now