0% found this document useful (0 votes)
20 views4 pages

CN Algorithm

Uploaded by

mr.dhanush.j
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views4 pages

CN Algorithm

Uploaded by

mr.dhanush.j
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

SNMP APPLICATION USING UDP

SNMPServer Algorithm

1. Initialize Server:
a. Create a DatagramSocket on port 8086 (SNMP typically uses UDP).
2. Server Ready:
a. Display a message indicating that the SNMP Server is running.
3. Main Loop (Continuous Listening):
a. Continuously wait for incoming SNMP requests.
4. Receive Request:
a. Create a DatagramPacket to hold incoming data.
b. Receive data from the client and store it in the packet.
c. Convert the received data into a string format (interpreted as an SNMP
request).
5. Print Request:
a. Display the received SNMP request.
6. Prepare Response:
a. Create a response message that includes the original request.
b. Convert the response message to bytes.
7. Send Response:
a. Retrieve the client’s IP address and port from the received packet.
b. Create a new DatagramPacket for the response data.
c. Send the response packet back to the client.
8. Repeat:
a. Go back to the listening state and wait for the next incoming request.

SNMPClient Algorithm

1. Initialize Client:
a. Set up a reader to take input from the user.
b. Create a DatagramSocket for sending and receiving data.
c. Set the server’s IP address and port (use "localhost" and port 8086 in this
case).
2. Get User Input:
a. Prompt the user to enter an SNMP request.
b. Read the request string from the user.
3. Send Request:
a. Convert the request string into bytes.
b. Create a DatagramPacket with the request data, targeting the server’s IP
and port.
c. Send the packet to the server.
4. Receive Response:
a. Prepare a DatagramPacket to receive the server’s response.
b. Wait and receive the response packet from the server.
5. Print Response:
a. Convert the received data into a string format.
b. Display the received SNMP response.
6. Close Socket:
a. Close the socket to end the client session.

PING APPLICATION USING RAW SOCKET

Algorithm for PingServer:

1. Initialize Server Socket:


a. Create a DatagramSocket object to listen on port 1234.
b. Initialize a byte array buffer (receiveBuffer) to store incoming data.
2. Listen for Client Requests:
a. Enter an infinite loop to continually listen for client pings.
3. Receive Data from Client:
a. Create a DatagramPacket object to hold the incoming packet data.
b. Use the receive() method on the socket to wait for data from the client.
c. Convert the received data to a string and print it to confirm reception.
4. Send Response to Client:
a. Retrieve the client’s IP address and port from the received packet.
b. Prepare a "Pong" response message.
c. Create a new DatagramPacket containing the response data, targeting
the client’s IP address and port.
d. Use the send() method on the socket to send the response back to the
client.
e. Print a confirmation message.
5. Error Handling:
a. If any exception occurs, print the stack trace.

Algorithm for PingClient:

1. Initialize Client Socket:


a. Create a DatagramSocket object for sending data.
b. Define the server’s IP address (localhost) and port (1234).
2. Send "Ping" Request:
a. Prepare a "Ping" message and convert it to bytes.
b. Create a DatagramPacket with the "Ping" data, targeting the server’s IP
and port.
c. Use the send() method on the socket to send the packet to the server.
d. Print a message confirming that the ping was sent.
3. Wait for Server Response:
a. Prepare a byte array buffer (receiveBuffer) to receive the response.
b. Create a DatagramPacket object to hold the incoming data.
c. Use the receive() method on the socket to wait for the response from
the server.
4. Display Server Response:
a. Convert the received data to a string (expected to be "Pong") and print it.
5. Error Handling:
a. If any exception occurs, print the stack trace.

TRACE ROUTE APPLICATION USINIG RAW SOCKET

TraceRouteServer Algorithm

1. Initialize Server:
a. Bind a DatagramSocket to port 33434 to listen for incoming UDP
packets.
2. Listen for Packets:
a. Start a loop to continuously listen for packets.
3. Receive Packet:
a. Allocate a buffer and receive a packet from a client.
b. Extract the client’s message, IP address, and port number.
4. Respond to Client:
a. Prepare a response message with the server’s IP address.
b. Send this response packet back to the client.
5. Repeat:
a. Continue listening and responding to new packets.

TraceRouteClient Algorithm

1. Initialize Client:
a. Define the server address (localhost in this case) and the destination
port (33434).
b. Set maxHops to the desired maximum number of hops (e.g., 30).
2. Tracing Route:
a. Loop through each TTL value from 1 to maxHops.
3. Create and Send Packet:
a. Set up a new DatagramSocket with a 3-second timeout.
b. Set the packet’s TTL to the current hop count.
c. Record the start time and send the packet to the server.
4. Receive Response or Timeout:
a. Try to receive a response packet from the server.
b. If successful, calculate the round-trip time (RTT) and display the router
address and RTT for the current hop.
c. If the response IP matches the server IP, print "Reached destination" and
exit the loop.
d. If a timeout occurs, indicate that the request timed out.
5. Close Socket and Repeat:
a. Close the socket and move to the next hop until reaching the destination
or the maximum hops limit.

You might also like