CSMA CD Program1
CSMA CD Program1
AIM: To study and implement the Carrier Sense Multiple Access with Collision Detection
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:
CLIENT:
1. Open socket with input address, port
2. Initialize output stream
3. Send the message, if message sent collision not occurred.
4. If message not sent, collision occurred (To occur collision don’t run not server)
5. Calculate back of time using random number selection and wait for that time
6. Again send the message, if message sent collision not occurred.
7. If message not sent, collision occurred, Again calculate back off time by selecting random
number, this trail can be done for 15 times.
8. If not succeeded with 15 trails transmission will be stopped.
//CSMA/CD PROGRAM
//CLEINT:(Sender side)
import java.io.*;
import java.net.*;
try
int Tp = 2000;
int R = 0;
int Tb = 0;
System.out.println("attempt : "+i);
if(cli.send() == "sent")
break;
else
R = 2^i-1;
System.out.println("Selected Random number :"+R);
Tb = R*Tp;
System.out.println("waiting for next attempt with back time (in seconds): "+Tb);
Thread.sleep(Tb);
catch (InterruptedException e)
System.out.println(e);
String send()
String str=null;
try
out.writeObject(msg);
str = "sent";
}
catch(Exception e)
return str;
//CSMA/CD PROGRAM
//SERVER:
import java.io.*;
import java.net.*;
try
System.out.println("Connected");
in.close();
ss.close();
catch(Exception e)
System.out.println(e);
Output: