skip to main | skip to sidebar

Java Programs and Examples with Output

Pages

▼
 
  • RSS
  • Twitter
Wednesday, October 17, 2012

Java Token Ring Application

Posted by Raju Gupta at 6:00 AM – 0 comments
 

Token ring local area network (LAN) technology is a protocol which resides at the data link layer (DLL) of the OSI model. It uses a special three-byte frame called a token that travels around the ring. Token-possession grants the possessor permission to transmit on the medium. Token ring frames travel completely around the loop.
This is a simple Java program that illustrates the working of a token ring.

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import java.io.*;
import java.lang.*;
 
class Tring {
 public static void main(String args[]) throws Throwable {
  DataInputStream dis = new DataInputStream(System.in);
  System.out.println("Enter the num of nodes:");
  int n = Integer.parseInt(dis.readLine());
  // Decides the number of nodes forming the ring
  int token = 0;
  int ch = 1;
  for (int i = 0; i < n; i++)
   System.out.print(" " + i);
  System.out.println(" " + 0);
  try {
   while (ch == 1) {
    System.out.println("Enter sender:");
    int s = Integer.parseInt(dis.readLine());
    System.out.println("Enter receiver:");
    int r = Integer.parseInt(dis.readLine());
    System.out.println("Enter Data:");
    String d = dis.readLine();
    System.out.print("Token passing:");
    for (int i = token; i != s; i++)
     System.out.print(" " + i + "->");
    System.out.println(" " + s);
    System.out.println("Sender " + s + "sending data: " + d);
    for (int i = s + 1; i != r; i = (i + 1) % n)
     System.out.println("data  " + d + " forwarded by " + i);
    System.out.println("Receiver " + r + "received data: " + d);
    token = s;
 
   }
  } catch (Exception e) {
  }
 }
}

Labels: Java Network Example

Leave a Reply

Newer Post Older Post
Subscribe to: Post Comments ( Atom )
  • Popular
  • Recent
  • Archives
Powered by Blogger.
 
 
 
© 2011 Java Programs and Examples with Output | Designs by Web2feel & Fab Themes

Bloggerized by DheTemplate.com - Main Blogger