当前位置: 首页>>代码示例>>Java>>正文


Java Connection类代码示例

本文整理汇总了Java中org.androidpn.server.xmpp.net.Connection的典型用法代码示例。如果您正苦于以下问题:Java Connection类的具体用法?Java Connection怎么用?Java Connection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Connection类属于org.androidpn.server.xmpp.net包,在下文中一共展示了Connection类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createClientSession

import org.androidpn.server.xmpp.net.Connection; //导入依赖的package包/类
/**
 * 根据连接创建一个新的客户端会话并返回
 * 
 * @param conn
 * @return
 */
public ClientSession createClientSession(Connection conn) {
	if (serverName == null) {
		throw new IllegalStateException("服务未初始化");
	}

	Random random = new Random();
	String streamId = Integer.toHexString(random.nextInt());

	ClientSession session = new ClientSession(serverName, conn, streamId);
	conn.init(session);
	conn.registerCloseListener(clientSessionListener);

	// 添加到预认证会话集中
	preAuthSessions.put(session.getAddress().getResource(), session);

	// 用户会话计数器执行自增
	connectionsCounter.incrementAndGet();

	log.debug("一个客户端会话创建完成.");
	return session;
}
 
开发者ID:lijian17,项目名称:androidpn-server,代码行数:28,代码来源:SessionManager.java

示例2: createClientSession

import org.androidpn.server.xmpp.net.Connection; //导入依赖的package包/类
/**
 * Creates a new ClientSession and returns it.
 *  
 * @param conn the connection
 * @return a newly created session
 */
public ClientSession createClientSession(Connection conn) {
    if (serverName == null) {
        throw new IllegalStateException("Server not initialized");
    }

    Random random = new Random();
    String streamId = Integer.toHexString(random.nextInt());

    ClientSession session = new ClientSession(serverName, conn, streamId);
    conn.init(session);
    conn.registerCloseListener(clientSessionListener);

    // Add to pre-authenticated sessions
    preAuthSessions.put(session.getAddress().getResource(), session);

    // Increment the counter of user sessions
    connectionsCounter.incrementAndGet();

    log.debug("ClientSession created.");
    return session;
}
 
开发者ID:elphinkuo,项目名称:Androidpn,代码行数:28,代码来源:SessionManager.java

示例3: createClientSession

import org.androidpn.server.xmpp.net.Connection; //导入依赖的package包/类
public ClientSession createClientSession(Connection conn, String streamId) {
    if (serverName == null) {
        throw new IllegalStateException("Server not initialized");
    }
    ClientSession session = new ClientSession(serverName, conn, streamId);
    conn.init(session);
    // Register to receive close notification on this session
    conn.registerCloseListener(clientSessionListener, session);
    // Add to pre-authenticated sessions
    preAuthSessions.put(session.getAddress().getResource(), session);
    // Increment the counter of user sessions
    connectionsCounter.incrementAndGet();

    log.debug("ClientSession created.");
    return session;
}
 
开发者ID:elphinkuo,项目名称:Androidpn,代码行数:17,代码来源:SessionManager.java

示例4: Session

import org.androidpn.server.xmpp.net.Connection; //导入依赖的package包/类
/**
 * Constructor. Creates a new JID using server name and stream ID.
 * 
 * @param serverName the server name
 * @param conn the connection
 * @param streamID the stream ID
 */
public Session(String serverName, Connection conn, String streamID) {
    this.connection = conn;
    this.sessionManager = SessionManager.getInstance();
    this.serverName = serverName;
    this.streamID = streamID;
    this.address = new JID(null, serverName, streamID, true);
}
 
开发者ID:elphinkuo,项目名称:Androidpn,代码行数:15,代码来源:Session.java

示例5: createClientSession

import org.androidpn.server.xmpp.net.Connection; //导入依赖的package包/类
public ClientSession createClientSession(Connection conn, String streamId) {
    if (serverName == null) {
        throw new IllegalStateException("Server not initialized");
    }
    ClientSession session = new ClientSession(serverName, conn, streamId);
    conn.init(session);
    // Register to receive close notification on this session
    conn.registerCloseListener(clientSessionListener, session);
    // Add to pre-authenticated sessions
    preAuthSessions.put(session.getAddress().getResource(), session);
    // Increment the counter of user sessions
    connectionsCounter.incrementAndGet();
    return session;
}
 
开发者ID:elphinkuo,项目名称:Androidpn,代码行数:15,代码来源:SessionManager.java

示例6: Session

import org.androidpn.server.xmpp.net.Connection; //导入依赖的package包/类
public Session(String serverName, Connection connection, String streamID) {
    conn = connection;
    this.streamID = streamID;
    this.serverName = serverName;
    String id = streamID;
    this.address = new JID(null, serverName, id, true);
    this.sessionManager = SessionManager.getInstance();
}
 
