Java Socket.getTrafficClass()
Syntax
Socket.getTrafficClass() has the following syntax.
public int getTrafficClass() throws SocketException
Example
In the following code shows how to use Socket.getTrafficClass() method.
//from w ww . j av a2 s. co m
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
public class Main {
public static void main(String args[]) throws Exception {
Socket s = new Socket("internic.net", 43);
InputStream in = s.getInputStream();
OutputStream out = s.getOutputStream();
String str = "asdfasdfasdf\n";
byte buf[] = str.getBytes();
out.write(buf);
int c;
while ((c = in.read()) != -1) {
System.out.print((char) c);
}
s.setTrafficClass(1);
System.out.println(s.getTrafficClass());
s.close();
}
}