本文整理汇总了Java中javax.microedition.io.SocketConnection.openOutputStream方法的典型用法代码示例。如果您正苦于以下问题:Java SocketConnection.openOutputStream方法的具体用法?Java SocketConnection.openOutputStream怎么用?Java SocketConnection.openOutputStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.microedition.io.SocketConnection
的用法示例。
在下文中一共展示了SocketConnection.openOutputStream方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
}
示例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();
}
示例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();
}
示例4: 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;
}
}
示例5: 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);
}
}
示例6: 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;
}
示例7: 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;
}