Errorsimulator

Errorsimulator - /* * @(#)Errorsimulator.java * * * @author...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
/** * @(#)Errorsimulator.java * * * @author * @version 1.00 2009/8/2 */ import java.io.*; import java.net.*; import java.util.*; public class Errorsimulator implements Runnable { p DatagramPacket receivePacket,sendPacket,tempPacket, wrongPacket; DatagramSocket listningSocket,sendingSocket,unknownSocket; BufferedReader errorChoice,packetType,errorBlock,theTID, theRequest; private int count = 3; private boolean wrongTid = false; private boolean wrongRequest = false; byte [] bufError; String receivedOpcode ,changedOpcode; S //these are the string for error that is requested //containing type of error,type of packet and block No String error,dataAck,blockNo, packetData,TID, RequestE; S int serverPort, changedPort; int delay,clientPort; InetAddress clientAddress,serverAddress; // this array will contain the message from received packet byte request [] = new byte [512]; byte [] ACK ; //constructore creates sockets public Errorsimulator(){ //receives the packets try{ listningSocket = new DatagramSocket(68); }catch(SocketException e){ System.err.println(e); } //sends packets try{ sendingSocket = new DatagramSocket(); }catch(SocketException e){ System.err.println(e); S } //this is for sending packets from unknown source try{ unknownSocket = new DatagramSocket(); }catch(SocketException e){ System.err.println(e); } } public void run(){ p //get instruction for error
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
checkRequest(); //packet created receivePacket = new DatagramPacket(request,request.length); r //receiveing socket try{ listningSocket.receive(receivePacket); }catch(IOException e){ System.out.println(e); S } System.out.println("received packet from client"); S //extract data from packet request = receivePacket.getData(); //change bytes to string String received = new String(request); //get the first two bytes that contain opcode receivedOpcode = new String(received.substring(0,2)); clientPort = receivePacket.getPort(); clientAddress = receivePacket.getAddress(); if(receivedOpcode.equalsIgnoreCase("01")){ System.out.println("The opcode is "+receivedOpcode); System.out.println("This is RRQ"); }else if(receivedOpcode.equalsIgnoreCase("02")){ System.out.println("The opcode is "+receivedOpcode);
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 7

Errorsimulator - /* * @(#)Errorsimulator.java * * * @author...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online