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


Java Socket.getInputStream方法代码示例

本文整理汇总了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);
	}
}
 
开发者ID:PanagiotisDrakatos,项目名称:T0rlib4j,代码行数:19,代码来源:SocksProxyBase.java

示例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();
      }
    };
  }
 
开发者ID:EVelez79,项目名称:CodeU-ProjectGroup6,代码行数:21,代码来源:ClientConnectionSource.java

示例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);
    }
}
 
开发者ID:dmitrykolesnikovich,项目名称:featurea,代码行数:9,代码来源:TcpSlave.java

示例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();
}
 
开发者ID:Miic,项目名称:WholesomeChat,代码行数:22,代码来源:MainController.java

示例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);
    }
}
 
开发者ID:intuit,项目名称:karate,代码行数:17,代码来源:MonitorThread.java

示例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);
}
 
开发者ID:android-notes,项目名称:vase,代码行数:24,代码来源:HttpPost.java

示例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);
    }
}
 
开发者ID:mikroskeem,项目名称:votifier2-java,代码行数:38,代码来源:Votifier2Test.java

示例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();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:39,代码来源:InvalidLdapFilters.java

示例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);
    }
}
 
开发者ID:wz12406,项目名称:accumulate,代码行数:14,代码来源:BinaryIn.java

示例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() + "]";
}
 
开发者ID:rtr-nettest,项目名称:open-rmbt,代码行数:15,代码来源:ClientHandler.java

示例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;
}
 
开发者ID:yanghanxy,项目名称:CloudDB,代码行数:7,代码来源:MessageHandler.java

示例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());
    }
}
 
开发者ID:NexusByte,项目名称:LotusCloud,代码行数:33,代码来源:PacketClient.java

示例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();
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:31,代码来源:TestBlockReplacement.java

示例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;
}
 
开发者ID:TauOmicronMu,项目名称:TeamProject,代码行数:15,代码来源:ServerSideClientHandler.java

示例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());
}
 
开发者ID:naeemkhan12,项目名称:IOTproject,代码行数:6,代码来源:Client.java


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