File Transfer In Java Using Sockets

Apr 8, 2014

I have written a java code to transfer files from one server to another using the concept of socket programming. I got the codes from another java forum that meet my requirements. The program is said to transfer large sized files (like .mkv , .mprg movies) from one machine to another and can be used to transfer files of all formats. But after running the codes I found that the program is not able to transfer large sized files such as movies and even pdf of sizes 80mb or 111mb. When i transfer small sized files, it gets transferred and the output shows that. You can run the codes and observe it. But when i try to transfer large sized files, the program goes on running for hours. The large sized files are not getting transferred. The program has used bytebuffer but still this error occurs.

**ClientMain.java**
import java.io.IOException;
import java.net.Socket;
public class ClientMain

[code]....

Note that:-

1. ClientMain.java and DirectoryTxr.java are the two classes under client application.
2. ServerMain.java and DirectoryRcr.java are the two classes under Server application.
3. run the ClientMain.java and ServerMain.java simultaneously

Also specify the source directory, destination directory and host address of the machine in which server is running in the ClientMain.java(as per your computer). Here we are not specifying source file ,instead a source directory or folder is specifying.So the entire files of source directory will be transferred.

View Replies


ADVERTISEMENT

File Empty When Attempt To Transfer Between Computers Using Sockets

May 26, 2014

I am working on a project with client/server relationship and I want the client to be able to transfer their personal music files over the socket. Every time I attempt to do it the file is created but it is empty.

Server code:

Java Code:

public class Server extends JFrame {
//===============================
// FIELDS
//===============================
// connection essentials
private ServerSocket server;
private Socket connection;

[Code] ....

View Replies View Related

File Transfer In Java Using Socket Programming

Apr 7, 2014

I have written a java code to transfer files from one server to another using the concept of socket programming. I got the codes from another java forum that meet my requirements. The program is said to transfer large sized files (like .mkv , .mprg movies) from one machine to another and can be used to transfer files of all formats. But after running the codes I found that the program is not able to transfer large sized files such as movies and even pdf of sizes 80mb or 111mb. When i transfer small sized files, it gets transferred and the output shows that. You can run the codes and observe it. But when i try to transfer large sized files, the program goes on running for hours. The large sized files are not getting transferred. The program has used bytebuffer but still this error occurs. The codes are as follows (I got them from this site [URL] ....)

**ClientMain.java**

import java.io.IOException;
import java.net.Socket;
public class ClientMain
{
private DirectoryTxr transmitter = null;
Socket clientSocket = null;

[Code] .....

1. ClientMain.java and DirectoryTxr.java are the two classes under client application.
2. ServerMain.java and DirectoryRcr.java are the two classes under Server application.
3. run the ClientMain.java and ServerMain.java simultaneously

Also specify the source directory, destination directory and host address of the machine in which server is running in the ClientMain.java (as per your computer). Here we are not specifying source file, instead a source directory or folder is specifying. So the entire files of source directory will be transferred.

View Replies View Related

File Transfer In Java Using Socket Programming

Apr 8, 2014

I have written a java code to transfer files from one server to another using the concept of socket programming. I got the codes from another java forum that meet my requirements. The program is said to transfer large sized files (like .mkv , .mprg movies) from one machine to another and can be used to transfer files of all formats. But after running the codes I found that the program is not able to transfer large sized files such as movies and even pdf of sizes 80mb or 111mb. When i transfer small sized files, it gets transferred and the output shows that. You can run the codes and observe it. But when i try to transfer large sized files, the program goes on running for hours. The large sized files are not getting transferred. The program has used bytebuffer but still this error occurs. The codes are as follows (I got them from this site [URL] ....)

**ClientMain.java**

import java.io.IOException;
import java.net.Socket;
public class ClientMain
{
private DirectoryTxr transmitter = null;
Socket clientSocket = null;

[Code] ....

Note that:-

1. ClientMain.java and DirectoryTxr.java are the two classes under client application.
2. ServerMain.java and DirectoryRcr.java are the two classes under Server application.
3. run the ClientMain.java and ServerMain.java simultaneously

Also specify the source directory, destination directory and host address of the machine in which server is running in the ClientMain.java(as per your computer). Here we are not specifying source file ,instead a source directory or folder is specifying.So the entire files of source directory will be transferred.

View Replies View Related

Can't Transfer Floating Number Matrix From MATLAB Bin File To Java Array

Mar 5, 2014

The problem is, the values are completely different than they are saved in MATLAB, and probably I need to shift the values after transforming them into byte arrays.My Java code which reads values of floating numbers from a MATLAB bin file as follows:

import java.io.*;
import java.io.File;
import javax.imageio.ImageIO;
import java.nio.ByteBuffer; // may be useful?
public class floatingNumberMatrixReader {

[code]....

View Replies View Related

Sockets Can Be Used To Transfers File Over Network

May 7, 2014

This question has confused me because "Errors" are capitalized and I'm not sure what they mean.

To me this question is false. Sockets can be used to transfers file over a network.

I can't see why this wouldn't work. The code looks fine to me.

I don't think this is true unless you're using the mouseEntered() or mouseExited() method. But again, I'm not sure.

I think this is true, I don't know what else could have listeners.

They're only worth a few marks each so the answer is only suppose to be a line or two. They are all true or false questions that require an explanation.

View Replies View Related

Java UDP Sockets And Multi-Threading

Dec 26, 2014

I have been practicing writing java code, my university course is going to cover socket programming and multi-threading.

I am presently just starting to write myself a framework for all multiplayer games I may make in the future, my aim really is simply to practice and understand better and this time, im not using an ide, just sublime text, all new grounds for me, I have a good basic understanding of the subject but I want to be fluent.

import java.net.*;
import java.util.ArrayList;
import java.io.*;
/*SMOOTH THREAD SAFE MULTI CLIENT HANDLING CLASS.
*
*This class will create connection objects when a connection is detected, these connections will run in a separate thread and update an array list in their parent class containing their last sent data

[Code] .....

View Replies View Related

Remote File Transfer

Dec 27, 2014

I want to write a java program which would do remote file transfer without using Byte array..how I can get sample code program??

View Replies View Related

Communicating Between Client And Server Sockets In Java

Apr 3, 2014

I'm working on an assignment right now which involves passing a variable series of numbers to the Server to be sorted into the correct order and returned to the client.

So far I have it connecting to the server and asking for my numbers, and I am entering each number and pressing return, and it is accepting each number individually.

One (smaller I think) problem i'm having is with the client code, specifically the while loop.. I've tried to code it so that when I enter a full stop ('.') the program will stop asking me for more numbers and move on to sending them to the server.. but instead it just crashes giving an error.. heres an example

"Enter a number: 1
Enter a number: 3
Enter a number: 2
Enter a number: 1.
java.lang.NumberFormatException: For input string: "1."
at java.lang.NumberFormatException.forInputString(Num berFormatException.java:65)

[Code] ....

Here's the client code in full

package numberSortprogram;
import java.io.*;
import java.net.ServerSocket;
public class NumSortClient {
public static void main(String[] args) {
InputStreamReader is = new InputStreamReader(System.in);
[Code] ....

The big problem that I have is figuring out how to send the sorted array back to the client..

So, what im trying to get to happen is-

-Client is asked to enter numbers
-Client enters series of numbers into an array
-Array is converted to a string and sent to the server
-String is then split into an array of strings and sorted using compareTo (don't know if this is the best way?)
-Sorted array is sent back to client and displayed.

fyi this is making use of streamsockets..

All of the rest of my code is below:

package numberSortprogram;
import java.io.IOException;
import java.net.*;
import java.util.regex.PatternSyntaxException;
public class NumSortServer {
public static void main(String[] args) {
int serverPort = 4444; // default port
if (args.length == 1 )

[Code] .....

View Replies View Related

Java Solution To Communicate Via Applications On Without Sockets

Oct 6, 2014

I have an application written in Java on the Linux platform. My application will work the following way:

User A will open application. User B will open application.User A will need to send User B a message but without a socket connection.User B will need to send User A a message but without a socket connection.The user should be able to identify the messages sent to each other.If User A reads user B's message the message will no longer be available in the channel of communication.If one user exits their application their message should be removed.User C should not be able to read user A and user B message (This is only via the application design, no real security here).Applications should be able to work on different machines however they will utilize a shared network mount to access files modified by each other.

I do have to note that the messages being sent is rather small and only 1 message is sent from each user, so in that regard I did not want to setup a client/server model to do this using sockets.

Basically I am looking for a similar concept as a message queue but more relevant to my requirements done in Java. What are some good options to use that will address some of my requirements? I have not touched Java in a long time and only have used it for certain usage so I am trying to get an idea of which current technologies are best for what I need.

View Replies View Related

File Transfer But Cannot Load In Its Launcher

Feb 3, 2015

Okay I am having a problem I wrote some code to transfer a file from my server when requested by the client. The problem is that when the file which is requested is transferred the file cannot be open in its respected file launcher when clicked. The File launcher throws back this msg "My Issue It request the File but after the File is requested and stored on the Client Machine when I Hit the File to be Launch adobe says the file "Adobe could not open the File for it is not supported file type or because the file as been damage"

So i have two pair sets of code for original coded by me. Original code i had first Server

import java.io.*;
import java.net.*;
public class SimpleFileServer {
public final static String FILE_TO_SEND = "c:/Users/Acer/Downloads/COAFlags.pdf"; // you may change this
public static void main(String args[]) {

[code]....

View Replies View Related

File Transfer Protocol Implementation

Mar 19, 2013

I have to write a code for File Transfer Protocol! It says that I only need to write code for client, but it also says that I have to run the program and send some files to server. I guess than I also need server side as well. I have to write my own classes, I cannot import some existing classes. I have to connect to the server with password and username and after that send some files to the server. I don't know anything about FTP. Can i maybe do this by Sockets and ports? I worked something with that.

View Replies View Related

File Transfer App - Create / Select Destination Folder

May 14, 2015

I'm currently new to java and I would just like to ask if Socket is sufficient for this file transfer app I'm planning to work on.

The specs are as follows:

~ Move/Copy Files of selected folder/s to a single folder(consolidating them) within the same machine and Network
~ File type will be specified on GUI and those specified will be the ones transferred
~ option to choose Move or Copy of files
~ ability to create/select folder of transfer destination

Here is an draft of what the GUI will look like.

View Replies View Related

How To Transfer Cipher - Encrypt A File And Decrypt It On Another Host

Jun 30, 2014

I want to encrypt a file and decrypt it on another host. For decryption on another host I guess I need to transfer the cipher... how can this be done? How can you write a Cipher to disk?Or am I completely on a wron track?

The following code is doing it already on one host:
 
package test;
import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.ObjectInputStream;import java.io.ObjectOutputStream;import java.io.Serializable;import java.security.Provider;
import javax.crypto.*;import javax.crypto.spec.DESKeySpec;

[Code] ....

View Replies View Related

JSF :: Transfer Value From JavaScript To Backingbean Java

Apr 30, 2014

I have a js code that finds out the timezone and then I am trying to "send" a value to a java backingbean. This code must be execute during the load of the xhtml page because in the process I use the "localTimeZone" bean.

<h:inputHidden value="#{localTimeZone.timeZoneID}" id="clientSelectedTimeZoneID"/>
<h:inputHidden value="#{localTimeZone.offset}" id="clientSelectedOffset"/>
<script type="text/javascript">
var userTimeZone = userTimeZone();

[Code] ....

How is the correct way to do this in order to have the setters of backingbean called ?

JSF ver: Implementation-Version: 1.2_12-b01-FCS
RICHFACES: Implementation-Version: 3.3.3.Final

View Replies View Related

Can Transfer Other Files With Jar Using Java Web Start?

Nov 15, 2014

I made a tiny app that saves notes to a folder within the classes directory where I created the .jar file.Let's say I wanted to add this to Java Web Start. Would I be able to transfer the jar file within a folder(s) or would I have to change the program so that It creates a new folder to save texts In automatically ? Basically , can jar files be transferred with other files/folders ?

View Replies View Related

How To Connect With Sockets From Other PCs

Dec 26, 2014

I have just started learning about sockets and such... and i have created a chat program with a server and a client

server:

public class Server {
private static ServerSocket server;
private static Socket connection;
private static PrintWriter pw;
private static BufferedReader br;
private static JTextField textOutput;

[Code] ....

so, everything is working fine . There is only one thing i would like to do now: make it so that i can run the server from my computer and then others can run the client from theirs and we will be able to chat . So I tried:

In the client code on line 56 is says:

connection = new Socket("localhost",7777);

So I changed "localhost",7777 to "myip",7777)

But when i run the server on my computer and run the client on another computer i get this error:

java.net.ConnectException: Connection refused: connect

Why is the connection getting refused? is it for security reasons? so hackers cant connect to me or something? And is there a way to tell your computer to allow that client to connect?

View Replies View Related

Passing A Value For Sockets?

Mar 13, 2014

I am having a problem passing an int value from one class to the other. The gist of the objective of this program is to compute a local sum at each client, and then once the local sums are computed.. to compute the overall sum from all the clients. My problem is that I'm having trouble figuring out how to pass each sum from each individual client in the class multicastSenderReceiver to the readThread class. I keep getting an error.

I feel that I have to be able to pass the sum value from each client generated in multicastSenderReceiver to the other class, because that is the only way I'll accurately be able to sum up all the values..

Java Code:

package multicastsenderreceiver;
import java.net.*;
import java.io.*;
import java.util.*;
//import static multicastsenderreceiver.multicastSenderReceiver.numProcesses;
class multicastSenderReceiver{

[code]....

View Replies View Related

Network Communication Using Sockets?

Dec 6, 2014

I have all of my code written, but it is not producing any output and i'm not sure why.

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;

[code]...

View Replies View Related

Using HTTP Requests For Sockets Instead Of TCP

Apr 11, 2014

Generally Socket Programming uses HTTP Protocol to send and receive messages in Java. Can we try to exchange HTTP/HTTPS requests instead of TCP?

a Socket constructs a HTTP request to send to another socket from information it has and sends to another one and Server responds with HTTPResponse.

View Replies View Related

How To Minimize CPU Usage For Sockets And Threads

Aug 16, 2012

I created an instant messenger using java. When I have the Server that communicates between the clients and one client running on my Computer the CPU Usage is at 100%. It really slows down everything else I'm doing and I figure this might be an issue if I gave this to people to use. I don't want the client taking up a lot of CPU Usage if they're just running it in the background while doing other things on their computer. The program utilizes multithreading. Each thread is constantly being polled for input.

The Server, as seen below, has two threads. I explain what the threads do before the code. There is also another while loop running constantly in the server that is waiting for sockets to connect. The loop does not run constantly at the line socket.accept(); it stops and just waits.

The User, split into a menu and chat window, has two threads as well. I explain what the threads do before the code. After I originally posted I put a 100 ms sleep in all my threads. CPU Usage is still at 100%*

This thread listens for input from the user. The input tells the server what action to take. There is a thread running for every user currently connected to the server.

public void run()
{
try
{
input = new DataInputStream(user.getSocket().getInputStream());
output = new DataOutputStream(user.getSocket().getOutputStream());

[code]....

View Replies View Related

How To Transfer The Value Of A Variable From One Class To Another

Mar 12, 2015

I am developing a program that seems to need to transfer the value of a variable from one class to another. However, neither of the classes is the main class.

This simplified code should make my problem clear:

This is my main class where I create runone from Class1 and runtwo from Class2:

public class MainClass {
public static void main(String[] args) { 
Class1 runone = new Class1();
Class2 runtwo = new Class2(); 

}

This is Class1 where I set up x and give it the value 20. I also have a getter-method to be able to access the value of x from other classes.

public class Class1 {
int x = 20;
public int getX(){
return x;
}}

This is Class2, where I try to access the value of x that was set up in runone.

public class Class2 {
int y;
public Class2() {
y = runone.getX + 10;
System.out.println(y);
}
}

Unfortunately, I get the error message "runone cannot be resolved to a variable."

What do I do to be able to access the variable x (that is set up in Class1) from Class2?

View Replies View Related

JSP :: Html To Page Transfer

Mar 31, 2015

i am trying to move from html to jsp in html it is simple code and in jsp there is database connection . but from html it is not going on the page of jsp. i put correct address in the form action attribute in html file.i am attaching both my files... following is my html code :-

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h3>ok its running fine</h3>
<form action="/ADMIN/add_material.jsp" method="post">
<div>

[code]....

View Replies View Related

How To Calculate Data Transfer Speed

Feb 25, 2014

Two machines are connected in a LAN & Sharing Files in between them.

Everything is Working Fine but now i want to calculate the Copying Speed/data transfer Speed between them.

View Replies View Related

Transfer Lowercase Letters Not Convert

Aug 20, 2014

I am trying to sort out all lower case letters out of my text file into a new file. I am not very good with char values. My text file that is being read says

AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz.

I just need it to write out all the lower case. The code below is what I have to read and write the file.

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Scanner;
public class Lower {
Scanner in=new Scanner(System.in);
FileWriter filw;
String fr;

[Code] .....

View Replies View Related

How To Transfer Output Into Text Area

Sep 26, 2014

how to put the output the the text area this is the code .

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package interns;
/**
*
* @author JosephP
*/
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

[Code]...

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved