John Cebedo

Greenhorn
+ Follow
since Sep 23, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by John Cebedo


Yes, instead of sleeping, do a timed wait on an object. When an ack is received (I assume there will be a different thread that receives ack by listening on a socket), just notify the object that the server is waiting on.



I googled some tutorials concerning wait(), notify(), and notifyall() but I am still not sure how to use these with my programs. The tutorials seem to be more interested in synchronizing methods or blocks of code so that only one thread can manipulate that method or block of code. What do you mean by "timed wait on an object"?

I created a thread whose sole responsibility is to wait for ACK and wake up the sleeping server when that ACK arrives. But I am still ignorant on how to awaken the sleeping server. I went over the Thread API but there aren't any methods that I can use like threadName.awaken() or Thread.awaken(threadName) something similar.
This new problem spawned from my previous topic (https://coderanch.com/t/409993/java/java/Serialization-IOException-writeObject) about a Serialization problem with my networking project.

To summarize: My networking project is composed of two programs, a Server and a Client. Client requests a file to Server. If the file is available, Server sends packets (represented by an instance of a class I made called Frame) containing fragments of the file to Client and Client responds with an acknowledgment (ACK) for each packet. If the Server does not receive an ACK for a packet, that packet is retransmitted. The project should also be flexible enough to implement a sliding-window protocol (hence the use of threads).

Here is my implementation: I created a class called SendFrame which extends Thread. This class is responsible for transmitting and/or retransmitting (if ACK is not received) a Frame object (packet). The code inside the run() method is quite simple. The main idea is to keep retransmitting the packet until ACK is received. Pseudocode inside run() looks like this:




The server pseudocode looks like this:



simple pseudocode for Client:



My question: When Client receives a packet, is there a way for Client to awaken the sleeping Server so that it can receive the ACK? Also, I think my implementation feels awkward. Any tips or suggestions on making it better?
Code involving the BufferedReader:



My entire algorithm attempting to simulate the Stop-and-Wait scheme:



EDIT: added comments in the code explaining how I'm sending the frames
[ April 08, 2008: Message edited by: John Cebedo ]
15 years ago
Since it is now a socket problem, here are the lines of code involving ObjectOutputStream:







And here is the SendFrame class:

15 years ago
Oops, I didn't copy the stack trace correctly. It should look like this:



After adding the line

inside the catch block, I get this additional stack trace:

15 years ago
Here is the stack trace:



Here is my Frame class:

15 years ago
Hi, I am in the middle of a networking project. The project is a pair of programs: a Server and a Client. The Client will ask the Server for some file and the Server will try to send the requested file to the Client.

My problem is that I keep getting an IOException when trying to use the ObjectOutputStream's writeObject() method. This happens when I am trying to send packets to the Client. In my project, a packet is represented by an instance of a class I made called Frame which implements Serializable.

This simple block of code generates the error:



Any hints on what I am doing wrong?
15 years ago
sorry for the bad formatting above...

17 years ago
your code confused me, why do you have the BadStyle class?

why not simply do:


public class MyNumbers {
private double[] a;

public MyNumbers(int x) {
a = new double[x];
for (int i = 0; i < a.length; i++)
a[i] = Math.random();
}

public void showMe() {...}
}

so then if you want an array of 100 numbers, you go:
MyNumbers n = new MyNumbers(100);
n.showMe();
17 years ago
ah, yes! thank you!

it works now. by overriding the xyz() for each of the subclasses above class D and having each of them call the xyz() of a child class, i can now call class D's xyz() through class B's xyz().
17 years ago
the following code generates an infinite loop:

abstract class A {
public static A xyz(List<String> list) throws someError {
if (B.aaa(list)) // the problem is in here
return B.xyz(list); // infinite loop from "if" to "return"
if (...)
return ...;
return ...;
}

// abstract method here but not part of the problem
}

abstract class B extends A {
public static boolean aaa(List<String> list) {
return C.aaa(list) || Z.aaa(list);
}
}

abstract class C extends B {
public static boolean aaa(List<String> list) {
return D.aaa(list) || E.aa(list);
}
}

class D extends C {
public static boolean aaa(List<String> list) {...}

public static A xyz(List<String> list) throws someError {...}

// abstract method implemented here
}

in class A, the problem is that i meant to use the xyz() method of class D but the program stubbornly uses class A's xyz() method instead. am i missing something here?
17 years ago