use of java.net.Socket in project CoreNLP by stanfordnlp.
the class LexicalizedParserClient method getLemmas.
/**
* Get the lemmas for the text according to the parser's lemmatizer
* (only applies to English), return it as whitespace tokenized text.
*/
public String getLemmas(String query) throws IOException {
Socket socket = new Socket(host, port);
Writer out = new OutputStreamWriter(socket.getOutputStream(), "utf-8");
out.write("lemma " + query + "\n");
out.flush();
String result = readResult(socket);
socket.close();
return result;
}
use of java.net.Socket in project CoreNLP by stanfordnlp.
the class LexicalizedParserClient method getParse.
/**
* Returns the String output of the parse of the given query.
* <br>
* The "parse" method in the server is mostly useful for clients
* using a language other than Java who don't want to import or wrap
* Tree in any way. However, it is useful to provide getParse to
* test that functionality in the server.
*/
public String getParse(String query, boolean binarized) throws IOException {
Socket socket = new Socket(host, port);
Writer out = new OutputStreamWriter(socket.getOutputStream(), "utf-8");
out.write("parse" + (binarized ? ":binarized " : " ") + query + "\n");
out.flush();
String result = readResult(socket);
socket.close();
return result;
}
use of java.net.Socket in project okhttp by square.
the class Http2Server method run.
private void run() throws Exception {
ServerSocket serverSocket = new ServerSocket(8888);
serverSocket.setReuseAddress(true);
while (true) {
Socket socket = null;
try {
socket = serverSocket.accept();
SSLSocket sslSocket = doSsl(socket);
String protocolString = Platform.get().getSelectedProtocol(sslSocket);
Protocol protocol = protocolString != null ? Protocol.get(protocolString) : null;
if (protocol != Protocol.HTTP_2) {
throw new ProtocolException("Protocol " + protocol + " unsupported");
}
Http2Connection connection = new Http2Connection.Builder(false).socket(sslSocket).listener(this).build();
connection.start();
} catch (IOException e) {
logger.log(Level.INFO, "Http2Server connection failure: " + e);
Util.closeQuietly(socket);
} catch (Exception e) {
logger.log(Level.WARNING, "Http2Server unexpected failure", e);
Util.closeQuietly(socket);
}
}
}
use of java.net.Socket in project okhttp by square.
the class DisconnectTest method setUp.
@Before
public void setUp() throws Exception {
// Sockets on some platforms can have large buffers that mean writes do not block when
// required. These socket factories explicitly set the buffer sizes on sockets created.
server = new MockWebServer();
server.setServerSocketFactory(new DelegatingServerSocketFactory(ServerSocketFactory.getDefault()) {
@Override
protected ServerSocket configureServerSocket(ServerSocket serverSocket) throws IOException {
serverSocket.setReceiveBufferSize(SOCKET_BUFFER_SIZE);
return serverSocket;
}
});
client = defaultClient().newBuilder().socketFactory(new DelegatingSocketFactory(SocketFactory.getDefault()) {
@Override
protected Socket configureSocket(Socket socket) throws IOException {
socket.setSendBufferSize(SOCKET_BUFFER_SIZE);
socket.setReceiveBufferSize(SOCKET_BUFFER_SIZE);
return socket;
}
}).build();
}
use of java.net.Socket in project okhttp by square.
the class URLConnectionTest method writeTimeouts.
/** Confirm that an unacknowledged write times out. */
@Test
public void writeTimeouts() throws IOException {
MockWebServer server = new MockWebServer();
// Sockets on some platforms can have large buffers that mean writes do not block when
// required. These socket factories explicitly set the buffer sizes on sockets created.
final int SOCKET_BUFFER_SIZE = 4 * 1024;
server.setServerSocketFactory(new DelegatingServerSocketFactory(ServerSocketFactory.getDefault()) {
@Override
protected ServerSocket configureServerSocket(ServerSocket serverSocket) throws IOException {
serverSocket.setReceiveBufferSize(SOCKET_BUFFER_SIZE);
return serverSocket;
}
});
urlFactory.setClient(urlFactory.client().newBuilder().socketFactory(new DelegatingSocketFactory(SocketFactory.getDefault()) {
@Override
protected Socket configureSocket(Socket socket) throws IOException {
socket.setReceiveBufferSize(SOCKET_BUFFER_SIZE);
socket.setSendBufferSize(SOCKET_BUFFER_SIZE);
return socket;
}
}).writeTimeout(500, TimeUnit.MILLISECONDS).build());
server.start();
server.enqueue(new MockResponse().throttleBody(1, 1, // Prevent the server from reading!
TimeUnit.SECONDS));
connection = urlFactory.open(server.url("/").url());
connection.setDoOutput(true);
connection.setChunkedStreamingMode(0);
OutputStream out = connection.getOutputStream();
try {
// 2 MiB.
byte[] data = new byte[2 * 1024 * 1024];
out.write(data);
fail();
} catch (SocketTimeoutException expected) {
}
}
Aggregations