How to transfer all types of  files such as exe,html,gif,jpg using TCP?

Respected Sir / Madam,
I am doing my project in Network Security using Java. The main aim of my project is to transfer the files between the client and server in a secured way. I have used MD5 algorithm to authenticate the person who are in the client machine. If the user is an authorized user then the user requested file should be transferred from server to client after encrypting the contents using DES algorithm. B4 encrypting the contents I have just transferred the file for checking. But I could transfer only .java and .txt files. From the forum I got the info that if we handle the data in byte format then we can transfer any kind of files. So I tried bu t I couldn't get the entire contents. If I transfer the file then transferred contents is in the form of [B061234 like this only. How can I rectify this problem. I will be grateful if anyone of you help me.  Thank you very much. Here are my codings.
Server Side Codings
     try
                     FileInputStream fis = new FileInputStream(new File(fname));
                     int nos = fis.available();
                     fdata = new byte[nos];
System.out.println("No.of bytes = " + nos);
fl=1;
System.out.println("FDATA = " + fdata);
int ch,i=0;
while((ch =fis.read())!=-1)
fdata[j++]=(byte)ch;
System.out.println("Ch "+ i++ + " = " + ch);
System.out.println("J = " + j);
sendMsgs(s,fdata); // s is the Socket of the client
public void sendMsgs(Socket s,byte b[])
PrintStream p;
try
p = new PrintStream(s.getOutputStream());
System.out.println("Sending Msg = " + b);
p.println(b);
catch(Exception e)
System.out.println("Sending Error : " + e);
Client Side Codings
public void start()
try
s = new Socket(InetAddress.getLocalHost().getHostName(),2500);
dis = new DataInputStream(s.getInputStream());
ByteArrayInputStream bis = new ByteArrayInputStream(s.getInputStream());
ps = new PrintStream(s.getOutputStream());
t = new Thread(this);
t.start();
catch(Exception e) {}
public void run()
String msg="",c="";
int f=0;
byte m[] = new byte[1000];
try
while(true)
// msg = dis.readLine();
m=bis.readLine().getBytes();
FileOutputStream fos = new FileOutputStream(new File("c:\\" + fnam),true);
fos.write(m);
fos.flush();
fos.close();
catch(Exception e){}
f=1;
}

int nos = fis.available();That method shouldn't be used to determine the file size. Use File.length().
public void sendMsgs(Socket s,byte b[])
PrintStream p;Bad. Don't use PrintStreams or PrintWriters in association with sockets, as they swallow exceptions.
try
p = new PrintStream(s.getOutputStream());
System.out.println("Sending Msg = " + b);
p.println(b);That writes b.toString() to the socket followed by a newline. That's not what you want to do. Just write the bytes directly to the socket output stream. Then close the socket, or the output stream if you use one.
dis = new
DataInputStream(s.getInputStream());Good, but unnecessary.
ByteArrayInputStream bis = new
ByteArrayInputStream(s.getInputStream());Bad, and it isn't used anyway.
// msg = dis.readLine();
m=bis.readLine().getBytes();Worse. Just read the bytes directly with the DataInputStream and write them to the FileOutputStream. Don't use PrintWriters or Object.toString() anywhere where you expect to recover the original data.
The issue here is that you're not sending what you think you're sending, and you're not reading it correctly. String is not a container for binary data. Just send and receive the binary data - the bytes - directly.
And you're reinventing the wheel. What's wrong with SSL?

