Discord Flashcards
InputStreamReader
- Bridge from byte streams to char streams
- Reads bytes and decodes them into characters using the specified charset
- Should always be wrapped in a BufferedReader
what does the server socket do?
listens for connections on the specified port
new ServerSocket(port);
how does a ServerSocket accept a connection from a client Socket?
Socket clientSocket = serverSocket.accept()
PrintWriter
wraps an output stream
new PrintWriter(outputStream)
automatic line flushing
can’t write raw bytes
What 5 things do you need to implement a ChatServer?
- ServerSocket
- Socket clientSocket
- BufferedReader in
- PrintWriter out
- Scanner to read from keyboard
Runnable
A class that implements Runnable can run without subclassing Thread by instantiating a Thread instance and passing itself in as the target.
what does scanner take as a param?
System.in
checklist
start threads
close sockets
update loop variables
difference between streams and readers
stream work with binary data and readers work with characters
DataInputStream
read primitive java data types in machine-independent way