0
我想以字節爲單位向java中的套接字服務器寫入字符串,然後接收答案(已知長度的字節)。在java中寫入python套接字服務器
我看了看周圍,有很多教程,但我似乎無法找到一個特定的函數來處理字節,並且,我似乎無法執行功能。這保持紅色下劃線。
import java.io.*;
import java.net.Socket;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
public class SocketTest {
public static void main(String [] args) throws IOException {
String hostName = "localhost";
int portNumber = 10000;
try (
//open a socket
Socket clientSocket = new Socket(hostName, portNumber);
BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
) {
System.out.print("Something went wrong");
}
}
try {
out.XXX; //can't seem to execute any function on this.
} catch (Exception e) {
e.printStackTrace();
}
非常感謝!嘗試錯誤的使用會讓錯誤檢查器混淆。我會嘗試作家的挑戰。 – dorien 2014-12-02 23:41:58