Similar Messages

  • How can I transfer all of the files from my old iPhone 4S to my new iPhone 5?

    how can I transfer all of the files from my old iPone 4S to my new iPhone 5?

    Download the media content from an iTunes library or the iTunes Store, and follow these instructions to transfer your personal settings and data.
    (83108)

  • How to transfer more than one files over internet at once?

    hi, friends,
    I just wonder how to transfer more than one files from one computer to another over internet at once. Not using ftp. pls any one give me the solution.

    This isn't hard to do, but it depends on your exact need. I did something very similar to let me upload all my mp3 file from home to work using sockets (don't have the code anymore..).
    What I did was implement a "pull" approach rather than a "push" approach. In other words, everytime my server got a request from a client, it served up the next file. It didn't know or care that the client was always the same.
    If you can set up a server to serve one file when a client attaches, then basically just put that code in a loop.
    If this doesn't meet you need, it might still be helpful as a starting point...

  • I cannot save pictures from facebook to "my Pictures" files on my hard drive. There is no place to indicate the type of file, such as jpg etc.

    I have been copying a picture & pasting it on my AOL email & saving photos from Facebook from email . Also, I cannot watch videos posted by my friends on Facebook.
    Firefox works fast on scrolling thru Facebook but I haven't found it to be that helpful for simple things I want to do.
    Thanks for any help you can provide.

    Hi perric,
    On the first issue about pictures.
    * You can set Firefox to ask you where to save the file rather than always using the Downloads folder. This article describes how to set that: [[Startup, home page and download settings]].
    * When you say "there is no place to indicate the type of file, such as jpg etc." is the problem that Facebook isn't including that in the file name and you need to add it? If you could explain this part a bit more.
    * Another way to save pictures is to use the Page Info dialog. While on the page with the images, you can use either:<br><br>* right-click and choose View Page Info > Media<br>* Alt+t (open the classic Tools menu) > Page Info > Media<br><br>As you scroll down the list, you can preview and use the Save As button to save those "hard to get" images.
    On the second issue about videos.
    * Do you see a gray space indicating that you need a plugin? Or does the video not play when you click it? Please explain what you're experiencing in a little more detail.
    * In case you do not have the Flash player plugin for Firefox, you can get it here: http://get.adobe.com/flashplayer/ (make sure to uncheck any unwanted extras that Adobe might offer). If you do the download from IE, you won't get the right version. In that case, use this link to choose the non-IE plugin: http://get.adobe.com/flashplayer/otherversions/
    Hope that helps a bit.

  • How to transfer video and audio files from windows PC to new ipad?

    How to transfer video and audio files from windows PC to new ipad?

    iTunes: Syncing media content to iOS devices and iPod
    Sync with iTunes.
    Connect the iPad to the PC and launch iTunes.
    Click on the iPad name on the left side under devices.
    Click on the Music Tab on the right.
    Click on all of the albums, artists, playlists that you want to sync
    Click on the Sync Music Heading.
    Click on Apply in the lower right corner of iTunes
    Follow the same procedure for Movies.

  • How to transfer more than 1 file usong bluetooth t...

    Can anyone tell me how to transfer more than one file via Bluetooth. I am using Lumia 720.

    Hi,
    My theory is that Windows get confused when it is opening the program file and the following intsructions should create a unique copy. I have produced the instructions in detail because I am never sure how much people are use to - forgive me you know much of it.
    Open Windows or Folder Explorer
    Navigate to C:\Program Files (x86)\Adobe\Photoshop Elements 12
    Look for PhotoshopElementsEditor.exe
    Right click on the file and select Copy
    Right click on a blank space and select Paste - you should get a prompt asking if you want to continue - you do - this should produce a copy of the file
    Rename PhotoshopElementsEditor - Copy.exe to PSE 12 ED  - you should get a prompt asking if you want to continue - you do
    Close the Explorer
    In the Windows Control Panel, select Default Programs
    In Default Programs, Select Associate a file type … - it will take a while to display the list
    Scroll down to the type you want to select - say .jpg and select it
    Click on the Change program button
    Click on the Browse button
    Search for the PSE 12 ED file renamed in 6 above, select it and then click on the Open button
    Click on OK and close the Default Programs
    Now try your tests. I can get multiple files to open as well as retain Expert mode.
    Good luck
    Brian

  • How to transfer my .bbb format file to iPhone5?

    Hello there,
    Could you, please, show me how to transfer my BlackBerry backup file to an iPhone 5?
    I feel it's a little bit difficult.
    Thank you.

    Hi FoxDie85
    Welcome to the Community
    You can't transfer. bbb file to Iphone nor android as it's for BlackBerry devices only. But, you can transfer Contacts, Calendar items, Pictures, Videos, Files and documents to Iphone using 'Device Switch'.
    On your old device, tap Search and type Device Switch in the field. For more information, visit www.blackberry.com/deviceswitch
    Good luck.
    • Click Likes to appreciate those who helps you
    • If your issue solved, mark the best post in your thread as Solution

  • How to transfer all materials from one plant to other plants?

    How to transfer all materials from one plant to other plants?

    Hi
    To transfer stock in one step  between plants belonging to same company code use movement type "301" and using transaction code "MIGO". IF you like in two step it helps to monitor stock in transit use movement type "303" and "305".
    303 Transfer posting plant to plant in two steps - removal from storage
    305 Transfer posting plant to plant in two steps - placement in storage
    to transfer stock between plants of diffrent company code go for stock transpor order using tcode "me21n"
    hope it helps

  • HT204150 I currently have 14,181 contacts that are on my computer, which an apple tech was nice enough to show me how to transfer all my contacts  from my mac 2 "iCloud " account all though when ever I log into my "iCloud" account it still only shows 13,0

    I currently have 14,181 contacts that are on my computer, which an apple tech was nice enough to show me how to transfer all my contacts  from my mac 2 "iCloud " account all though when ever I log into my "iCloud" account from a different web browser it still only shows 13,032. Meanwhile on my mac book pro, the "icloud" contact is still spinning like its trying to update the rest of the missing contacts. I have let the computer run for 2 days straight and still no progress. Is there a limit to how many contacts I store on "iCloud" I have upgraded to the extra 25 gigs per year. If anyone has any advice I would greatly appreciate it, because its also slowing down my mac book pro significantly causing it hard to do any other task on my computer....Any advice or help would be again greatly appreciated.

    On the surface, it doesn't sound like you're reaching a limit in the number of contacts you can have.
    I would first create a contacts archive (file >> export) for a backup.  Then, go to system preferences >> icloud and uncheck contacts.  Reboot.  Return to those preferences and recheck contacts.
    Also, review http://support.apple.com/kb/HT4489 just in case you have some contact cards that are reaching a different limitation.

  • How to transfer all songs from ipod to my library?

    got a new ipod, but some of my songs are only on old ipod, not in my lib. how to transfer all songs from old ipod to lib, so i can put them on new ipod. both ipods are 4GB mini. thanks for help.

    There are a number of third party utilities that you can use to retrieve the music files and playlists from your iPod. You'll find that they have varying degrees of functionality and some will transfer movies, videos, photos, podcasts and games as well. Have a look at the web pages and documentation, this is just a small selection of what's available, they are generally quite straightforward. You can read reviews and comparisons of some of them here:
    Wired News - Rescue Your Stranded Tunes
    Comparison of iPod managers
    TuneJack Windows Only (iPhone and iPod Touch compatible)
    SharePod Windows Only (iPhone and iPod Touch compatible)
    iPod2PC Windows Only
    iDump Windows Only
    iPodRip Mac & Windows
    YamiPod Mac and Windows
    Music Rescue Mac & Windows
    iPod Music Liberator Mac & Windows
    Floola Mac & Windows
    iGadget Mac & Windows (iPhone and iPod Touch compatible)
    iRepo Mac & Windows (iPhone and iPod Touch compatible)
    iPod Access Mac & Windows (iPhone and iPod Touch compatible)
    TouchCopy Mac & Windows (iPhone and iPod Touch compatible)
    If you have any iTunes Music Store purchases the transfer of purchased content only from the iPod to authorised computers was introduced with iTunes 7. You'll find details in this article: Copying iTunes Store purchases from your iPod or iPhone to a computer
    There's also a manual method of copying songs from your iPod to a Mac or PC. The procedure is a bit involved and won't recover playlists but if you're interested it's available on page 2 at this link: Copying Content from your iPod to your Computer - The Definitive Guide

  • Firefox4 always cannot remember how to open these types of file

    When I download certain types of file, for example, .rar file, firefox4 always cannot remember how to open these types of file next time. The check box “automatically use the same method to handle the file” in the download popup window looks grey and cannot be checked. Also, these types never appear in the list of option-application. I check previously installed firefox 3.6, these types are all called (application/***). What’s more, when I want to turn off computer, as long as firefox 4 is opened, it will lose response and prevent Windows from turning off. Whatever I do, reinstalling firefox, deleting profile and even reinstall Windows, I cannot get rid of those issues. I think these are bugs of firefox4. I hope they will be fixed as soon as possible.

    Purchase a legal copy of Windows instead of attempting to pirate it. You will then have the installation disks you'll need and won't have to worry about opening Torrent files.

  • I am going to buy a Mac desktop and want to know how to transfer all my purchases and uploaded music from my PC. How can I do this to ensure all videos and music transfer over and not just purchases?

    I am going to buy a Mac desktop and want to know how to transfer all my purchases and uploaded music from my PC. I originally started using iTunes on my PC so it has everything I have ever purchased or uploaded from my own collection of music.
    How can I do this to ensure all videos and music transfer over and not just purchases? Do they do it at the Apple Store or at Best Buy? help!

    Move iTunes Library from PC to MAC
    http://www.macworld.com/article/146958/2010/03/move_itunes_windows_mac.html
    Also, See here if you need to...  iTunes to an External Drive
    http://support.apple.com/kb/HT1751

  • Me and my partner are currently using the same apple id and have no space left on our devices. We are currently waiting on the iphone 6 plus to arrive and don't know how to transfer all data to the new phones.

    Me and my partner are currently using the same apple id and have no space left on our devices. We are currently waiting on the iphone 6 plus to arrive and don't know how to transfer all data to the new phones.?

    I don't know if I'm asking this all in a way that can be understood? Thanks ED3K, however that part I do understand (in the link you provided!)
    What I need to know is "how" I can separate or rather create another Apple ID for my son-who is currently using "my Apple ID?" If there is a way to let him keep "all" his info on his phone (eg-contacts, music, app's, etc.) without doing a "reset?') Somehow I need to go into his phone's setting-create a new Apple ID and possibly a new password so he can still use our combined iCloud & Itunes account?
    Also then letting me take back my Apple ID & password, but again allowing us (my son and I) to use the same iCloud & Itunes account? Does that make more sense??? I'm sincerely trying to get this cleared up once and for all----just need guidance from someone who has a true understanding of the whole Apple iCloud/Itunes system!
    Thanks again for "anyone" that can help me!!!

  • How do I transfer non-iTunes music files from my iPad to my MacBook using home sharing?

    My MacBook Pro hard drive recently had to be replaced by Apple, because it quit for some reason they couldn't identify. However, now my ipad2 doesn't recognize my macbook pro and I have at least 200 music files in my library on my iPad that I did not get from iTunes. I need to upgrade my iPad to iOS 5 but I also don't want to lose all those music files. I was hopeful I could use home sharing to sync my iTunes libraries, but I can't figure out how to export files from my iPad. Please help, anyone?

    I was hopeful I could use home sharing to sync my iTunes libraries,
    Unfortunately, you can only stream content to your iOS devices via home sharing (not sync it).
    I'd have a check through the following user tip instead:
    Recovering your iTunes library from your iPod or iOS device

  • Getting all types of files with the help of get_file_name function

    hi all,
    i am using Forms [32 Bit] Version 6.0.8.24.1 (Production).
    i have used get_file_name function to the file name of all type of files
    but i am able to get only the folders when i tried like below
    :FILE_NAME := GET_FILE_NAME(NULL,NULL,NULL,'Choose a Directory',OPEN_FILE,FALSE);my requirement to get all types of files on the window(user will selects whichever way he wants)
    Can i acheive it through get_file_name or i have to go for any alternative to get the file list, so that user can select by browsing the folders.
    Please help.
    Thanks..

    hi,
    in my code the select file was set to false(so showing only the directories) now i have set it to 'true'. its showing the files now.
    with the help of my above shown code i can get the full path of the file.
    is there any way to get only the file name?(other than the last occurance of '/' logic or that is only the way?)
    Please help.
    Thanks..

Maybe you are looking for

  • Zen Vision M Managing Active Selected Mu

    I really like the Zen vision...with on exception: the inability to manage acti've Playlists and expand contract...selected music. This is my fourth Creative MP3 player and the Zen Jukebox had a MUCH better music management system. You could expand/co

  • Transaction Key for Movement Type 561

    Hello, For movement type 561, I know one of the Transaction Key is BSX.  I would like to ask what is the other Transaction Key as I would like to set the GL Account Determination.  Thanks. Thanks.

  • Printing the date and time on a photo

    The date and time that the photo was taken showes up but how do I get it to print on my photos?

  • Export of multiple artboards with only artboards' name, doesnt save to desired folder.

    when trying to export multiple artboards into files that only bear the separate artboards' name, i set up the export with the filenames with blank names so set to ".jpg" . i also choose a folder that they are to be saved to. what happens now is weird

  • Smartview problem

    Hi guys, I am facing this problem with smartview. When connecting to Hyperion through excel, the sheets will automatically be protected. When I enter new data in the sheet and try to submit data, i get the message that the excel sheet is protected. T