• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java SocketConnection类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: openConnection

import javax.microedition.io.SocketConnection; //导入依赖的package包/类
private boolean openConnection(int index, boolean outputError) {
	System.out.println("Attempting to connect to " + remoteIPList[index]);
	if (index < 0 || index >= lastConnectionAttempt.length)
		return false;
	lastConnectionAttempt[index] = System.currentTimeMillis();
	try {
		// This is my version of a "timeout" for 5000ms
		//Timer t = new Timer();
		//t.schedule(new TimeoutTask(Thread.currentThread()), 5000);
		// This is what is being timed out
		comm = (SocketConnection)Connector.open("socket://"+remoteIPList[index]+":"+remotePort, connectionType, true);
		outputStream = comm.openOutputStream();
		return true;
	} catch (Exception ex) {
		outputStream = null;
		comm = null;
		if (outputError) {
			String error = toString()
					+ ": Failed to establish connection"
					+ " with driver station"
					+ " at " + remoteIPList[index]+":"+remotePort;
			System.out.println(error);
		}
		return false;
	}
}
 
开发者ID:Team-2502,项目名称:RobotCode2014,代码行数:27,代码来源:BlackBoxProtocol.java


示例2: benchmarkLargeRead

import javax.microedition.io.SocketConnection; //导入依赖的package包/类
void benchmarkLargeRead() throws IOException {
  SocketConnection client = (SocketConnection)Connector.open("socket://localhost:8000");

  OutputStream os = client.openOutputStream();
  os.write("GET /bench/benchmark.jar HTTP/1.1\r\nHost: localhost\r\n\r\n".getBytes());
  os.close();

  InputStream is = client.openInputStream();
  byte[] data = new byte[1024];
  int len;
  MemorySampler.sampleMemory("Memory before");
  long start = JVM.monotonicTimeMillis();
  do {
    len = is.read(data);
  } while (len != -1);
  System.out.println("large read time: " + (JVM.monotonicTimeMillis() - start));
  MemorySampler.sampleMemory("Memory  after");
  is.close();

  client.close();
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:22,代码来源:SocketBench.java


示例3: benchmarkLargeRead

import javax.microedition.io.SocketConnection; //导入依赖的package包/类
void benchmarkLargeRead() throws IOException {
  SocketConnection client = (SocketConnection)Connector.open("socket://localhost:8000");

  OutputStream os = client.openOutputStream();
  os.write(("GET /bench/benchmark.jar HTTP/1.1\r\n" +
            "Host: localhost\r\n" +
            "Connection: close\r\n" +
            "\r\n").getBytes());
  os.close();

  InputStream is = client.openInputStream();
  byte[] data = new byte[1024];
  int len;
  long start = JVM.monotonicTimeMillis();
  do {
    len = is.read(data);
  } while (len != -1);
  System.out.println("large read time: " + (JVM.monotonicTimeMillis() - start));
  is.close();

  client.close();
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:23,代码来源:SocketStressBench.java


示例4: run

import javax.microedition.io.SocketConnection; //导入依赖的package包/类
public void run() {
    try {
        final ServerSocketConnection s = (ServerSocketConnection) Connector.open("serversocket://:" + port);
        while (listening) {
            final SocketConnection connection = (SocketConnection) s.acceptAndOpen(); // blocks until a connection is made
            final Thread t = new Thread(new VisionServerConnectionHandler(connection));
            t.start();
            connections.addElement(connection);
            try {
                Thread.sleep(100);
            } catch (final InterruptedException ex) {
                System.out.println("Thread sleep failed.");
            }
        }
    } catch (final IOException e) {
        System.out.println("Socket failure.");
        e.printStackTrace();
    }
}
 
开发者ID:FRC3161,项目名称:Iapetus2014,代码行数:20,代码来源:CheesyVisionServer.java


示例5: testApn

import javax.microedition.io.SocketConnection; //导入依赖的package包/类
private boolean testApn(String apn, String target) throws ATCommandFailedException {
    if (Logger.BUILD_DEBUG) {
        Logger.log(this + ".testApn( \"" + apn + "\", \"" + target + "\" );");
    }
    ATExecution.applyAPN(apn);

    try {
        SocketConnection conn = (SocketConnection) Connector.open("socket://" + target);
        conn.close();
        if (Logger.BUILD_DEBUG) {
            Logger.log("Connected ok !");
        }
        return true;
    } catch (Exception ex) {
        // This is the standard message for APN detection failure, let's skip it
        if (ex instanceof IOException && ex.getMessage().equals("Profile could not be activated")) {
            return false;
        }
        if (Logger.BUILD_CRITICAL) {
            Logger.log(this + ".testApn: " + ex);
        }
    }
    return false;
}
 
开发者ID:fclairamb,项目名称:tc65lib,代码行数:25,代码来源:APNAutodetection.java


示例6: connect

import javax.microedition.io.SocketConnection; //导入依赖的package包/类
/**
 * Connect using custom settings
 * @param ip Address of Server "xxx.xxx.xxx.xxx"
 * @param port of Server "XXXXX"
 */
public void connect(String ip, String port, int bufferSize, char delimiter) throws IOException {
    this.ip = ip;
    this.port = port;
    this.bufferSize = bufferSize;
    this.delimiter = delimiter;
    beenConnected = true;
    url = "socket://" + ip + ":" + port; //Store URL of Connection
    System.out.println("Connecting to PI...");
    client = (SocketConnection) Connector.open(url, Connector.READ_WRITE, true); //Setup input and output through client SocketConnection
    try{            
        is = client.openInputStream();
        os = client.openOutputStream();
        if(true) {
            System.out.println("Connected to: "+client.getAddress() + ":" + client.getPort());
        }
        connected = true;
    }
    catch (Exception ex){
         connected = false;
    }
    
    
}
 
开发者ID:frc3946,项目名称:UltimateAscent,代码行数:29,代码来源:SocketPi.java


示例7: start

import javax.microedition.io.SocketConnection; //导入依赖的package包/类
/**
 * Starts the module, by creating a TCP socket to the server.
 */
public void start() throws IOException, MqttException {
	final String methodName = "start";
	try {
		log.fine(className,methodName, "252", new Object[] {uri});
		connection = (SocketConnection) Connector.open(uri);
		connection.setSocketOption(SocketConnection.DELAY, 0);  // Do not use Nagle's algorithm
		in = connection.openInputStream();
		out = connection.openOutputStream();
	}
	catch (IOException ex) {
		//@TRACE 250=Failed to create TCP socket
		log.fine(className,methodName,"250",null,ex);
		throw new MqttException(MqttException.REASON_CODE_SERVER_CONNECT_ERROR, ex);
	}
}
 
开发者ID:gulliverrr,项目名称:hestia-engine-dev,代码行数:19,代码来源:TCPMicroNetworkModule.java


示例8: start

import javax.microedition.io.SocketConnection; //导入依赖的package包/类
/**
 * Starts the module, by creating a TCP socket to the server.
 */
public void start() throws IOException, MqttException {
	final String methodName = "start";
	try {
		log.fine(className,methodName, "252", new Object[] {uri});
		connection = (SecureConnection) Connector.open(uri);
		connection.setSocketOption(SocketConnection.DELAY, 0);  // Do not use Nagle's algorithm
		in = connection.openInputStream();
		out = connection.openOutputStream();
	}
	catch (IOException ex) {
		System.out.println(ex.getMessage());
		//@TRACE 250=Failed to create TCP socket
		log.fine(className,methodName,"250",null,ex);
		ex.printStackTrace();
		throw new MqttException(MqttException.REASON_CODE_SERVER_CONNECT_ERROR, ex);
	}
}
 
开发者ID:gulliverrr,项目名称:hestia-engine-dev,代码行数:21,代码来源:SSLMicroNetworkModule.java


示例9: socketOpen

import javax.microedition.io.SocketConnection; //导入依赖的package包/类
public Socket socketOpen(String url)
{
  try
  {
    Socket socket = new Socket();
    socket.socket = ((SocketConnection)Connector.open("socket://" + url));
    jcc2.lib.stdlib.library.getSingleton().setLastError(null);
    return socket;
  }
  catch (Exception e)
  {
    jcc2.lib.stdlib.library.getSingleton().setLastError(e.toString());
  }
  return null;
}
 
开发者ID:NeiroNext,项目名称:JccAPV,代码行数:16,代码来源:library.java


示例10: connectToSocket

import javax.microedition.io.SocketConnection; //导入依赖的package包/类
private boolean connectToSocket() {
	if (initialized)
		return true;
	try {
		comm = (SocketConnection)Connector.open(address, Connector.READ_WRITE);
		inputStream = comm.openInputStream();
		outputStream = comm.openOutputStream();
		initialized = true;
		BlackBoxProtocol.log("Successfully connected to " + address);
	} catch (IOException ex) {
		BlackBoxProtocol.log("Failed to connect to " + address);
		initialized = false;
	}
	return initialized;
}
 
开发者ID:Team-2502,项目名称:RobotCode2014,代码行数:16,代码来源:Socket.java


示例11: checkOption

import javax.microedition.io.SocketConnection; //导入依赖的package包/类
/**
 * Check a socket option to make sure it's a valid option.
 *
 * @param option socket option identifier (KEEPALIVE, LINGER, 
 * SNDBUF, RCVBUF, or DELAY)
 * @exception  IllegalArgumentException if  the value is not 
 *              valid (e.g. negative value)
 *              
 * @see #getSocketOption
 * @see #setSocketOption
 */
private void checkOption(byte option) 
    throws IllegalArgumentException {
    if (option == SocketConnection.KEEPALIVE 
        || option == SocketConnection.LINGER 
        || option == SocketConnection.SNDBUF 
        || option == SocketConnection.RCVBUF 
        || option == SocketConnection.DELAY) {
        return;
    }
    throw new IllegalArgumentException("Unsupported Socket Option");
        
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:24,代码来源:Protocol.java


示例12: createConnection

import javax.microedition.io.SocketConnection; //导入依赖的package包/类
/**
 * Create the underlying network TCP connection.
 *
 * @param url the url of connection
 * @return network stream connection
 * @exception IOException is thrown if the connection cannot be opened
 */
private com.sun.midp.io.j2me.socket.Protocol createConnection(String url)
    throws IOException {
    com.sun.midp.io.j2me.socket.Protocol conn =
        new com.sun.midp.io.j2me.socket.Protocol();

    conn.openPrim(classSecurityToken, url);

    // Do not delay request since this delays the response.
    conn.setSocketOption(SocketConnection.DELAY, 0);

    return conn;
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:20,代码来源:Protocol.java


示例13: OBEXTCPServiceRecordImpl

import javax.microedition.io.SocketConnection; //导入依赖的package包/类
OBEXTCPServiceRecordImpl(SocketConnection connection) {
	try {
		port = String.valueOf(connection.getPort());
		host = connection.getAddress();
	} catch (IOException e) {
		host = null;
	}
}
 
开发者ID:empeeoh,项目名称:bluecove-osx,代码行数:9,代码来源:OBEXTCPServiceRecordImpl.java


示例14: connect

import javax.microedition.io.SocketConnection; //导入依赖的package包/类
public synchronized void connect() throws IOException {
    m_socket = (SocketConnection) Connector.open(url);//, Connector.READ_WRITE, true);
    m_is = m_socket.openInputStream();
    m_os = m_socket.openOutputStream();
    m_connected = true;
    
}
 
开发者ID:frc3946,项目名称:UltimateAscent,代码行数:8,代码来源:ThreadedPi.java


示例15: establishConnection

import javax.microedition.io.SocketConnection; //导入依赖的package包/类
public void establishConnection(String host, int port) {
this.host = host;
this.port = port;
running = connected = false;
socketListeners = new Vector();
try {
	connection = ((SocketConnection) (Connector.open("socket://" + host
			+ ":" + port)));
} catch (IOException e) {
	e.printStackTrace();
	connection = null;
}

  }
 
开发者ID:manitourobotics,项目名称:2013-robot,代码行数:15,代码来源:ClientSocket.java


示例16: connect

import javax.microedition.io.SocketConnection; //导入依赖的package包/类
public void connect() throws IOException {
	this.sc = (SocketConnection) Connector.open("socket://" + this.ip + ":" + this.port);
	sc.setSocketOption(SocketConnection.LINGER, 5);

	this.is = sc.openInputStream();
	this.os = sc.openOutputStream();

	this.isConnected = true;
}
 
开发者ID:team178,项目名称:Hawkeye,代码行数:10,代码来源:OculusClient.java


示例17: connect

import javax.microedition.io.SocketConnection; //导入依赖的package包/类
/**
 * Connect to the underlying network TCP transport.
 * If the proxy is configured, connect to it as tunnel first.
 * <p>
 * Warning: A subclass that implements this method, should not call this
 * method and should implement the disconnect method.
 *
 * @return network stream connection
 * @exception IOException is thrown if the connection cannot be opened
 */
protected StreamConnection connect() throws IOException {
    StreamConnection sc;
    com.sun.midp.io.j2me.socket.Protocol conn;

    if (!permissionChecked) {
        throw new SecurityException();
    }

    sc = connectionPool.get(classSecurityToken, protocol,
                                          url.host, url.port);

    if (sc != null) {
        return sc;
    }

    conn = new com.sun.midp.io.j2me.socket.Protocol();

    if (http_proxy == null || url.host.equals("localhost") ||
        url.host.equals("127.0.0.1")) {
        /* bypass proxy when trying to connect to the same computer
         * and not using explicit IP or host name */
        conn.openPrim(classSecurityToken, "//" + hostAndPort);

        // Do not delay request since this delays the response.
        conn.setSocketOption(SocketConnection.DELAY, 0);
        return conn;
    }
  
    conn.openPrim(classSecurityToken, "//" + http_proxy);

    // Do not delay request since this delays the response.
    conn.setSocketOption(SocketConnection.DELAY, 0);

    // openData*Stream cannot be call twice, so save them for later
    streamOutput = conn.openDataOutputStream();
    streamInput = conn.openDataInputStream();

    try {
        doTunnelHandshake(streamOutput, streamInput);
    } catch (IOException ioe) {
        String response = ioe.getMessage();

        try {
            disconnect(conn, streamInput, streamOutput);
        } catch (Exception e) {
            // do not over throw the handshake exception
        }

        streamOutput = null;
        streamInput = null;

        if ((response != null) && (response.indexOf(" 500 ") > -1)) {
            throw new ConnectionNotFoundException(response);
        } else {
            throw ioe;
        }
    }

    return conn;
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:71,代码来源:Protocol.java


示例18: VisionServerConnectionHandler

import javax.microedition.io.SocketConnection; //导入依赖的package包/类
public VisionServerConnectionHandler(SocketConnection c) {
  connection = c;
}
 
开发者ID:runnymederobotics,项目名称:robot2014,代码行数:4,代码来源:CheesyVisionServer.java


示例19: VisionServerConnectionHandler

import javax.microedition.io.SocketConnection; //导入依赖的package包/类
public VisionServerConnectionHandler(final SocketConnection c) {
    connection = c;
}
 
开发者ID:FRC3161,项目名称:Iapetus2014,代码行数:4,代码来源:CheesyVisionServer.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java NSString类代码示例发布时间:2022-05-21
下一篇:
Java ManagementPermission类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap