Mousa A. Rafi

Greenhorn
+ Follow
since Jan 30, 2005
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 Mousa A. Rafi

Thanks Craig Wood. That piece of program told be that I was doing something wrong and then found how stupid I've been not to check if the class files were created in the same directory where the java and image files are. I was using JCreator and for some reason it created the class files in a different place. So, when tried to execute (also with JCreator) they didn't find the images.
18 years ago
Here's how I'm trying to use a toolbar:
First create a ImageIcon type object and create an Action.

Then somewhere registering the action with the toolbar:


When I run this, there appears small boxes in the toolbar and by click them I achieve their desired behaviour. It's only the image that should be shown in the boxes do not appear.

I confirmed the existence and actual name of the image file. It's in the same directory where the .java file is.
18 years ago


Originally posted by Joe Ess:

I tried it again. The only problem I got was when the file already existed on the client side. The server side crashes.



Joe Ess, what version of JDK or any IDE are you using? The problem you mentioned never occured to me. So, I can't tress why it crashes on your machine. But, it probably is the main problem, because after handling it, the applications now work fine.
18 years ago
That's interesting. I didn't handle the situation when the file already exists on client side. But, the server never generated an error. I wonder why.

I checked the files with notepad on Windows and gedit on Linux.
18 years ago
Sorry Joe, but the problem still exists. I've tried with the modifications you suggested. It now works lot faster. I could transfer a mp3 file of 5MB in seconds which would take minutes before and couldn't find any transfer problem with that file.

Changed code on the server:


Actually the problem don't happen everytime. In my case, the last time I tried the programs: first I transferred a html file, then a java file and then another java file (all located in the same root directory). Then I checked the transferred files. The first two were ok, but the last java file was totally empty.


Are you certain that you have recompiled your source and you don't have any old versions in the classpath?


I've recompiled the source codes and as a result it works faster. I'm certain that's not the problem.
18 years ago
James Carmen, what you are saying is true. But, shouldn't we get the exact copy of the file when using binary mode? We might not have a carriage return at the end but atleast we shouldn't have missed a character.

In the previous post what I meant is I tried the server and the client program on the same machine. Once on Linux and once on Windows (for example). It's not like my server is on Linux and the client is on Windows or vice versa. So, there actually shouldn't be any hassle of appending any extra character at the first place.
18 years ago
Joe Ess, thanks for trying it out. I'll try it with the changes you've mentioned. However, you might want to try it out with some text files. I tested it with few html and java files. Most of the time some characters were lost at the beginning of the files. This happens on Windows. Originally I coded and tested on Linux where thing were worse. Sometimes the text files were totally blank.
18 years ago
Actually, if you look closely to my code, you'll find that the part that deals with sending and receiving a file does not use any reader. I used BufferedInputStream and BufferedOutputStream to do the job. I used readers (BufferedReader)only to read messages sent from the client to server and vice versa. Besides the program behaves inappropriately even when I'm dealing with text files.
18 years ago
I've a JFrame that has a JTextField and a JButton object. After typing something in the Textfield I want the JButton to be clicked when I hit Enter.
How can I do it? Does it have something to do with Actions?

Code example will be helpful. Thanks in advance.
18 years ago
This is a simple client server program. The client requests for a file to the server and if the file is present on the server server sends it to the client.
I've tried it with sockets and streams, but it's not working properly. Most of the time some data loss occurs and seems very slow. I assume that as the server sends data byte by byte and the client reads the same way and since they are separate programs, the proper sequencing of sending and receiving is not happening. So, is it actually the problem or is there anything else? How to solve it (in the best way)?

Here's my server code:


Here's my client code:

[ May 05, 2005: Message edited by: Mousa A. Rafi ]
18 years ago
Well, I'm new in java web technologies. All I know is JSP is like PHP that can be used to build dynamic pages. But I hear these words JSF and Jakarta Struts a lot these days. So, what exactly are these? Why use them? And what is a servlet? Want to see the big picture.
[ April 26, 2005: Message edited by: Mousa A. Rafi ]
18 years ago
JSF
Stan James,
Thanks for your suggestions. They indeed sound useful to me. Well, as you mentioned, FTP is the most suitable solution and as long as it full-fills the constraints I mentioned earlier I'd really want to go for it. But, as you can guess, I wouldn't have started this topic if I knew how to do it in the first place.

What I would really wish for is a short program / example that works with FTP to get myself running and then go for the doc for details and advanced features.

Thanks once again for the help. By the way, I liked that quotation you used for signature.
It might be helpful to read my topic: Keeping an image in database in the JDBC section to understand the main problem.

Well, what I want to do is, send a file (most likely jpg or gif) to another machine on the network and save it in a particular directory of that machine, with the file renamed to something else. For example, I have an image named mypic.jpg. My application will send this file to another machine and it will be saved there as /DBUser/images/user0001.jpg. So, what would be the neat and clean way to do this?

If I were to do this app using web technology, I would send the file using HTTP 'post' method and let the webserver and PHP do the rest on the remote / server machine. I have some experience of making simple client server applications with Java which simply talk to each other. But never worked with protocols. Will FTP be of any help?
Nice to see different opinions. Well, if I were to build this database for a intranet or web solution that works with general HTML, HTTP protocol and probably a scripting language like PHP, I would definitely go for saving links to the files rather than BLOB. Even if the Java application was to run on the same machine where the DB server is running I would do the same. But, when it comes to building an application with Java that should work on a network and the DB server is located in a different machine then using BLOB seems easier. However maintaining the database is also an issue and hence how I can do it with links is something I'd really love to know. Thanks once again to all for your responses.
If that's what you've actually typed, then there is a bit problem. The import statement is all lower case, but you used an upper case 'I'. It'd be:

import java.sql.*;