本文整理匯總了Java中java.net.Socket.shutdownInput方法的典型用法代碼示例。如果您正苦於以下問題:Java Socket.shutdownInput方法的具體用法?Java Socket.shutdownInput怎麽用?Java Socket.shutdownInput使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.net.Socket
的用法示例。
在下文中一共展示了Socket.shutdownInput方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: test
import java.net.Socket; //導入方法依賴的package包/類
public static void test(Socket s1, Socket s2, String mesg) throws Exception {
OutputStream os = s1.getOutputStream();
os.write("This is a message".getBytes("US-ASCII"));
InputStream in = s2.getInputStream();
s2.shutdownInput();
if (in.available() != 0) {
failed = true;
System.out.println(mesg + ":" + s2 + " in.available() should be 0, " +
"but returns "+ in.available());
}
byte[] ba = new byte[2];
if (in.read() != -1 ||
in.read(ba) != -1 ||
in.read(ba, 0, ba.length) != -1) {
failed = true;
System.out.append(mesg + ":" + s2 + " in.read() should be -1");
}
}
示例2: runServer
import java.net.Socket; //導入方法依賴的package包/類
/**
* Method to run in a thread to accept requests coming
* in over TCP and put them in a queue.
*/
private static void runServer() {
try (ServerSocket ss = new ServerSocket(port)) {
if (verbosity > 1)
System.out.println("Server listening on port " + port);
while (true) {
Socket s = ss.accept();
if (verbosity > 1)
System.out.println("Connection established.");
boolean status = false;
if (requestQueue.size() < maxQueue) {
status = requestQueue.offer(new FuzzRequest(s));
if (verbosity > 1)
System.out.println("Request added to queue: " + status);
}
if (!status) {
if (verbosity > 1)
System.out.println("Queue full.");
OutputStream os = s.getOutputStream();
os.write(STATUS_QUEUE_FULL);
os.flush();
s.shutdownOutput();
s.shutdownInput();
s.close();
if (verbosity > 1)
System.out.println("Connection closed.");
}
}
} catch (BindException be) {
System.err.println("Unable to bind to port " + port);
System.exit(1);
} catch (Exception e) {
System.err.println("Exception in request server");
e.printStackTrace();
System.exit(1);
}
}
示例3: shutdownInput
import java.net.Socket; //導入方法依賴的package包/類
private static void shutdownInput(Socket socket) {
if (socket != null && !socket.isInputShutdown()) {
try {
LoggerFactory.getLogger().info("關閉Socket輸入...");
socket.shutdownInput();
} catch (IOException e) {
LoggerFactory.getLogger().error("關閉Socket輸入異常", e);
}
}
}