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


Java Socket.getOutputStream方法代码示例

本文整理汇总了Java中java.net.Socket.getOutputStream方法的典型用法代码示例。如果您正苦于以下问题:Java Socket.getOutputStream方法的具体用法?Java Socket.getOutputStream怎么用?Java Socket.getOutputStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.net.Socket的用法示例。


在下文中一共展示了Socket.getOutputStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: Http2TestServerConnection

import java.net.Socket; //导入方法依赖的package包/类
Http2TestServerConnection(Http2TestServer server, Socket socket) throws IOException {
    if (socket instanceof SSLSocket) {
        handshake(server.serverName(), (SSLSocket)socket);
    }
    System.err.println("TestServer: New connection from " + socket);
    this.server = server;
    this.streams = Collections.synchronizedMap(new HashMap<>());
    this.outputQ = new Queue<>();
    this.socket = socket;
    this.serverSettings = SettingsFrame.getDefaultSettings();
    this.exec = server.exec;
    this.secure = server.secure;
    this.pushStreams = new HashSet<>();
    is = new BufferedInputStream(socket.getInputStream());
    os = new BufferedOutputStream(socket.getOutputStream());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:Http2TestServerConnection.java

示例2: responseClient

import java.net.Socket; //导入方法依赖的package包/类
private void responseClient(Socket client) throws IOException {
    // 用于接收客户端消息
    BufferedReader in = new BufferedReader(new InputStreamReader(
            client.getInputStream()));
    // 用于向客户端发送消息
    PrintWriter out = new PrintWriter(new BufferedWriter(
            new OutputStreamWriter(client.getOutputStream())), true);
    out.println("欢迎来到聊天室!");
    while (!mIsServiceDestoryed) {
        String str = in.readLine();
        System.out.println("msg from client:" + str);
        if (str == null) {
            break;
        }
        int i = new Random().nextInt(mDefinedMessages.length);
        String msg = mDefinedMessages[i];
        out.println(msg);
        System.out.println("send :" + msg);
    }
    System.out.println("client quit.");
    // 关闭流
    MyUtils.close(out);
    MyUtils.close(in);
    client.close();
}
 
开发者ID:didi,项目名称:VirtualAPK,代码行数:26,代码来源:TCPServerService.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: runServer

import java.net.Socket; //导入方法依赖的package包/类
@Override
public void runServer(ServerSocket serverSocket) {
    try {
        while (true) {
            try {
                Socket socket = serverSocket.accept();
                DataOutputStream out = new DataOutputStream(socket.getOutputStream());
                StringBuilder builder = new StringBuilder();
                builder.append(response.getStatusLine().toString() + "\r\n");
                for (Header header : response.getAllHeaders()) {
                    builder.append(header.getName() + ":" + header.getValue() + "\r\n");
                }
                builder.append("\r\n");
                builder.append(content);
                System.out.println(builder.toString());
                out.writeBytes(builder.toString());
            } catch (SocketException se) {
            }
        }
    } catch (IOException e) {
        throw new RuntimeException("Error when waiting for new socket connection.", e);
    }
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:24,代码来源:MockServer.java

示例5: TimerClient

import java.net.Socket; //导入方法依赖的package包/类
public TimerClient(InetSocketAddress addr) throws IOException
{
	sock = new Socket();
	sock.connect(addr);
	in = new BufferedReader(new InputStreamReader(sock.getInputStream()));
	out = sock.getOutputStream();
	done = true;
}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:9,代码来源:TimerClient.java

示例6: initIncomingConnection

import java.net.Socket; //导入方法依赖的package包/类
/**
 * Initialize a new outgoing connection. 
 */
private void initIncomingConnection(Socket sock) throws IOException{
	server.log.log(Level.FINER, "Initializing connection with new server");
	
	PrintWriter pw = new PrintWriter(sock.getOutputStream());
	BufferedReader br = new BufferedReader(new InputStreamReader(sock.getInputStream()));
	
	// listen for INIT message from unknown server
	String msg = br.readLine();
	LamportMessage lm = LamportMessage.fromString(msg);
	
	// invalid message ... break connection
	if(lm==null || lm.type!=LamportMessageType.INIT_REQUEST){
		sock.close();
		return;
	}
	
	// get serverID
	int iServer = lm.serverID; 					
	
	if(lamportSockets[iServer] != null){
		server.log.log(Level.WARNING, "Imposter attempt from server ID "+ iServer);
		sock.close();
		return;
	}
					
	initConnectionCommon(sock, pw, br, iServer);

	// respond with current data
	// and current number of servers
	LamportMessage respond = LamportMessage.INIT_RESPOND(serverID, nServers, clock, server.getSerializedData());
	sendMessage(iServer, respond.toString());

}
 
开发者ID:ericaddison,项目名称:Dist_HW_2,代码行数:37,代码来源:LamportMutex.java

示例7: openSocket

import java.net.Socket; //导入方法依赖的package包/类
/**
 * open real socket and set time out when waitForAck is enabled
 * is socket open return directly
 */
protected void openSocket() throws IOException {
   if(isConnected()) return ;
   try {
       socket = new Socket();
       InetSocketAddress sockaddr = new InetSocketAddress(getAddress(), getPort());
       socket.connect(sockaddr,(int)getTimeout());
       socket.setSendBufferSize(getTxBufSize());
       socket.setReceiveBufferSize(getRxBufSize());
       socket.setSoTimeout( (int) getTimeout());
       socket.setTcpNoDelay(getTcpNoDelay());
       socket.setKeepAlive(getSoKeepAlive());
       socket.setReuseAddress(getSoReuseAddress());
       socket.setOOBInline(getOoBInline());
       socket.setSoLinger(getSoLingerOn(),getSoLingerTime());
       socket.setTrafficClass(getSoTrafficClass());
       setConnected(true);
       soOut = socket.getOutputStream();
       soIn  = socket.getInputStream();
       setRequestCount(0);
       setConnectTime(System.currentTimeMillis());
       if (log.isDebugEnabled())
           log.debug(sm.getString("IDataSender.openSocket", getAddress().getHostAddress(), Integer.valueOf(getPort()), Long.valueOf(0)));
  } catch (IOException ex1) {
      SenderState.getSenderState(getDestination()).setSuspect();
      if (log.isDebugEnabled())
          log.debug(sm.getString("IDataSender.openSocket.failure",getAddress().getHostAddress(), Integer.valueOf(getPort()), Long.valueOf(0)), ex1);
      throw (ex1);
    }
    
 }
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:35,代码来源:BioSender.java

示例8: connect

import java.net.Socket; //导入方法依赖的package包/类
private static String[] connect(String host, int port) {
    try {
        Socket socket = new Socket(host, port);
        socket.setSoTimeout(5000);

        DataOutputStream out = new DataOutputStream(socket.getOutputStream());
        DataInputStream in = new DataInputStream(socket.getInputStream());

        out.write(0xFE);

        int b;
        StringBuilder str = new StringBuilder();
        while ((b = in.read()) != -1) {
            if (b != 0 && b > 16 && b != 255 && b != 23 && b != 24) {
                str.append((char) b);
            }
        }

        String[] data = str.toString().split("§");
        return data;
    } catch (IOException ex) {
        if (!ex.getMessage().toLowerCase().contains("connection refused")) {
            ex.printStackTrace();
        }
    }

    String[] notOnline = {"error: not online", "0", "0"};
    return notOnline;
}
 
开发者ID:NexusByte,项目名称:LotusCloud,代码行数:30,代码来源:ProxyServer.java

示例9: SocketStream

import java.net.Socket; //导入方法依赖的package包/类
public SocketStream(Scheme scheme, String host, Integer port,
                    Preprocessor<String,Microblog> preprocessor) {
    setScheme(scheme);
    this.host = host;
    this.port = port;
    this.preprocessor = preprocessor;

    try {
        socket = new Socket(host, port);
        in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        out = new PrintWriter(socket.getOutputStream(), true);
    } catch (Exception e) {
    }
}
 
开发者ID:amrmagdy4,项目名称:kite,代码行数:15,代码来源:SocketStream.java

示例10: initialization

import java.net.Socket; //导入方法依赖的package包/类
public void initialization() {

        //Establish a connection with server, get number of active peers and their information.
        try {
            Thread t2 = new ReceiveServerRequest(this);
            t2.start();

            Socket serverConnection = new Socket(swAdr, swPort);
            serverConnection.setSoTimeout(Config.SERVER_TIMEOUT);

            DataInputStream in = new DataInputStream(serverConnection.getInputStream());

            receivePeerList(in);

            //Send itself data to server.
            DataOutputStream out = new DataOutputStream(serverConnection.getOutputStream());
            out.writeInt(heartBeatPort);
            out.writeInt(serverPort);
            out.writeUTF(Config.USER_NAME);
            out.writeUTF(Config.USER_PASS);
            out.flush();

            boolean authenticated = in.readBoolean();
            active = in.readBoolean();
            crypDist.setActive(active);
            int size = in.readInt();
            byte[] key_array = new byte[size];
            in.read(key_array);

            crypDist.setSessionKey(key_array);
            crypDist.setAuthenticated(authenticated);

            serverConnection.close();
        }
        catch(IOException e)
        {
            log.warn("Cannot connect to the server, terminated.");
            log.warn(e);
        }
    }
 
开发者ID:CrypDist,项目名称:CrypDist,代码行数:41,代码来源:Client.java

示例11: commandLoop

import java.net.Socket; //导入方法依赖的package包/类
void commandLoop(Socket socket) throws IOException {
    // in before out -- so we don't hang the controlling process
    ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
    OutputStream socketOut = socket.getOutputStream();
    System.setOut(new PrintStream(new MultiplexingOutputStream("out", socketOut), true));
    System.setErr(new PrintStream(new MultiplexingOutputStream("err", socketOut), true));
    ObjectOutputStream out = new ObjectOutputStream(new MultiplexingOutputStream("command", socketOut));
    while (true) {
        int cmd = in.readInt();
        performCommand(cmd, in, out);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:RemoteAgent.java

示例12: connectActually

import java.net.Socket; //导入方法依赖的package包/类
private void connectActually(){
    try {
        mSocket = new Socket(this.ip,this.port);
        mSocket.setTcpNoDelay(true);
        mSocket.setReuseAddress(true);
        mDataInputStream = new DataInputStream(mSocket.getInputStream());
        mDataOutputStream = new DataOutputStream(mSocket.getOutputStream());
    } catch (IOException e) {
        if(mTCPResultListener !=null){
            mTCPResultListener.onConnectFailed(e.getMessage());
        }

    }
}
 
开发者ID:zhenweiyu,项目名称:socket-client-server,代码行数:15,代码来源:TCPClient.java

示例13: sendEvent

import java.net.Socket; //导入方法依赖的package包/类
private void sendEvent(Socket socket, String content, String encoding) throws IOException {
  OutputStream output = socket.getOutputStream();
  IOUtils.write(content + IOUtils.LINE_SEPARATOR_UNIX, output, encoding);
  output.flush();
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:6,代码来源:TestNetcatSource.java

示例14: Client

import java.net.Socket; //导入方法依赖的package包/类
/**
 * 
 * @param socket socket per la comunicazione
 * @throws IOException lanciata quando si verifica un errore di input output
 */
public Client(Socket socket) throws IOException {
    this.daGiocatore = new BufferedReader(new InputStreamReader(socket.getInputStream()));
    this.aGiocatore = new PrintWriter(socket.getOutputStream(), true);
    this.socket = socket;

}
 
开发者ID:IngSW-unipv,项目名称:Progetto-A,代码行数:12,代码来源:Client.java

示例15: socks4aSocketConnection

import java.net.Socket; //导入方法依赖的package包/类
public static Socket socks4aSocketConnection(String networkHost, int networkPort, String socksHost, int socksPort)
        throws IOException {

    Socket socket = new Socket();
    socket.setSoTimeout(READ_TIMEOUT_MILLISECONDS);
    SocketAddress socksAddress = new InetSocketAddress(socksHost, socksPort);
    socket.connect(socksAddress, CONNECT_TIMEOUT_MILLISECONDS);

    DataOutputStream outputStream = new DataOutputStream(socket.getOutputStream());
    outputStream.write((byte) 0x04);
    outputStream.write((byte) 0x01);
    outputStream.writeShort((short) networkPort);
    outputStream.writeInt(0x01);
    outputStream.write((byte) 0x00);
    outputStream.write(networkHost.getBytes());
    outputStream.write((byte) 0x00);

    DataInputStream inputStream = new DataInputStream(socket.getInputStream());
    byte firstByte = inputStream.readByte();
    byte secondByte = inputStream.readByte();
    if (firstByte != (byte) 0x00 || secondByte != (byte) 0x5a) {
        socket.close();
        throw new IOException("SOCKS4a connect failed, got " + firstByte + " - " + secondByte +
                ", but expected 0x00 - 0x5a");
    }
    inputStream.readShort();
    inputStream.readInt();
    return socket;
}
 
开发者ID:PanagiotisDrakatos,项目名称:T0rlib4j,代码行数:30,代码来源:Utilities.java


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