本文整理汇总了Java中org.bouncycastle.crypto.tls.TlsClientProtocol.getOutputStream方法的典型用法代码示例。如果您正苦于以下问题:Java TlsClientProtocol.getOutputStream方法的具体用法?Java TlsClientProtocol.getOutputStream怎么用?Java TlsClientProtocol.getOutputStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.crypto.tls.TlsClientProtocol
的用法示例。
在下文中一共展示了TlsClientProtocol.getOutputStream方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.bouncycastle.crypto.tls.TlsClientProtocol; //导入方法依赖的package包/类
public static void main(String[] args)
throws Exception
{
InetAddress address = InetAddress.getLocalHost();
int port = 5556;
long time1 = System.currentTimeMillis();
MyTlsClient client = new MyTlsClient(null);
TlsClientProtocol protocol = openTlsConnection(address, port, client);
protocol.close();
long time2 = System.currentTimeMillis();
System.out.println("Elapsed 1: " + (time2 - time1) + "ms");
client = new MyTlsClient(client.getSessionToResume());
protocol = openTlsConnection(address, port, client);
long time3 = System.currentTimeMillis();
System.out.println("Elapsed 2: " + (time3 - time2) + "ms");
OutputStream output = protocol.getOutputStream();
output.write("GET / HTTP/1.1\r\n\r\n".getBytes("UTF-8"));
output.flush();
InputStream input = protocol.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
String line;
while ((line = reader.readLine()) != null)
{
System.out.println(">>> " + line);
}
protocol.close();
}
示例2: testConnection
import org.bouncycastle.crypto.tls.TlsClientProtocol; //导入方法依赖的package包/类
public void testConnection()
throws Exception
{
Thread server = new HTTPSServerThread();
server.start();
Thread.yield();
AlwaysValidVerifyer verifyer = new AlwaysValidVerifyer();
Socket s = null;
for (int i = 0; s == null && i != 3; i++)
{
Thread.sleep(1000);
try
{
s = new Socket("localhost", PORT_NO);
}
catch (IOException e)
{
// ignore
}
}
if (s == null)
{
throw new IOException("unable to connect");
}
// long time = System.currentTimeMillis();
TlsClientProtocol protocol = new TlsClientProtocol(s.getInputStream(), s.getOutputStream());
protocol.connect(new LegacyTlsClient(verifyer));
InputStream is = protocol.getInputStream();
OutputStream os = protocol.getOutputStream();
os.write("GET / HTTP/1.1\r\n\r\n".getBytes());
// time = System.currentTimeMillis();
byte[] buf = new byte[4096];
int read = 0;
int total = 0;
while ((read = is.read(buf, total, buf.length - total)) > 0)
{
total += read;
}
is.close();
byte[] expected = Hex.decode("485454502f312e3120323030204f4b0d0a436f6e74656e742d547970653a20746578742f68"
+ "746d6c0d0a0d0a3c68746d6c3e0d0a3c626f64793e0d0a48656c6c6f20576f726c64210d0a3c2f626f64793e0d0a3c2f"
+ "68746d6c3e0d0a");
assertEquals(total, expected.length);
byte[] tmp = new byte[expected.length];
System.arraycopy(buf, 0, tmp, 0, total);
assertTrue(Arrays.areEqual(expected, tmp));
}