Carrier Sense Multiple Access With Collision Detection AIM: To Write A Program To Implement The CSMA/CD Using Java. Principle
Carrier Sense Multiple Access With Collision Detection AIM: To Write A Program To Implement The CSMA/CD Using Java. Principle
Carrier Sense Multiple Access With Collision Detection AIM: To Write A Program To Implement The CSMA/CD Using Java. Principle
PRINCIPLE:
The Carrier Sense Multiple Access is based on the principle of “SENSE BEFORE TRANSMIT”. This
CSMA/CD is generally used in wired networks. It is mainly focused to detect the collision if it has occurred.
ALGORITHM:SERVER:
1. Start the program.
2. Initialize server socket.
3. Display waiting for connection.
4. Initialize the socket and accept the client message.
5. Display connected with client.
6. Initialize i/p stream.
7. Read message.
8. Display message from client.
9. Close all objects.
10. Stop the program.
CLIENT:
1. Start the program.
2. Open socket with input address ,port
3. Initialize o/p stream
4. Send the message, if message sent collision not occurred.
5. If message not sent, collision occurred (To occur collision don’t run not server)
6. Calculate back of time using random number selection and wait for that time
7. Again send the message, if message sent collision not occurred.
8. If message not sent, collision occurred, Again calculate back off time by selecting random number,
this trail can be done for 15 times.
9. If not succeeded with 15 trails transmission will be stopped.
10. Stop the program.
PROGRAM:
//CSMA/CD PROGRAM - SERVER:
import java.io.*;
import java.net.*;
public class server
{
public static void main(String[] args)
{
try
{
System.out.println("============ Client 2 ==============");
ServerSocket ss = new ServerSocket(137);
System.out.println("Waiting for connection");
Socket con = ss.accept();
System.out.println("Connected");
ObjectInputStream in = new ObjectInputStream(con.getInputStream());
System.out.println((String)in.readObject());
in.close();
ss.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
OUTPUT:CLIENT
D:\jdk1.6.0\bin>javac client1.java
D:\jdk1.6.0\bin>java client1
============ Client 1 ===============
attempt : 1
Message sent : null
Selected Random number :2
waiting for next attempt with back time (in seconds): 4000
attempt : 2
Message sent : null
Selected Random number :3
waiting for next attempt with back time (in seconds): 6000
attempt : 3
Message sent : null
Selected Random number :0
waiting for next attempt with back time (in seconds): 0
attempt : 4
Message sent : null
Selected Random number :1
waiting for next attempt with back time (in seconds): 2000
attempt : 5
Message sent : null
Selected Random number :6
waiting for next attempt with back time (in seconds): 12000
attempt : 6
Message sent : CNLAB
D:\jdk1.6.0\bin>
SERVER:
D:\jdk1.6.0\bin>javac server.java
D:\jdk1.6.0\bin>java server
============ Client 2 ===============
Waiting for connection
Connected
CNLAB
D:\jdk1.6.0\bin>
RESULT:
Thus the above program to implement the CSMA/CD using java has been performed, verified and executed
successfully.