This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line!
See this thread for details.
Win a copy of Kotlin for Android App Development this week in the Kotlin forum!

agustinus lumbantoruan

Ranch Hand
+ Follow
since Jul 17, 2010
Studying Information System for a hobby. I love 3D design, 3D animation, web design.
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by agustinus lumbantoruan

Wouter Oet wrote:Well scrap that. I'm not sure any more. But you do try to close dis twice. On line 93 and 98.

hahahaha i didn't notice that. Thanks man, i appreciate it

So here is the little update of the server and client code. The update was just to make it look cleaner
7 years ago

Wouter Oet wrote:Couple of remarks:

Method names should start with a lowercase letter.
Sometimes you're logging with java.util.Logger (which isn't really a good solution, check out SLF4J) and other times you're using System.out.
Your constructors invoke overridable methods.
Your constructors execute functionality. I think it's better to use constructors only for initialization.
You could close resources sooner.
In Client on line 37 you probably want t.start() instead of

Hi thanks for the remarks. I have do your remarks except for this part which
I do not understand "You could close resources sooner."

Could you elaborate that please.

Thanks Oet
7 years ago
Hi everyone, so this is somewhat the final code might look like. I hope it's useful for every one.
Thanks for the support guys!

7 years ago

James Sabre wrote:In your client

In your server

Note - once you have wrapped a stream use only the wrapper or you could end up loosing data buffered in the wrapper.

I will give you an update change about the code tomorrow. It's late night here.
Thanks James for your help. I appreciate it man.
7 years ago

James Sabre wrote:As I said earlier! Use a DataOutputStream and method writeUTF() to write the file name and then DataInputStream and method readUTF() to read it.

Could you elabore DataOutputStream please? is it like this?
Ok, about writeUTF(String str). How can i get the filename?
7 years ago

James Sabre wrote:Looks like I wasted my time; you are still using a buffered reader in the server!

I use buffered reader to get the file name.

From the java docs
public String readLine() throws IOException
Reads a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed.
A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached

If i do not use "BufferedReader" how can i get the input file name? I want the transfered file to the server has the same name as the inputted name from the client.
The bufferedreader reads the client's PrintWriter. In the client side, I wrote this in line 25-27
If i do not use the BufferedReader, i have to write the file name manually and that is not what I want. Imagine if there are >100 videos uploaded from each encoder server to the streaming server
Do you know any other alternative?
7 years ago

James Sabre wrote:I haven't gone through the code in detail but these is at least one problem that could cause you to loose bytes. You get the file name from the input by wrapping the input in a BufferedReader and reading a line. You then use this name to create the file and then read the file content from a a BufferedInputStream which wraps the the original InputStream. This means that anything buffered in the BufferedReader will be lost forever.

Consider the use of DataInputStream and DataOutputStream. You can then use the readUTF() and writeUTF() methods to pass the file name and use the data streams directly to write and read the file content.

Edit: This code
is very suspect. You seem to be trying to read a buffer full of data and then write "something" but you sure as heck are not writing out the data you have written. All you need is something along the lines of

Note : there are very few legitimate uses for available() and in conjunction with reading from a socket like you are doing is definitely not one of them.

Thanks man for the help! I appreciate it. I decide it to re-program it from the beginning. I took your advice about the loop and modify it a little bit. The good news is, it's working perfectly as expected. The output file at the server side is saved same as the original file name and no more byte loss

So here is the code

7 years ago
Ok so this is the latest update code. I decided to create a server that keeps on listening.
The server uses the socket input stream to get the uploaded data from the client.
At the end, there is a loop which reads buffereinputstream.

Unforunately, each file uploaded from the client is always missing about 8 bytes. Or in other word, the file becomes corrupted (missing bytes).
Interestingly the server side always gave me this message at the end. Correct me if im wrong that this because the loop hsa reached -1? Connection reset


7 years ago

Wouter Oet wrote:If you're able to write a multithreaded video encoding then you should be able to read documentation and use google.
I would advise you to read this and then you'll be able to comprehend why the
code you found is bad.

Thanks Wouter for the reference. I will read the tutorial and try to come up with a solution. I'll come back soon.
I appreciate it man.
7 years ago

James Sabre wrote:

agustinus lumbantoruan wrote:

Im sorry, I think you misunderstand.

I understand perfectly.

This is not my homework. This is part of my Thesis.

Aha; it is all clear now; it is not homework! Am I missing something? What is the essential difference between 'homework' and 'thesis' when it comes to who is supposed to do the work?

My thesis is about Distributed Video encoding. I have done the RPC, file download, multi threading video encoding. The last part is uploading the video back to the server.
Im seeking for a help.

So have you followed the same approach for the rest of your thesis? Did you take a copy of someone else's work and get a forum to massage that so that it met your brief? It would seem to me that anyone who can do significant work on "Distributed Video encoding" should find the modification required to the upload code to be trivial. You are not so much "seeking for a help" as requesting someone to do the work for you.

Am I being unjust?

OMG man. I am implementing that thesis title. I learned, took bit and pieces of other people's code, combine it, modified it, use it and apply it to make my thesis works. Oh James, you see, there is no original thesis. Everybody borrows on every body idea and works. It's sharing, being open for progress. FYI, I put reference on my thesis book, where i got the piece of code and modified it. If you are sincerely would like to give me help, please do. I do not have time to argue with this and i do not want to argue to this, copying stuff arguement. People invent things by learning/copying what others are doing. Take a look around.

Have a nice day man. I gotta go back to work solving on my program
7 years ago

James Sabre wrote:Interesting. You say "I understand most of the code" yet you want somebody to modify in an almost trivial manner some poor quality and flawed code that you found on the Internet.

This sounds very very like a request to do your homework.

Im sorry, I think you misunderstand.
This is not my homework. This is part of my Thesis.
My thesis is about Distributed Video encoding. I have done the RPC, file download, multi threading video encoding. The last part is uploading the video back to the server.
Im seeking for a help.
7 years ago
Hi, I found this code on the internet and I understand most of the code.
With this code every time I upload a file foe instance "daihatsu_ffmpeg_4.mp4" , the file output name is always name "receivedData".
Could any one help me please, how to create the output name on the server same as the upload file name. Or automatically save the output name same as for every uploaded file name.

Server Socket

7 years ago
Thanks for the response Henry

So the all threads must have a inter thread communication, am i right Henry?
Like using Wait(), Notify() and NotifyAll() and this example

The link above, there is this part "System.out.println("Press Control-C to stop.");"
I am interested at that part. How does it work? it did not mention there.
Hello dear programmers

I am on my progress in implementing my thesis.
My thesis uses thread, that is why i come here to gain guidance and help

So recently I am having a small problem.

Let say I have a total 5 threads running together.
Thread #1 accept keyboard inputs from the users.
The other threads do it's own jobs.
These threads will keep on going round around in a loop.

So if Thread #1 reads the input "Stop" given from the users, i would like the other threads to stop it's job.

Could anyone gives me a guidance where i should look the solution from.

Thank you friends. I hope im not bothering all of you.
So, how could you insert a variable with a data type "Date" into a database using Hibernate?

That is interesting.

Or should i make a new thread?