开发者ID:elphinkuo,项目名称:Androidpn,代码行数:9,代码来源:Session.java

示例7: createClientSession

import org.androidpn.server.xmpp.net.Connection; //导入依赖的package包/类
public ClientSession createClientSession(Connection conn, String streamId) {
    if (serverName == null) {
        throw new IllegalStateException("Server not initialized");
    }
    ClientSession session = new ClientSession(serverName, conn, streamId);
    conn.init(session);

    // Add to pre-authenticated sessions
    preAuthSessions.put(session.getAddress().getResource(), session);

    // Increment the counter of user sessions
    connectionsCounter.incrementAndGet();

    return session;
}
 
开发者ID:elphinkuo,项目名称:Androidpn,代码行数:16,代码来源:SessionManager.java

示例8: createSession

import org.androidpn.server.xmpp.net.Connection; //导入依赖的package包/类
/**
 * 在服务器和客户端之间创建一个新的会话,并返回它。
 * 
 * @param serverName
 *            服务名
 * @param connection
 *            连接
 * @param xpp
 *            XML解析器来处理传入的数据
 * @return 一个新创建的会话
 * @throws XmlPullParserException
 *             如果解析传入的数据时发生错误
 */
public static ClientSession createSession(String serverName,
		Connection connection, XmlPullParser xpp)
		throws XmlPullParserException {
	log.debug("createSession()...");

	if (!xpp.getName().equals("stream")) {
		throw new XmlPullParserException("坏的开始标签 (not stream)");
	}

	if (!xpp.getNamespace(xpp.getPrefix()).equals(ETHERX_NAMESPACE)) {
		throw new XmlPullParserException("不正确的名称空间的流");
	}

	String language = "en";
	for (int i = 0; i < xpp.getAttributeCount(); i++) {
		if ("lang".equals(xpp.getAttributeName(i))) {
			language = xpp.getAttributeValue(i);
		}
	}

	// 存储语言和版本信息
	connection.setLanaguage(language);
	connection.setXMPPVersion(MAJOR_VERSION, MINOR_VERSION);

	// 创建一个ClientSession
	ClientSession session = SessionManager.getInstance()
			.createClientSession(connection);

	// 建立开始数据包响应
	StringBuilder sb = new StringBuilder(200);
	sb.append("<?xml version='1.0' encoding='UTF-8'?>");
	sb.append("<stream:stream ");
	sb.append("xmlns:stream=\"http://etherx.jabber.org/streams\" xmlns=\"jabber:client\" from=\"");
	sb.append(serverName);
	sb.append("\" id=\"");
	sb.append(session.getStreamID().toString());
	sb.append("\" xml:lang=\"");
	sb.append(language);
	sb.append("\" version=\"");
	sb.append(MAJOR_VERSION).append(".").append(MINOR_VERSION);
	sb.append("\">");
	connection.deliverRawText(sb.toString());

	// XMPP 1.0 需要 stream features
	sb = new StringBuilder();
	sb.append("<stream:features>");
	if (connection.getTlsPolicy() != Connection.TLSPolicy.disabled) {
		sb.append("<starttls xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\">");
		if (connection.getTlsPolicy() == Connection.TLSPolicy.required) {
			sb.append("<required/>");
		}
		sb.append("</starttls>");
	}

	// 具体功能
	String specificFeatures = session.getAvailableStreamFeatures();
	if (specificFeatures != null) {
		sb.append(specificFeatures);
	}
	sb.append("</stream:features>");

	connection.deliverRawText(sb.toString());
	return session;
}
 
开发者ID:lijian17,项目名称:androidpn-server,代码行数:78,代码来源:ClientSession.java

示例9: createSession

import org.androidpn.server.xmpp.net.Connection; //导入依赖的package包/类
/**
 * Creates a new session between the server and a client, and returns it.
 * 
 * @param serverName the server name
 * @param connection the connection
 * @param xpp the XML parser to handle incoming data 
 * @return a newly created session
 * @throws XmlPullParserException if an error occurs while parsing incoming data
 */
