Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Go Back N Arq Implementation Using Java


  • Please log in to reply
2 replies to this topic

#1 stargazerboi

stargazerboi

  • Members
  • 1 posts
  • OFFLINE
  •  
  • Local time:10:53 PM

Posted 30 June 2007 - 03:28 AM

hello guys..
so far i've managed to build a skeleton...now it seems i'm badly in need of some flesh..

overview:
I've written separate sender and reciever portions...the sender portion goes like this:



import java.io.*;
import java.net.*;

public class SendGBN{
//constants
public static byte N = 10; //the N from "Go-Back-N"
public static byte MAX_SEQ_NUMBER = 20; //The maximum sequence number
public static int PORT = 7609; //the receiver's port
public static int DELAY = 1000; //1 second delay for timeout

//the socket
DatagramSocket socket;
//the ip address of the receiver
InetAddress ipAddress;

//variables from the algorithm
byte base = 1;
byte nextSeqNum = 1;

//needed for receiver thread
volatile boolean done = false;

//number of packets sent, but unacknowledged
int unAckedPackets = 0;

//////////////////////////////
//
// other instance variables
//

//main program
//hostname can be included on the command line
//if not, assume the receiver is listening on this machine
public static void main(String[] args) throws IOException{
InetAddress ipAddress = null;
if(args.length > 0){
//get specified host
ipAddress = InetAddress.getByName(args[0]);
}
else{
//use default local host
ipAddress = InetAddress.getByName("localhost"); //loopback
}
//create a new sender
SendGBN sender = new SendGBN(ipAddress);

//start processing the user's data
sender.processUserData();
}

//constructor
public SendGBN(InetAddress ip) throws IOException{
ipAddress = ip;

socket = new DatagramSocket();

//create receiver thread
ACKListener rcv = new ACKListener();

//start the thread
rcv.start();

/////////////////////////////
//
// other initialization
//
}

//deals with getting the data from the user to send
public void processUserData() throws IOException{
//create input reading mechanism
BufferedReader in =
new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter some text, to end place a . on a line alone.");

String line = null;
while((line = in.readLine()) != null && !(line.equals("."))){
//send one packet per character
for(int i = 0; i < line.length(); i++){
char c = line.charAt(i);
//wait until the queue is no longer full
while(unAckedPackets == N){
//we can do this because we will be running other threads
//we'll give them a chance to run
Thread.yield();
}
sendPacket©;
}

///////////////////////////////////////////
//
// wait until the queue is no longer full
// send an end of line character
//
}
done = true;
socket.close();
System.out.println("Done!");
}

/*
* The following three methods
* are defined as synchronized so that only one can be active
* at a time from any given thread (main thread, ackListener or timer.
*
*/

public synchronized void sendPacket(char c) throws IOException{
///////////////////////////////////////////
//
// Turn the char c into a packet and send it off.(how!?)
//
// Called from processUserData().
//
//
//
}

public synchronized void receivePacket(DatagramPacket ack){
///////////////////////////////////////////
//
// Process a received packet(how!?)
// Called from the ACKListener thread
//
//
//
}

public synchronized void timeOut(){
///////////////////////////////////////////
//
// Process a message from the timer. (how?)
// Called from the timer.
//
//
//
}


class ACKListener extends Thread{
public void run(){
try{
while(!done){
//listen for packet
DatagramPacket ack = null;

///////////////////////////////////////////
//
// Get an incoming ACK packet
//

//process it
receivePacket(ack);
}
}
catch(IOException ioe){
//Will enter here if the thread is listening for a packet
//when we quit, and that's ok.
}

}
}
}



where I need help is mainly the sendPacket(),recievepacket() and timeOut() methods...
can anybody correct and complete the code?...it would be a great help !..=)

BC AdBot (Login to Remove)

 


m

#2 siriusexperiment

siriusexperiment

  • Members
  • 1 posts
  • OFFLINE
  •  
  • Local time:09:53 PM

Posted 18 April 2011 - 10:22 PM

Did you ever finish this project? I realize it was many years ago now... I would appreciate your help if possible. I am trying to implement the same algorithm in Java.

#3 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:09:53 PM

Posted 19 April 2011 - 06:23 AM

We don't help with homework; we will help you correct errors, and help with implementation issues. If you would like help, start your own thread and show us what you have done. The above poster didn't get help because he didn't even try. Anyone can come up with a bunch of methods signatures; that doesn't show effort at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users