如何使用getOutputStream方法发送strin.它只能发送他们提到的字节.到目前为止,我可以发送一个字节.但不是字符串值.
public void sendToPort() throws IOException {
Socket socket = null;
try {
socket = new Socket("ip address", 4014);
socket.getOutputStream().write(2); // have to insert the string
} catch (UnknownHostException e) {
System.err.print(e);
} finally {
socket.close();
}
}
Run Code Online (Sandbox Code Playgroud)
提前致谢