public static ClientSession createSession(String serverName,
        Connection connection, XmlPullParser xpp)
        throws XmlPullParserException {
    log.debug("createSession()...");

    if (!xpp.getName().equals("stream")) {
        throw new XmlPullParserException("Bad opening tag (not stream)");
    }

    if (!xpp.getNamespace(xpp.getPrefix()).equals(ETHERX_NAMESPACE)) {
        throw new XmlPullParserException("Stream not in correct namespace");
    }

    String language = "en";
    for (int i = 0; i < xpp.getAttributeCount(); i++) {
        if ("lang".equals(xpp.getAttributeName(i))) {
            language = xpp.getAttributeValue(i);
        }
    }

    // Store language and version information
    connection.setLanaguage(language);
    connection.setXMPPVersion(MAJOR_VERSION, MINOR_VERSION);

    // Create a ClientSession
    ClientSession session = SessionManager.getInstance()
            .createClientSession(connection);

    // Build the start packet response
    StringBuilder sb = new StringBuilder(200);
    sb.append("<?xml version='1.0' encoding='UTF-8'?>");
    sb.append("<stream:stream ");
    sb
            .append("xmlns:stream=\"http://etherx.jabber.org/streams\" xmlns=\"jabber:client\" from=\"");
    sb.append(serverName);
    sb.append("\" id=\"");
    sb.append(session.getStreamID().toString());
    sb.append("\" xml:lang=\"");
    sb.append(language);
    sb.append("\" version=\"");
    sb.append(MAJOR_VERSION).append(".").append(MINOR_VERSION);
    sb.append("\">");
    connection.deliverRawText(sb.toString());

    // XMPP 1.0 needs stream features
    sb = new StringBuilder();
    sb.append("<stream:features>");
    if (connection.getTlsPolicy() != Connection.TLSPolicy.disabled) {
        sb.append("<starttls xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\">");
        if (connection.getTlsPolicy() == Connection.TLSPolicy.required) {
            sb.append("<required/>");
        }
        sb.append("</starttls>");
    }

    String specificFeatures = session.getAvailableStreamFeatures();
    if (specificFeatures != null) {
        sb.append(specificFeatures);
    }
    sb.append("</stream:features>");

    connection.deliverRawText(sb.toString());
    return session;
}
 
开发者ID:elphinkuo,项目名称:Androidpn,代码行数:74,代码来源:ClientSession.java

示例10: createSession

import org.androidpn.server.xmpp.net.Connection; //导入依赖的package包/类
/**
 * Creates a new session between the server and a client, and returns it.
 * 
 * @param serverName the server name
 * @param connection the connection
 * @param xpp the XML parser to handle incoming data 
 * @return a newly created session
 * @throws XmlPullParserException if an error occurs while parsing incoming data
 */
public static ClientSession createSession(String serverName,
        Connection connection, XmlPullParser xpp)
        throws XmlPullParserException {
    log.debug("createSession()...");

    if (!xpp.getName().equals("stream")) {
        throw new XmlPullParserException("Bad opening tag (not stream)");
    }

    if (!xpp.getNamespace(xpp.getPrefix()).equals(ETHERX_NAMESPACE)) {
        throw new XmlPullParserException("Stream not in correct namespace");
    }

    String language = "en";
    for (int i = 0; i < xpp.getAttributeCount(); i++) {
        if ("lang".equals(xpp.getAttributeName(i))) {
            language = xpp.getAttributeValue(i);
        }
    }

    // Store language and version information
    connection.setLanaguage(language);
    connection.setXMPPVersion(MAJOR_VERSION, MINOR_VERSION);

    // Create a ClientSession
    ClientSession session = SessionManager.getInstance()
            .createClientSession(connection);

    // Build the start packet response
    StringBuilder sb = new StringBuilder(200);
    sb.append("<?xml version='1.0' encoding='UTF-8'?>");
    sb.append("<stream:stream ");
    sb
            .append("xmlns:stream=\"http://etherx.jabber.org/streams\" xmlns=\"jabber:client\" from=\"");
    sb.append(serverName);
    sb.append("\" id=\"");
    sb.append(session.getStreamID().toString());
    sb.append("\" xml:lang=\"");
    sb.append(language);
    sb.append("\" version=\"");
    sb.append(MAJOR_VERSION).append(".").append(MINOR_VERSION);
    sb.append("\">");
    connection.deliverRawText(sb.toString());

    // XMPP 1.0 needs stream features
    sb = new StringBuilder();
    sb.append("<stream:features>");
    String specificFeatures = session.getAvailableStreamFeatures();
    if (specificFeatures != null) {
        sb.append(specificFeatures);
    }
    sb.append("</stream:features>");

    connection.deliverRawText(sb.toString());
    return session;
}
 
开发者ID:elphinkuo,项目名称:Androidpn,代码行数:66,代码来源:ClientSession.java

示例11: getConnection

import org.androidpn.server.xmpp.net.Connection; //导入依赖的package包/类
public Connection getConnection() {
    return conn;
}
 
开发者ID:elphinkuo,项目名称:Androidpn,代码行数:4,代码来源:Session.java

示例12: ClientSession

import org.androidpn.server.xmpp.net.Connection; //导入依赖的package包/类
public ClientSession(String serverName, Connection connection,
        String streamID) {
    super(serverName, connection, streamID);
    presence = new Presence();
    presence.setType(Presence.Type.unavailable);
}
 
