本文整理汇总了Java中java.net.Socket.getInputStream方法的典型用法代码示例。如果您正苦于以下问题:Java Socket.getInputStream方法的具体用法?Java Socket.getInputStream怎么用?Java Socket.getInputStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.net.Socket
的用法示例。
在下文中一共展示了Socket.getInputStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startSession
import java.net.Socket; //导入方法依赖的package包/类
protected void startSession() throws SocksException {
try {
if (chainProxy == null) {
proxySocket = new Socket(proxyIP, proxyPort);
} else if (proxyIP != null) {
proxySocket = new SocksSocket(chainProxy, proxyIP, proxyPort);
} else {
proxySocket = new SocksSocket(chainProxy, proxyHost, proxyPort);
}
in = proxySocket.getInputStream();
out = proxySocket.getOutputStream();
} catch (final SocksException se) {
throw se;
} catch (final IOException io_ex) {
throw new SocksException(SOCKS_PROXY_IO_ERROR, "" + io_ex);
}
}
示例2: fromSocket
import java.net.Socket; //导入方法依赖的package包/类
private static Connection fromSocket(final Socket socket) throws IOException {
return new Connection() {
@Override
public InputStream in() throws IOException {
return socket.getInputStream();
}
@Override
public OutputStream out() throws IOException {
return socket.getOutputStream();
}
@Override
public void close() throws IOException {
socket.close();
}
};
}
示例3: TcpConnectionHandler
import java.net.Socket; //导入方法依赖的package包/类
TcpConnectionHandler(Socket socket) throws ModbusInitException {
this.socket = socket;
try {
transport = new TestableTransport(socket.getInputStream(), socket.getOutputStream());
} catch (IOException e) {
throw new ModbusInitException(e);
}
}
示例4: InitSocket
import java.net.Socket; //导入方法依赖的package包/类
/** Create socket, and receiving thread */
public void InitSocket(String server, int port) throws IOException {
socket = new Socket(server, port);
outputStream = socket.getOutputStream();
Thread receivingThread = new Thread() {
@Override
public void run() {
try {
BufferedReader reader = new BufferedReader(
new InputStreamReader(socket.getInputStream()));
String line;
while ((line = reader.readLine()) != null)
notifyObservers(line);
} catch (IOException ex) {
notifyObservers(ex);
}
}
};
receivingThread.start();
}
示例5: run
import java.net.Socket; //导入方法依赖的package包/类
@Override
public void run() {
logger.info("starting thread: {}", getName());
Socket accept;
try {
accept = socket.accept();
BufferedReader reader = new BufferedReader(new InputStreamReader(accept.getInputStream()));
reader.readLine();
logger.info("shutting down thread: {}", getName());
stoppable.stop();
accept.close();
socket.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例6: process
import java.net.Socket; //导入方法依赖的package包/类
@Override
public void process(Config config, String stateLine, Socket socket) {
this.mConfig = config;
Message request = new Message();
InputStream inputStream = null;
OutputStream outputStream = null;
Headers headers;
try {
inputStream = socket.getInputStream();
outputStream = socket.getOutputStream();
headers = HttpUtils.readHeaders(inputStream);
request.reqHeaders = (Headers) headers.clone();
headers = HttpUtils.filterHeaders(headers);
} catch (Exception e) {
IOUtils.closeStream(inputStream);
IOUtils.closeStream(outputStream);
return;
}
request.reqStateLine = stateLine;
proxyHttpPost(stateLine, headers, inputStream, outputStream, request);
}
示例7: testVoteSending
import java.net.Socket; //导入方法依赖的package包/类
@Test
public void testVoteSending() throws Exception {
try {
/* Open up connection to Votifier */
Socket socket = new Socket("127.0.0.1", 8192);
InputStream is = socket.getInputStream();
OutputStream os = socket.getOutputStream();
/* Read Votifier packet and grab challenge token */
String in = new BufferedReader(new InputStreamReader(is)).readLine();
String[] votifierIn = in.split(" ");
Assert.assertEquals("Incorrect Votifier data!", 3, votifierIn.length);
Assert.assertEquals("Votifier signature mismatch", "VOTIFIER", votifierIn[0]);
String challengeToken = votifierIn[2];
/* Create vote object */
Votifier2.Vote vote = Votifier2.newVoteObject(TEST_VOTER_NAME, TEST_SERVICE_NAME);
byte[] message = Votifier2.encodeMessage(vote, challengeToken, TEST_SERVER_KEY);
/* Send vote object */
os.write(message);
os.flush();
/* Read status */
in = new BufferedReader(new InputStreamReader(is)).readLine();
JSONObject result = new JSONObject(in);
Assert.assertEquals("Votifier status was not 'ok'! Data: " + result, "ok", result.get("status"));
/* Close connection */
os.close();
socket.close();
} catch(SocketException e){
/* Skip test */
Assume.assumeNoException(e);
}
}
示例8: doServerSide
import java.net.Socket; //导入方法依赖的package包/类
void doServerSide() throws Exception {
ServerSocket serverSock = new ServerSocket(serverPort);
// signal client, it's ready to accecpt connection
serverPort = serverSock.getLocalPort();
serverReady = true;
// accept a connection
Socket socket = serverSock.accept();
System.out.println("Server: Connection accepted");
InputStream is = socket.getInputStream();
OutputStream os = socket.getOutputStream();
// read the bindRequest
while (is.read() != -1) {
// ignore
is.skip(is.available());
break;
}
byte[] bindResponse = {0x30, 0x0C, 0x02, 0x01, 0x01, 0x61, 0x07, 0x0A,
0x01, 0x00, 0x04, 0x00, 0x04, 0x00};
// write bindResponse
os.write(bindResponse);
os.flush();
// ignore any more request.
while (is.read() != -1) {
// ignore
is.skip(is.available());
}
is.close();
os.close();
socket.close();
serverSock.close();
}
示例9: BinaryIn
import java.net.Socket; //导入方法依赖的package包/类
/**
* Create a binary input stream from a socket.
*/
public BinaryIn(Socket socket) {
try {
InputStream is = socket.getInputStream();
in = new BufferedInputStream(is);
fillBuffer();
}
catch (IOException ioe) {
System.err.println("Could not open " + socket);
}
}
示例10: ClientHandler
import java.net.Socket; //导入方法依赖的package包/类
/**
*
* @param serverSocket
* @param socket
* @throws IOException
*/
public ClientHandler(ServerSocket serverSocket, Socket socket) throws IOException {
this.serverSocket = serverSocket;
this.socket = socket;
this.in = new BufferedInputStream(socket.getInputStream());
this.out = new FilterOutputStream(socket.getOutputStream());
this.reader = new BufferedReader(new InputStreamReader(in));
this.name = "[ClientHandler " + socket.getInetAddress().toString() + "]";
}
示例11: MessageHandler
import java.net.Socket; //导入方法依赖的package包/类
public MessageHandler(Socket socket, Logger logger) throws IOException{
this.input = socket.getInputStream();
this.output = socket.getOutputStream();
this.socket = socket;
this.logger = logger;
}
示例12: request
import java.net.Socket; //导入方法依赖的package包/类
public static Packet request(String host, int port, Packet packet) {
KeyPair keyPair = Crypter.generateKeyPair();
try {
Socket socket = new Socket(host, port);
if (socket.isClosed()) {
return new ErrorPacket("socket closed");
}
ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream());
ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
out.writeObject(keyPair.getPublic());
PublicKey publicKey = (PublicKey) in.readObject();
SecretKey key = Crypter.generateEC(keyPair.getPrivate(), publicKey);
out.writeObject(Crypter.encrypt(key, Crypter.toByteArray(packet)));
out.flush();
Packet response = (Packet) Crypter.toObject(Crypter.decrypt(key, (byte[]) in.readObject()));
in.close();
out.close();
socket.close();
return response;
} catch (Exception ex) {
return new ErrorPacket(ex.getMessage());
}
}
示例13: replaceBlock
import java.net.Socket; //导入方法依赖的package包/类
private boolean replaceBlock(
ExtendedBlock block,
DatanodeInfo source,
DatanodeInfo sourceProxy,
DatanodeInfo destination,
StorageType targetStorageType) throws IOException, SocketException {
Socket sock = new Socket();
try {
sock.connect(NetUtils.createSocketAddr(destination.getXferAddr()),
HdfsServerConstants.READ_TIMEOUT);
sock.setKeepAlive(true);
// sendRequest
DataOutputStream out = new DataOutputStream(sock.getOutputStream());
new Sender(out).replaceBlock(block, targetStorageType,
BlockTokenSecretManager.DUMMY_TOKEN, source.getDatanodeUuid(),
sourceProxy);
out.flush();
// receiveResponse
DataInputStream reply = new DataInputStream(sock.getInputStream());
BlockOpResponseProto proto =
BlockOpResponseProto.parseDelimitedFrom(reply);
while (proto.getStatus() == Status.IN_PROGRESS) {
proto = BlockOpResponseProto.parseDelimitedFrom(reply);
}
return proto.getStatus() == Status.SUCCESS;
} finally {
sock.close();
}
}
示例14: ServerSideClientHandler
import java.net.Socket; //导入方法依赖的package包/类
public ServerSideClientHandler(Socket clientSocket, Queue playerQueue) {
if (clientSocket == null) {
System.err.println("[ERROR] ServerSideClientHandler constructor: Client socket is null.");
System.exit(1);
}
this.clientSocket = clientSocket;
try {
this.inputStream = new ObjectInputStream(clientSocket.getInputStream());
this.outputStream = new ObjectOutputStream(clientSocket.getOutputStream());
} catch (IOException e) {
System.err.println("[ERROR] ServerSideClientHandler constructor: Couldn't get input or output stream from socket.");
}
this.playerQueue = playerQueue;
}
示例15: createConnection
import java.net.Socket; //导入方法依赖的package包/类
public void createConnection() throws UnknownHostException, IOException{
Socket client = new Socket("127.0.0.1", 2222);
BufferedInputStream stream = new BufferedInputStream(client.getInputStream());
}