0
我有這樣的代碼:什麼Socket.getInputStream()。read()方法會在java中做什麼?
class ConnectionHandler implements Runnable {
private Socket socket;
private InputStream is;
private OutputStream os;
private Packetizer packetizer;
boolean closed = true;
public ConnectionHandler(Socket socket, ProtocolHandler ph) {
this.socket = socket;
try {
is = socket.getInputStream();
os = socket.getOutputStream();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Thread t = new Thread(this);
t.start();
//log.debug("ConnectionHandler const done");
}
public void run() {
try
{
//
// Read a message sent by client application
//
closed = false;
while (!closed)
{
if (is.available() > 0)
{
byte c = (byte) (0xff & is.read());
//log.debug("r " + c);
} else {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
}
}
}
is.close();
os.close();
socket.close();
} catch (IOException e) {
}
}
我的問題是什麼用的這 - >字節C =(字節)(0xFF的& is.read());
請讓我知道您的想法。
請幫我一把。提前致謝。
謝謝喬恩: ) –