Java DatagramSocket .setTrafficClass (int tc)

Syntax

DatagramSocket.setTrafficClass(int tc) has the following syntax.

public void setTrafficClass(int tc)   throws SocketException

Example

In the following code shows how to use DatagramSocket.setTrafficClass(int tc) method.


import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
/* w w w.jav a2  s .  co  m*/
public class Main {

  public static void main(String args[]) {
    try {

      InetAddress ia = InetAddress.getByName("www.java2s.com");

      DatagramSocket ds = new DatagramSocket();

      byte buffer[] = "hello".getBytes();
      DatagramPacket dp = new DatagramPacket(buffer, buffer.length, ia, 80);
      ds.setTrafficClass(1);
      ds.send(dp);
      
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
} 




















Home »
  Java Tutorial »
    java.net »




CookieManager
CookiePolicy
CookieStore
DatagramPacket
DatagramSocket
HttpCookie
HttpURLConnection
InetAddress
JarURLConnection
MulticastSocket
ServerSocket
Socket
SocketAddress
URI
URL
URLConnection
URLDecoder
URLEncoder