.getInputStream() 有问题
Having problems with .getInputStream()
我正在尝试编写 TCP 聊天服务器程序,但在使用 .getInputStream() 和 .getOutputStream() 方法时遇到困难,编译器显示“找不到符号方法 .getInputStream()。
这是我的代码,我还没有取得太大进展:
import java.net.*;
import java.io.*;
public class Server {
public static void Server (String[] args) {
ServerSocket SS1 = null;
DataOutputStream DOS1 = null;
DataInputStream DIS1 = null; //Setting the values to null
try {
SS1 = new ServerSocket(5000); //setting the socket SS1 to port 5000 and creating an instance
Socket clientSocket = SS1.accept(); //accepting the connection request
DOS1 = new DataOutputStream(SS1.getOutputStream());
DIS1 = new DataInputStream(SS1.getInputStream()); //creating output and input streams
}
catch (Exception e){
System.err.println("Error!");
}
}
}
我在 Windows 7 上使用 BlueJ,如果这是问题所在。
另外,我似乎找不到关于数据流或 "old-school" 套接字如何工作的很好的解释,所以如果有人知道我可以从哪里得到这些,将不胜感激。 :)
~阿隆.
您必须致电:
clientSocket.getOutputStream()
clientSocket.getInputStream()
在你的 DataOutput-/DataInputStream 构造函数中。
您错误地使用了 Socket
(连接到服务器的客户端)
内部的 ServerSocket
试试这个:
clientSocket.getOutputStream()
clientSocket.getInputStream()
我正在尝试编写 TCP 聊天服务器程序,但在使用 .getInputStream() 和 .getOutputStream() 方法时遇到困难,编译器显示“找不到符号方法 .getInputStream()。 这是我的代码,我还没有取得太大进展:
import java.net.*;
import java.io.*;
public class Server {
public static void Server (String[] args) {
ServerSocket SS1 = null;
DataOutputStream DOS1 = null;
DataInputStream DIS1 = null; //Setting the values to null
try {
SS1 = new ServerSocket(5000); //setting the socket SS1 to port 5000 and creating an instance
Socket clientSocket = SS1.accept(); //accepting the connection request
DOS1 = new DataOutputStream(SS1.getOutputStream());
DIS1 = new DataInputStream(SS1.getInputStream()); //creating output and input streams
}
catch (Exception e){
System.err.println("Error!");
}
}
}
我在 Windows 7 上使用 BlueJ,如果这是问题所在。 另外,我似乎找不到关于数据流或 "old-school" 套接字如何工作的很好的解释,所以如果有人知道我可以从哪里得到这些,将不胜感激。 :)
~阿隆.
您必须致电:
clientSocket.getOutputStream()
clientSocket.getInputStream()
在你的 DataOutput-/DataInputStream 构造函数中。
您错误地使用了 Socket
(连接到服务器的客户端)
ServerSocket
试试这个:
clientSocket.getOutputStream()
clientSocket.getInputStream()