I am trying to program a TCP chat server, but am having difficulties with the .getInputStream() and .getOutputStream() methods, the compiler says it "Cannot find symbol- method .getInputStream(). Here is my code, I have not progressed very far yet:
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!");
}
}
}
I am using BlueJ on Windows 7, if that's the problem. Also, I am can't seem to find good explanations about how data streams or "old-school" sockets work, so if anyone knows where I can get those, it'd be very much appreciated. :)
~Alon.
You have to call:
clientSocket.getOutputStream()
clientSocket.getInputStream()
inside your DataOutput-/DataInputStream constructors.