开发者ID:elphinkuo,项目名称:Androidpn,代码行数:7,代码来源:ClientSession.java

示例13: createSession

import org.androidpn.server.xmpp.net.Connection; //导入依赖的package包/类
public static ClientSession createSession(String serverName,
        XmlPullParser xpp, Connection connection)
        throws XmlPullParserException {
    if (!xpp.getName().equals("stream")) {
        throw new XmlPullParserException("Bad opening tag (not stream)");
    }

    if (!xpp.getNamespace(xpp.getPrefix()).equals(ETHERX_NAMESPACE)) {
        throw new XmlPullParserException("Stream not in correct namespace");
    }

    String language = "en";
    for (int i = 0; i < xpp.getAttributeCount(); i++) {
        if ("lang".equals(xpp.getAttributeName(i))) {
            language = xpp.getAttributeValue(i);
        }
    }

    // Store language and version information in the connection.
    connection.setLanaguage(language);
    connection.setXMPPVersion(MAJOR_VERSION, MINOR_VERSION);

    // Create a ClientSession for this user.
    ClientSession session = SessionManager.getInstance()
            .createClientSession(connection);

    // Build the start packet response
    StringBuilder sb = new StringBuilder(200);
    sb.append("<?xml version='1.0' encoding='");
    sb.append(CHARSET);
    sb.append("'?>");
    sb.append("<stream:stream ");
    sb
            .append("xmlns:stream=\"http://etherx.jabber.org/streams\" xmlns=\"jabber:client\" from=\"");
    sb.append(serverName);
    sb.append("\" id=\"");
    sb.append(session.getStreamID().toString());
    sb.append("\" xml:lang=\"");
    sb.append(language);
    sb.append("\" version=\"");
    sb.append(MAJOR_VERSION).append(".").append(MINOR_VERSION);
    sb.append("\">");
    connection.deliverRawText(sb.toString());

    // XMPP 1.0 so we need to announce stream features.
    sb = new StringBuilder(490);
    sb.append("<stream:features>");
    // Include Stream features
    String specificFeatures = session.getAvailableStreamFeatures();
    if (specificFeatures != null) {
        sb.append(specificFeatures);
    }
    sb.append("</stream:features>");

    connection.deliverRawText(sb.toString());
    return session;
}
 
开发者ID:elphinkuo,项目名称:Androidpn,代码行数:58,代码来源:ClientSession.java

示例14: createSession

import org.androidpn.server.xmpp.net.Connection; //导入依赖的package包/类
public static ClientSession createSession(String serverName,
        XmlPullParser xpp, Connection connection)
        throws XmlPullParserException {
    if (!xpp.getName().equals("stream")) {
        throw new XmlPullParserException("Bad opening tag (not stream)");
    }

    if (!xpp.getNamespace(xpp.getPrefix()).equals(ETHERX_NAMESPACE)) {
        throw new XmlPullParserException("Stream not in correct namespace");
    }

    String language = "en";
    for (int i = 0; i < xpp.getAttributeCount(); i++) {
        if ("lang".equals(xpp.getAttributeName(i))) {
            language = xpp.getAttributeValue(i);
        }
    }

    // Store language and version information
    connection.setLanaguage(language);
    connection.setXMPPVersion(MAJOR_VERSION, MINOR_VERSION);

    // Create a ClientSession
    ClientSession session = SessionManager.getInstance()
            .createClientSession(connection);

    // Build the start packet response
    StringBuilder sb = new StringBuilder(200);
    sb.append("<?xml version='1.0' encoding='");
    sb.append(CHARSET);
    sb.append("'?>");
    sb.append("<stream:stream ");
    sb
            .append("xmlns:stream=\"http://etherx.jabber.org/streams\" xmlns=\"jabber:client\" from=\"");
    sb.append(serverName);
    sb.append("\" id=\"");
    sb.append(session.getStreamID().toString());
    sb.append("\" xml:lang=\"");
    sb.append(language);
    sb.append("\" version=\"");
    sb.append(MAJOR_VERSION).append(".").append(MINOR_VERSION);
    sb.append("\">");
    connection.deliverRawText(sb.toString());

    // XMPP 1.0 needs stream features
    sb = new StringBuilder();
    sb.append("<stream:features>");
    String specificFeatures = session.getAvailableStreamFeatures();
    if (specificFeatures != null) {
        sb.append(specificFeatures);
    }
    sb.append("</stream:features>");

    connection.deliverRawText(sb.toString());
    return session;
}
 
开发者ID:elphinkuo,项目名称:Androidpn,代码行数:57,代码来源:ClientSession.java


注:本文中的org.androidpn.server.xmpp.net.Connection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。