Problem in file and socket fd

Hi
I am using TCP sockets for communication.I create a server which blocks on the accept method to listen for new connections.
The problem is that if I open a file descriptor in the program ,then the server does not block on accept method but instead it reads garbage from the socket.
What could be the possible problem.??
Thanks

hi Here I am sending you a piece of code thaat simply starts a server and opens a file . When I run this ther server does not wait .And if I comment out the line which openss the file it works fine .
<pre>
#include <stdio.h>
#include <strings.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netdb.h>
#include <sys/uio.h>
#include <arpa/inet.h>
#include <errno.h>
#include <ctype.h>
#include <signal.h>
#include <fcntl.h>
#include <time.h>
#include <sys/timeb.h>
#include <stdlib.h>
#include <stropts.h>
#include <sys/filio.h>
#include <iostream.h>
#include <pthread.h>
#include <plot.h>
#define PORT 8888
#define BACKLOG 10;
int main()
int listenfd ,connfd;
//** if I comment this line server works fine
int fd = open("file",O_RDWR,777);
socklen_t clientlen;
struct sockaddr_in clientaddr;
struct sockaddr_in serveraddr;
listenfd = socket(AF_INET,SOCK_STREAM,0);
serveraddr.sin_family = AF_INET;
serveraddr.sin_addr.s_addr = htonl(INADDR_ANY);
serveraddr.sin_port = htons(8888);
bzero(&(serveraddr.sin_zero), 8);
int n=1;
if (setsockopt (listenfd, SOL_SOCKET, SO_REUSEADDR, (char *)&n, sizeof (n)) <0)
fprintf(stdout,"Error: socket option\n");
close (listenfd);
shutdown(listenfd,2);
bind (listenfd,(sockaddr*) &serveraddr,sizeof(serveraddr));
listen(listenfd,10);
//*** Server Started
printf("Server listening on port 8888 \n");
connfd = accept(listenfd, (sockaddr*)&clientaddr,&clientlen);
printf("Connected accepted \n");
return 0;
</pre>
Thanks

Similar Messages

  • Problem with file and printer sharing

    I just installed a Linksys WRT54G to replace a D-Link wireless router and cannot reestablish my file and printer sharing since replacing the router.  I had file and printer sharing working fine before installing the WRT54G.   All of the computers are running either XP Pro or 2000 Pro.  I have two printers attached to one of my computers that I was previously sharing with all of the other computers on our home network.  One is attached via a parallel port, the other via a USB port.  
    Here's what I've tried so far without success.
    1.  The IP of the WRT54G is 192.168.1.1, and the IP's it assigns to my LAN computers begin 192.168.1.XXX.  The old IP of the D-Link was 192.168.0.1 and its LAN IPs were 192.168.0.XXX, so I've gone into my firewall and changed the settings for the range of trusted computers to correspond to the WRT54G's IP addresses.
    2.   I've tried uninstalling the printers and reinstalling them, including reinitializing printer sharing.
    3.  When I try to use the Windows  "Add printer" wizard to add a networked printer, it can see the computer that has the printers attached, but it does not see the printers.
    4.  I haven't fooled around with the file sharing settings, but they've all be lost too, so I suspect there is a common problem for both printer and file sharing.
    Any suggestions would be most welcome.  I don't know what would be different about the WRT54G that would cause this problem.

    Try this to Enable File and Printer Sharing...Turn Off the Router Firewall...Make sure the Windows Firewall is also Off...

  • Problems with files and a new hard drive...

    Hi there...
    I have maxed out an external hard drive I was using to hold all my photos....
    I have bought a 2 new drives with a view to backing up everything I have on file.
    If I start moving files around LR then can not locate the files and they come up in red in the folders section of the programme.
    IS there a way of reorganizing things without having to re import stuff?
    Any help would be great....
    Lee

    I think I get it... (im having a dumb day!!)
    I set the new h/d up and I import in essence an empty file into LR.
    Then all the files I want to keep on the new h/d I drag and drop from the old h/d...is this right??
    like I said Im having a dumb day...
    all the help is much appreciated
    Lee

  • Problems previewing file and with flash action

    I am using Acrobat.com for my children's book in order to send it out to agents and it has been working well since October. I have checked it several times and there were no issues but today it will not preview either file any longer and the flash page turner is no longer working. I upoaded a new version of the same file and it is working but the link I sent out to agents will only allow a download now. Just wondering what may have caused this. I read where someone else had a similar issue but there was no result posted. The page turning issue, though not really an important feature, is just something I really liked about the program. Thank you.

    Hello,
    This should have been a temporary issue - the preview function should be working normally for the new file now. Please lmk if this is not the case.
    Michelle

  • Problem restoring files and settings after a recovery

    I did a system recovery using recovery disks purchased from HP. My files and settings were backed up during the recovery program on an external drive.
    There were no instructions included on restoring files and settings after the system recovery. I called HP and a support tech told me to run the backup program on the external drive from the admin profile which I did. However, the program put my old files on my C drive at the following location C:\System Recovery Files\C\Users\Bill.
    How do I use these files under my current user profile at C:\Users\Bill?
    I suppose I could move my data files, folder by folder, but is there an easier and better way?
    My computer is as follows:
    HP Pavilion GC673AAR-ABA m8100n, SN MX3733051W
    Windows Vista Home Premium 32-bit
    This question was solved.
    View Solution.

    Unfortunately the backup feature within the recovery manager is used as a last resort option for gathering whatever files can be saved, and there is no way to place the files back to where they were previously.
    I am an HP employee, but my views are my own and are not endorsed by HP.

  • Problem with File and his methods

    Is there a way to know how much Files there is in a File.
    MyFile contain MySubFile1 MySubFile2 and what i want my program to do is to return the number 2 (for my two subfiles).

    File repracine = new File("namedir") ;
    String[] tabfile ;
    if (!repracine.exists())
    repracine.mkdir() ;
    tabfile = repracine.list() ;
    for (int i=0;i<tabfile.length();i++)
    System.out.println(tabfile) ;
    problem: tabfile.length()...
    Small changes have to be done..
    1. length is not a method but an attribute of the array. That means that> for (int i=0;i<tabfile.length();i++) has to be for (int i=0;i<tabfile.length;i++)2. If you want just the number of files in your directory You don't need the for loop at all. All you need is the tabfile.length value. If you need to print the names of all the files in the directory then you better change line:>    System.out.println(tabfile) ; to >    System.out.println(tabfile) ;
    Hope that helped.
    afotoglidis

  • Problem removing files and other issues

    Hello, i have been using Solaris 10 now for almost a week. I am starting to see a lot of flaws in it. I hate to go back to Linux when I have wanted Unix for so long. well here are my problems.
    Removing files from the DIR /export/home/ gives me this error:
    Error "Not on the same file system" while deleting "/export/hom...-1.src.rpm".
    would you like to continue?
    [Skip] [X_Cancel] [Retry]
    I seem to get that error everytime I try to delete a downloaded file, also I am logged in as root. (because I created a user account, assigined the user a group and password and I still can't log in with it)
    I also configure my panel, and add applications like the cd player, and when i reboot my computer, the applications are question marks wich are also dead links.
    I can't set my clock. the timezone seems to be messed up.
    When I reboot my computer or shut it down, it takes longer everytime to boot back up. I have timed it. The computer has passed infant mortality, but it is still young, and runs good. So i am assuming all my hardware is fine. since i have installed the os, I have installed firefox. and I have used firefox. that is about it. I am loggin in as root, so i am extremely carefull with what i do, I just seem to have a new problem with each log in. I am starting to feel like Unix is losing it's special value, but i want to try and fix the problems before giving up, after all, it has been less than a week.
    If you have any information on anything that i babbled on about thank in advance.

    Had the same problem. This post (external) seems to suggest this is Nautilus problem: http://unix.derkeiler.com/Newsgroups/comp.unix.solaris/2005-04/1109.html
    Deleting stuff form the shell instead works as a workaround, but then you don't have the benefits of trash can.
    / Rich

  • I am working in LR 5.7. I am having problems moving files and folders from my internal Mac drive to an external drive.

    My process is to drag files or folders from one location to another. Sometimes it works, but it takes a VERY long time. Sometimes it does not work. For example, I tried to move a folder with 329 images. LR processed for 13 hours and moved 58 images; then it stopped and gave the message "…error copying files to the destination you selected. The following files could not be copied." Then it noted the files not copied. Does this look like a LR problem? A hardware problem? Any suggestions on how to fix would be appreciated.

    Jim has a very good suggestion. There are many factors at work here:
    1) How are you connecting the external drive to the computer?
    2) How big are files (329 x 1MB is not the same as 329 x 25MB)?
    3) What is your computer specification?
    4) Do you have any power saving settings on (in particular something that would send the computer/hard drives to sleep)?

  • Problem Displaying file and doind a redirect

    Hello,
    I am displaying a file using a wpg_docload.download_file(v_bfile); call from a PL/SQL procedure that is called on a button
    which works fine once I put a call to APEX_APPLICATION.g_unrecoverable_error inside the procedure , as below.
    APEX_APPLICATION.g_unrecoverable_error := FALSE;
    The button is supposed to automatically refresh (reload, resubmit) the page once that operation is finished. However the page does not refresh unless I remove the APEX_APPLICATION.g_unrecoverable_error line, which in turn means the file is not displayed.
    I have tried putting in a APEX_APPLICATION.g_unrecoverable_error= TRUE at the end of the procedure and in Apex where the button is called but the system is not having any of it.
    How can I get the file to display (dialog button to appear) and then the redirect to work please..

    Hi,
    The requirement is as below.
    We need to create an customize xml using some  other xmls.
    Than using the generated xml,we need to generate an pdf report.
    Then we need to sent this pdf report for printing.
        I have created a custom action block using java.
       This code takes path of xml and generates a pdf report.
       It than creates a report at particular location.
       This code is working fine in xMII 11.5. As we can store/ create files at any location. 
       But not working in 12.0. I donu2019t know why?
       Is their way around in 12.0 by which we can achieve this functionality.
    Thanks,
    Vishal J

  • Problem with file and tabbedpanes

    Hi
    i am reading a file on my program .in that file i am written 4lines .but i want that from that file 2 lines on one tab and another two lines on another tab using tabbedpanes
    Edited by: nirmala on Dec 26, 2007 7:26 AM

    i am written some code see this public void actionPerformed(ActionEvent e) {
    // Handle open button action.
    if (e.getSource() == browse) {
    int returnVal = fc.showOpenDialog(NnsClient.this);
    if (returnVal == JFileChooser.APPROVE_OPTION ) {
    File file = fc.getSelectedFile();
    // This is where a real application would open the file.
    log.setText(file.getParent());
    } else {
    log.setText("Open command cancelled by user." + newline);
    log.setCaretPosition(log.getDocument().getLength());
    // Handle update button action.
    } else if (e.getSource() == update) {
    File file = fc.getSelectedFile();
    String val = file.getAbsolutePath();
    File file1 = new File (val);
    try
    RandomAccessFile ra = new RandomAccessFile(file1,"r");
    //System.out.println(ra);
    long last = ra.length();
    System.out.println(last);
    FileReader fis = new FileReader (file1);
    //LineNumberReader lr = new LineNumberReader(fis);
    //System.out.println(lr);
    //lr.skip(last);
    //int countRec = lr.getLineNumber()-1;
    //System.out.println(countRec);
    BufferedReader bis = new BufferedReader(fis);
    StringBuffer sb = new StringBuffer();
    String line = null;
    while((line= bis.readLine())!=null)
         //int i = line.length();
         System.out.print(line.toString());
         //System.out.println(line);
         //sb.append(line);
    System.out.println(sb.append(line));
         sb.append("\n");
    tf.setText(sb.toString());
    ra.close();
    fis.close();
    //dis.close();
    bis.close();
    catch(FileNotFoundException e2)
    e2.printStackTrace();
    catch(IOException e1)
    e1.printStackTrace();
    }this is for action performed in this code only i want to develop that when i click on update i wanto get the file data on different tabs
    JTabbedPane tp = new JTabbedPane();
    JPanel pa = new JPanel();
    pa.add(scroll);
    //pa.add(ns.ta.setText(sb.toString()));
    JPanel pb = new JPanel();
    pb.add(tf);
    t.setEditable(false);
    //setPrefferedSize(new Dimension(30,40));
    //tf.setText(sb.toString());
    tp.addTab("tab1", pb);
    tp.addTab("tab2",pa);
    content.add(tp,BorderLayout.SOUTH);this code is for tabbedpanes on my program

  • I can't manage file and storage services in server manager.

    I have a windows 2012 R2 server. I had turned on the file and storage services role and was able to configure a single share in server manager. A few days later I wanted to create another share but when I select file and storage services within server manager
    I get the message at the top that says The server has not been queried for data since it appeared offline. Also there are no shares listed. Even though the shared folder that I already created is available from other computers.
    If I try to create a file share anyway I am asked to choose a server to create the share on and the server appears in the list with a status of offline. 
    Now this may seem like an obvious connection issue however, I am trying to configure the server locally, not over the network. I can manage other services in server manager just fine. I have WDS and WSUS roles installed and can be configured with server
    manager just fine. I only have a problem with file and storage services. 
    There are no errors in the event log. 
    I tried to remove the file and storage services role from the server but as soon as I uncheck the box for file and storage services I get a pop up windows that says: 
    The validation process found problems on the server from which you want to remove features. The selected features cannot be removed from the selected server. click ok to select different featres.
    I lists validation results that simply state the name of the server and says "storage services cannot be removed."
    How can I get file and storage services working again?

    Hi,
    How many servers are there in the list? If the offline serve is a remote server, please reboot the remote server to see the result. In the meantime, please new a shared folded on the local server in Windows Explorer to see if the issue still exists.
    Please refer to the article below to share a folder with server manager.
    12 Steps to NTFS Shared Folders in Windows Server 2012
    https://blogs.technet.com/b/keithmayer/archive/2012/10/21/ntfs-shared-folders-a-whole-lot-easier-in-windows-server-2012.aspx#.Ux1ty_mSwXV
    Regards,
    Mandy
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • File and printer sharing using Airport Express, usb HP Deskjet 3620 printer

    I have a general question, and other forum users might have a good resolution for it - but if not, here's what i'm dealing with..
    I have an Airport Express that I bought a couple of years back, it has all the necessary firmware upgrades, i'm running 2 Windows XP boxes going through a combination of Ethernet on 1 directly to the 2 Wire Home Portal 2701HG-B, and I also have an additional Netgear WGR614 v7. All firmware upgrades on all devices is installed and functioning after reset.. I've tried using a combination of the Windows XP built-in networking software, Apple Airport Utility, as well as Bonjour to get things configured and working right over the network. I've also installed the AT&T software, one is running the Mcafee security suite, and mine (the Etnernet box) is running the diagnostic utility.
    I've tried defaulting all the firewall settings in either/or/all routers i've tried setting the Airport up with, and there still seems to be problems getting file and printer sharing to work right on all computers, and still remain safe behind the firewall. All the network hardware is set up with wpa2/psk authentication, and appears to be configured correctly.
    The only version of the Apple Airport Utility that will run successfully on the systems, is the original version that came on the CD with the Airport. Both systems are completely up-to-date from Windows update, and are both running XP service pack 3.
    I know for a fact, that the Airport is working just fine, as I've troubleshot all possible known hardware issues with it individually, hooked up to 1 pc (with current updates installed and running). Wireless works fine, i'm actually running the Airport utility on my main system in the living room, that's hooked up hardwired to the router. Both systems get online and surf without a problem going through either/or router as well. I've also tried dissabling the Windows firewall on both systems, and trying to set up file and printer sharing manually using the wizard, and that don't seem to resolve the issues either. However, both systems (wheather hooked up networked, OR individually), have both been experiencing some odd "quirks". The Ethernet box i'm on, has overwritten my primary HD, as "Athena" and made it unusable. The wireless box, has been giving simular "boot-up" related errors as well. I've checked the Cmos/DOS settings on both, and performed the suggested "boot-up" priority related tasks, and both systems are still experiencing problems. The Mcafee suite is up-to-date, and has caught several potentially dangrous programs running on the wireless box, hooked up to the Airport Express, INCLUDING the bundled HP diagnostic software.. However file and printer sharing still remains elusive...
    Are there any suggestions about settings to check on the devices, or in the computers, to make sure it's all configured correctly?

    ...Also file/printer sharing just flat out over the network is NOT a problem, as it's been configured before over ethernet through my Netgear router and file/printer sharing worked just fine.
    The main problem seems to be in the Airport Express' settings, it will "get configured" and then lock me out of the utility to where I can't get back in..
    The main Airport password has not been changed, and the wireless network encryption is the same for all wireless devices running on the network.
    The main problem, just seems to be with the Airport.
    Even the Home Portal has detected the Netgear router (unless it having my Netgear router saved in it's settings might be causing a conflict)... Suggestions?
    I've contacted AT&T Home Networking for help already about the Home Portal, unfortunately they can not help me with other network related issues, since i'm not using the 2 wire wireless adapters offered by AT&T...
    Message was edited by: okwolffcub

  • How to delete duplicate files and fix borken links

    Problem: Duplicate Files and Broken Links
    Involves 2 IBM ThinkPads (1) one main partition (system driveC:) running Windows XP SP3, (2) running Windows 7 and with two partitions  - Drive C: has the library while drive D:contains the “itunes media” folder.
    Issues:
    On both laptops, the iTunes media folder contains duplicatecopies of purchased songs and movies (some purchased prior to iTunes 9),imported or ripped songs from CDs, and redeemed digital copies of movies. EverythingI have tried results in broken links and duplicate files. Is there a method or aprogram which will allow me to disentangle this mess? I have spent hoursdeleting files, not using the iTunes “copy” function and so on but the problemcontinues. At times I simply run out of disc space and simply have to start theprocess all over again. I have spoken to someone in Apple’s iTunes tech supportand was told this was a “windows” problem?!?
    Any suggestions or advice that would help me to untanglethis mess would be greatly appreciated. Is taking the ThinkPads to a PC repairshop the only answer? How would they fix the problem?
    Thanks all, PrimeSequence.

    PrimeSequence wrote:
    Thanks 'turingtest2' for your suggestion. I know the location of the files, but iTunes keeps duplicating them as soon as I launch iTunes.
    You know the location of your file, but it sounded like iTunes doesn't. The FindTracks script is designed to fix the broken links.
    I doubt uninstalling and reinstalling will change anything. Uninstalling iTunes does not affect the contents of your media library or media folders, the files stay put.
    iTunes shouldn't generate much in the way of new files just through launching it... Exceptions include artwork files for tracks it knows it has yet to scan and any downloads related to podcast subscriptions.
    The only other thing I can think of would be some sort of error with the Automatically add to iTunes folder. Any files that are in there should be moved to their normal locations within the media folder layout, not copied, and then added to the library. I suppose the processing order could be add, then move, and if for some reason the move fails then next time you start up iTunes they could be added again. So do you have any files in the Automatically add to iTunes folder? If not is there any other pattern you can see to this duplication? Do you have any software that tries to add files to iTunes automatically?
    Actually, and in a similar vein, does this duplication happen on both machines or just the Windows 7 one? Vista introduced new "default" locations for user profiles plus a bunch of symbolic links that automagically redirect attempts by older software to look for things in the default XP locations. As a result your Music folder, for example, can appear at multiple locations within the tree of folders on your C: drive. I suppose it is just possible that some form of recursive nightmare could be going on there.
    FWIW it is much easier to manage a self-contained library where the media folder is inside the library folder.
    tt2

  • Large file transfer problems over client/server socket

    Hi,
    I wrote a simple chat problem in which I can send files from client to client. The problem is when I send large files over 101 MB the transfer freezes. I do not even get any error mesages in the console. The files I am sending are of any type (Ex mp3, movies, etc...). I am serializing the data into a "byteArray[packetSize]" and sending the file packet by packet until the whole file has been sent, and reconstructed on the other side. The process works perfectly for files smaller than 101MB, but for some reason freezes after that if the file is larger. I have read many forums and there aren't too many solutions out there. I made sure to use the .reset() method to reset my ObjectOutputStream each time I write to it.
    Here's my file sending code:
    byte[] byteArray = new byte[defaultPacketSize];
    numPacketsRequired = Math.ceil(fileSize / defaultPacketSize);
    try {
    int i = 0;
    reader = new FileInputStream(filePath);
    while (reader.available() > 0) {
    if (reader.available() < defaultPacketSize) {
    byte[] lastPacket = new byte[reader.available()];
    reader.read(lastPacket);
    try {
    if (socket == null || output == null) {
    throw new SocketException("socket does not exist");
    output.writeObject(lastPacket);
    output.reset();
    output.writeObject("DONE");
    output.reset();
    output.close();
    socket.close();
    catch (Exception e) {
    System.out.println("Exception ***: " + e);
    output.close();
    socket.close();
    else {
    reader.read(byteArray);
    try {
    if (socket == null || output == null) {
    throw new SocketException("socket does not exist");
    output.writeObject(byteArray);
    output.reset();
    catch (Exception e) {
    System.out.println("Exception ***: " + e);
    output.close();
    socket.close();
    reader.close();
    catch (Exception e) {
    System.out.println("COULD NOT READ PACKET");
    Here's my file receiving code:
    try {
    // The message from the client
    Object streamInput;
    FileOutputStream writer;
    byte[] packet;
    while (true) {
    streamInput = input.readObject();
    if (streamInput instanceof byte[]) {
    packet = (byte[]) streamInput;
    try {
    writer = new FileOutputStream(outputPath, true);
    writer.write(packet); //Storing the bytes on file
    writer.close();
    catch (Exception e) {
    System.out.println("Exception: " + e);
    else if (streamInput.equals("DONE")) {
    socket.close();
    input.close();
    break;
    catch (Exception e) {
    I'm looking for any way I can possibly send large files from client to client without having it freeze. Are there any better file transfer ways other than socket? I don't really want FTP. I think I want to keep it HTTP.
    Any suggestions would be helpful.Thanks!
    Evan

    I've taken a better look a the code you posted, and
    there is one problem with the receiving code. You
    keep repeatedly opening and closing the
    FileOutputStream. This is not going to be efficient
    as the file will keep needing to be positioned to its
    end.Yes sorry I did change that code so that it leaves the file open until completely done writing. Basically I have a progress bar that records how far along in the writing process the client is, and when the progress bar reaches 100%, meaning the file is complete, the file.close() method is invoked. Sorry about that.
    I also ran some memory tests using the "Runtime.getRuntime().totalMemory()", and "Runtime.getRuntime().freeMemory()" methods. I put these methods inside the loop where I read in the file and send it to the client. here's the output:
    Sender's free memory: 704672
    File reader read 51200 bytes of data.
    767548 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 702968
    File reader read 51200 bytes of data.
    716348 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 701264
    File reader read 51200 bytes of data.
    665148 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 699560
    File reader read 51200 bytes of data.
    613948 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 697856
    File reader read 51200 bytes of data.
    562748 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 696152
    File reader read 51200 bytes of data.
    511548 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 694448
    File reader read 51200 bytes of data.
    460348 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 692744
    File reader read 51200 bytes of data.
    409148 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 691040
    File reader read 51200 bytes of data.
    357948 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 689336
    File reader read 51200 bytes of data.
    306748 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 687632
    File reader read 51200 bytes of data.
    255548 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 685928
    File reader read 51200 bytes of data.
    204348 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 684224
    File reader read 51200 bytes of data.
    153148 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 682520
    File reader read 51200 bytes of data.
    101948 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 680816
    File reader read 51200 bytes of data.
    50748 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 679112
    File reader read 50748 bytes of data.
    0 left to read.
    Creating last packet of size: 50748
    Last packet size after setting it equal to byteArray: 50748
    Here's the memory stats from the receiver:
    Receiver's free memory: 639856
    Receiver's total memory: 2842624
    Receiver's free memory: 638920
    Receiver's total memory: 2842624
    Receiver's free memory: 637984
    Receiver's total memory: 2842624
    Receiver's free memory: 637048
    Receiver's total memory: 2842624
    Receiver's free memory: 636112
    Receiver's total memory: 2842624
    Receiver's free memory: 635176
    Receiver's total memory: 2842624
    Receiver's free memory: 634240
    Receiver's total memory: 2842624
    Receiver's free memory: 633304
    Receiver's total memory: 2842624
    Receiver's free memory: 632368
    Receiver's total memory: 2842624
    Receiver's free memory: 631432
    Receiver's total memory: 2842624
    Receiver's free memory: 630496
    Receiver's total memory: 2842624
    Receiver's free memory: 629560
    Receiver's total memory: 2842624
    Receiver's free memory: 628624
    Receiver's total memory: 2842624
    Receiver's free memory: 627688
    Receiver's total memory: 2842624
    Receiver's free memory: 626752
    Receiver's total memory: 2842624
    Receiver's free memory: 625816
    Receiver's total memory: 2842624
    Receiver's free memory: 624880
    Receiver's total memory: 2842624
    Receiver's free memory: 623944
    Receiver's total memory: 2842624
    Receiver's free memory: 623008
    Receiver's total memory: 2842624
    Receiver's free memory: 622072
    Receiver's total memory: 2842624
    Receiver's free memory: 621136
    Receiver's total memory: 2842624
    Receiver's free memory: 620200
    Receiver's total memory: 2842624
    Receiver's free memory: 619264
    Receiver's total memory: 2842624
    Receiver's free memory: 618328
    Receiver's total memory: 2842624
    Receiver's free memory: 617392
    Receiver's total memory: 2842624
    Receiver's free memory: 616456
    Receiver's total memory: 2842624
    Receiver's free memory: 615520
    Receiver's total memory: 2842624
    Receiver's free memory: 614584
    this is just a sample of both receiver and sender's stats. Everything appears to be fine! Hope this message post isn't too long.
    Thanks!

  • Problem with Sending files over Sockets

    Hi. I have a problem when I try to send files over sockets. When I send text files it works well but when I try to send .jpg or other kind of files it doesn't work well because some characters are wrong, I hope you can help me.
    Here is my code:
    //Sender code
    import java.io.*;
    import java.net.*;
    class Servidor{
         Servidor(){
              try{
                   String arch="art.jpg";
                   ServerSocket serv=new ServerSocket(125);
                   Socket socket=serv.accept();
                   System.out.println("Conectado");
                   int c;
                   BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
                   FileInputStream fis=new FileInputStream(arch);
                   File f=new File(arch);
                   bw.write(""+f.length());
                   bw.newLine();
                   bw.flush();
                   System.out.println("Escribiendo");
                   while((c=fis.read())!=-1){
                        bw.write(c);
                   bw.flush();
                   fis.close();
                   System.out.println("Terminado");
                   while(true){
              }catch(Exception e){
                   System.out.println(e);
         public static void main(String arg[]){
              new Servidor();
    //Client code
    import java.io.*;
    import java.net.*;
    class Cliente{
         Cliente(){
              try{
                   Socket socket=new Socket("localhost",125);
                   System.out.println("Conectado");
                   BufferedReader br=new BufferedReader(new InputStreamReader(socket.getInputStream()));
                   long tam=Long.parseLong(br.readLine());
                   long act=0;
                   FileOutputStream fos=new FileOutputStream("resp.jpg");
                   System.out.println("Recibiendo: "+tam);
                   while(act<tam){
                        fos.write(br.read());
                        act++;
                   System.out.println("Terminado: "+act+" / "+tam);
                   fos.close();
              }catch(Exception e){
                   System.out.println(e);
         public static void main(String arg[]){
              new Cliente();
    }

    I don't think you want BufferedReader and OutputStreamWriter, you want ByteArrayOutputStream and ByteArrayInputStream . The problem is that you are sending jpegs (binary data) as text.

Maybe you are looking for

  • Importing Class

    I was reading the tutorial on importing class's. This is what I read Importing classes To reference a class in another script, you must prefix the class name with the class's package path. The combination of a class's name and its package path is the

  • Mail - OSX Lion - Can't change font in mail list

    OSX Lion seems incapable of changing the font in the mail list on the left side. The default is a horrendous, teeny tiny font. Going to Preferences > Fonts and Colors and choosing message list font reveals a font picker. All the other font settings w

  • How to create an interface if the class has a nested class

    I have the following class public class SampleImport{ public SampleResult import (InputSource xml) { SampleResult sampleResult = new SampleResult();           //do something           return sampleResult; public static class SampleResult {           

  • How do i insert into more than one table from temp table?

    Hi, I have three tables such as temp,stck and stol temp table contains data as below. It has 22 columns. STOCK     STOCKDESC     ALIAS1     ALIAS2     ALIAS3     ALIAS4     ALIAS5     ALIAS6     ALIAS7     ALIAS8     ALIAS9     ALIAS10     ALIAS11   

  • Change clock to local time

    How to change clock to local time