JPeg file transfer over network

hello all,
can you tell me how to trasfer a JPEG file to another computer using sockets
thank yoou all

If the JPEG is on the disk just open a FileInputStream, read the JPEG and write it to the OutputStream of the socket.
Read the socket tutorial:
http://java.sun.com/docs/books/tutorial/networking/sockets/readingWriting.html

Similar Messages

  • Help : windows xp to mac os x file transfer over network

    hi folks! ... (sorry for the double post ... in the macbook discussion thread)
    i've recently bought a macbook pro and am in the process of switching predominantly to the mac from my windows pc. I'ld really appreciate a guide/tutorial on how to transfer the files of my pc to my mac over a home network
    okay .. here's wht iv got ..
    1. macbook pro with hardly any data
    2. laptop with windows xp home (which has a lot of my data) (ntfs formatted)
    3. external hard drive with a lot of data (hard drive formatted with ntfs)
    4. Router and wireless connection
    what i want to do ...
    transfer my data from external hard drive & my pc to my mac without using macdrive/macfuse. I want to enable file sharing over the network between the laptop (preferably the external hard disk attached to the laptop) and the macbook pro.
    I haven't done network file sharing before... and it would be really nice if anyone could guide me through it ..
    thanks!
    zambie

    Hi zambie,
    Here is article that might help you out:
    http://www.apple.com/getamac/movetomac/network.html
    basically it is the same between macbookpro and macbook to get file sharing from pc.
    Good Luck.

  • Port 548 Shutting Down File Transfer Over Network

    OK, nobody laugh, but I am trying to transfer some old work files from an ancient PowerBook 3400 (including many on Zip disks) running OS 8.1 to one of our newer machines so we can look through them at our leisure later and save those of interest.
    On the PowerBook, I have successfully connected to both of the new machines (see below) via Chooser and started to copy files to those machines. In the middle of the copy, after a few minutes, I get the following message: 192.168.1.xx:548 "The file server connection has closed down". 192.168.1.xx is the LAN IP address of the receiving machine. Personal File Sharing is allowed, and file permissions have been given to Others in the receiving folder. Do I need to do authorize something on Port 548 to allow the transfer?
    Thanks in advance for any suggestions.
    Bob

    Hi Ralph
    I can see where that might be the case, but file transfer worked flawlessly BEFORE I went wireless using the same modem. The only way to unblock ports on my router is to turn NAT off - it creates a DMZ, so it permits unhindered 2-way traffic...
    It's a pretty confusing piece of kit. Maybe I should just get a Netgear anyway!
    I have a laptop on the wireless network as well, and file transfer works a treat between it and the iMac. All I can think of is that because I'm now working on a LAN, there's a blockage to get out to the "Real World" - even though it's easy for video to pass through.
    I'll check my unblocked ports again, just to be sure. I'm unfamilar with the term "Jabber" - is that what Apple decided to call one of the elements of iChat? Excuse my ignorance...!

  • File Transfer Over Network Problem since 10.4.9 Update

    Since the update I've had this problem. Here's a typical operation:
    In a finder window, from my PowerMac G5, I click on Network and mount a disk from another Mac on the Network (Intel Mac Mini). I navigate to that mounted disk and drag a 1.5GB file from it to a directory on my G5.
    This used to take a couple of minutes before the update. Now it takes over 4 hours! My network looks like this:
    Intel mac Mini (10.4.9) hard-wired to new Airport Extreme 802.11n
    PowerMac G5 (10.4.9) hard-wired to new Airport Extreme 802.11n
    Pwerbook (10.4.8) Wi-Fied to new Airport Extreme 802.11n
    I don't understand why this is happening or how to correct this problem. Any help would be greatly appreciated since I do this operation frequently and 4+ hours is totally unacceptable.
    Thanks!
    G5 2.5gHz PowerMac, Mac Mini Core Duo, G3 400mHz Powerbook   Mac OS X (10.4.9)  

    I found out that about the same time as the update one of my five external hard drives started going south on me. When it got to the point of no return where it wouldn't mount any more I took it off the Mac. The network is running fast and fine now. For some reason the drive was slowing everything up. Weird.

  • When upgrading to OSX Yosemite do all my programs and files transfer over such as Office for mac, saved documents from word,excel,pics,pdf files,etc.etc...

    Will all my files transfer over (or stay) automatically right after upgrading to Yosemite or do I have to backup every single desired program or document? Question is do I HAVE to please if you can answer if its mandatory or not. Not looking for recommendations that I SHOULD back up or anything like that just want to know if it is mandatory to perform a backup to be able to keep or transfer all my current programs and apps and documents currently on my MB Pro Retina.

    Yes, upgrading to Yosemite will not touch your 3rd party apps or files in the Home folder.
    Although not mandatory you should have a a backup of your hard drive regardless if you upgrade to Yosemite or not.  To not have a backup is just playing  Russian roulette as there are only two types of hard drives;  those that have failed and those that will.

  • Files deleted over network

    Hi, some of users over the network accidentally deleted a folder from XServe, and he asked if it can be recovered, when someone deletes a file/folder over network OSX reports that "the item will be deleted immediately", is this true? it wont going to be stored in some "Network Trash Folder"? or ".Trashes"? or "Temporary Items"??
    And if it really wont be recovered, is there a way to prevent this in the future? like to tell OSX Server to put all the files/folders deleted over network to be stored in a special folder for a certain time to prevent loosing important files accidentally or by other users??
    Thanks

    Bertrand> This seems a nice idea, but its not exactly what i need, people still need to delete files from the server, but sometimes they delete important things and im looking for a way that the OSX Server keeps the remotely deleted file for a certain amount of time so it can be restored if needed. many times users accidentally delete files from the server and hit the "OK" button without noticing they just delete an important file from the server and not from there HD, for example, in Apple Share IP on OS9 if you delete a file over the network it would keep it in the user Trash and he empties it, and if he for example restarted his computer, the file on the ASIP would be stored in "Network Trash Folder".. why the mighty OSX Server doest have this great ability?!
    Steve> Tapes is great for backup and archiving, but its not what i am really looking for, it has the same problem i have with Time Machine, time machine wont backup a file copied to the server and accidentally deleted within an hour, so Tapes, wont backup a file copied and deleted within a day..
    WelshDog2> just a question: if i dont have any partition on my XRAID, how can i make it backup its self on its own HD's?! is this possible?! it wont solve my problem but its good to know if this can be done..
    Thank you all guys for your replies, i really appreciate it..

  • IChatAV and file transfer over wireless network

    Hi there...
    I'd like to let you in on my predicament. Firstly, a bit of background.
    I decided to buy my folks an old iMac from eBay in Australia - and pay for their broadband connection - so that I could video chat to them from the UK, and they could see my 5 year old son for the first time in 4 years. Cute, eh?
    Well, everything was working fine until I decided to go wireless in my home about 3 months ago. I have a static IP address, and purchased a nice new Airport Express to integrate into the system. I allocated my G5 iMac it's own network address (10.0.1.2), and the base station the master address (10.0.1.1). From there, the base station communicates to the router via the static IP... Sound ok?
    Anyway - NOW (or, for as long as I can recall), I CANNOT for the life of me send files over the connection. Video chat and audio chat are fine (although OCCASIONALLY it takes a few goes to be able to see THEM on my computer - I think their bandwidth isn't THAT stable at 512Kbps down and 128Kbps up) - however, the correct ports have been unblocked on the OSX firewall AND the Airport Express base station.
    And just so that you know it's not the folks' fault - I can't send documents/images over the network to friends I KNOW are competent (or, at least more competent than my parents!). There's always an error message at the receiver's end, and the file I'm attempting to send just times out.
    Has anyone any suggestions as to how I might be able to resolve this problem before I expire from old age?!?
    Your thoughts are REALLY appreciated!

    Hi Ralph
    I can see where that might be the case, but file transfer worked flawlessly BEFORE I went wireless using the same modem. The only way to unblock ports on my router is to turn NAT off - it creates a DMZ, so it permits unhindered 2-way traffic...
    It's a pretty confusing piece of kit. Maybe I should just get a Netgear anyway!
    I have a laptop on the wireless network as well, and file transfer works a treat between it and the iMac. All I can think of is that because I'm now working on a LAN, there's a blockage to get out to the "Real World" - even though it's easy for video to pass through.
    I'll check my unblocked ports again, just to be sure. I'm unfamilar with the term "Jabber" - is that what Apple decided to call one of the elements of iChat? Excuse my ignorance...!

  • Problem with file transfer over the net

    Hi!I'm trying to make a program that allows to send/receive files and I'm almost done,except for a little problem:the file received has some bytes missing at the end!
    For example if I send a text the last 2-3 lines are missing,same thing for an image,an html document,etc.,although the file opens without any problem.As transport-level protocol I'm using TCP so it's not a networking problem,I think the problem is in the application layer so I post here the code,hoping someone helps me out(in this example I'm trying to send an image .jpg):
    Sender:
    Socket connectionSocket=new Socket("ipadress",port);
    FileInputStream source=new FileInputStream(System.getProperty("user.home")+"\\Documents\\image.jpg");
    BufferedOutputStream send=new BufferedOutputStream(connectionSocket.getOutputStream());
    int c;
    while ((c = source.read()) !=-1)
                    send.write(c1);
    Receiver
    ServerSocket receiverSocket=new ServerSocket(port);
    Socket  connection=receiverSocket.accept();
    BufferedInputStream rec=new BufferedInputStream(connection.getInputStream());
    FileOutputStream receivedFile=new FileOutputStream(System.getProperty("user.dir")+"\\received.jpg");
    int c;
    while ((c = rec.read()) != -1)
                    receivedFile.write(c);I think the problem is in this code:somehow the sender stops sending bytes before the end of the file is actually reached...what do u think?

    Thank you so much!At the end it was a very stupid mistake!:D
    Btw now that the main problem is solved I continue posting asking for your opinion:is this program for you efficient enough?Or there's a better way to do file transfer?

  • File loss over network on Mac Pro /windows

    Hi I hope someone can help, I have been using my network for over a year with no problems also networked the same for the last 4 years.
    I now have files and folders go missing when dragging between computers I have one mac pro and x2 windows computers vista & 7.
    The network is set up so I have the windows set up for emails and downloading files - I then transfer to the mac, I work on them and drag them over to the windows vista which runs the rip for my large format printer.
    I have a shared folder on each pc which all the computers can read/write.
    When i drag files and more often folders from the windows 7 to the mac they will not show on the mac but are sitting in the shared folder. when i drag from the mac to the windows vista I sometimes can't see anything in the shared folder (other times a few things) but I can't add folders or drag files over without them going missing. there is no logic or pattern to what i get so if this make any sense i really could do with the help!
    thanks ali

    The new user helped a little but not enough to make the customer happy. I have done a bunch of research over the weekend and I have found there is a little known bug in Apple's ACLs. ACL stands for Access Control List and I have a snippet from a MacFixit that describes the issue:
    "A disappointing aspect of Repair Permissions in Leopard is that it does not deal with ACLs (Access Control Lists), a secondary layer of permissions control laid on top of standard Unix permissions, tentatively introduced in Tiger and actually used for the first time in Leopard. Repair Permissions will announce that it is surprised to discover that a certain folder has an unexpected ACL setting, but it won't do anything about it (in other words, it won't repair that kind of permissions)."
    Anyway it appears to me that if your privileges get hosed in a computer upgrade the only way to really fix the problem is copy all of your data to a second HD and then break out the install DVDs that came with the Mac Pro and do a fresh install and set the user/file-sharing up manually and then copy your data back to the Mac Pro. I did not connect back to the G4 to get the data again, I just copied my many years of correspondence back to the Mac Pro and this time everything works?
    The new user idea did let me manually drop files onto the Mac Pro from connected computers it WOULD NOT let me save files to the Mac Pro from network computers. I usually got a bad path message when I would try and save from Word or TextEdit. I figured I had wasted enough time on this problem and erasing everything and starting over was a better idea.
    Thanks everybody.

  • Quark files corrupting over network

    I run 3 macs - a mini, a g4 imac and an old g3. All are running 10.4.7. When I transfer quark 6.5 documents over the network, they corrupt. After being transferred, they always cause quark to quit unexpectedly (although it's never all that unexpected when quark quits suddenly). If I repair permissions or run ONYX to clean things up, the files are suddenly OK!
    Any ideas?

    Check permissions on one of those files before and after running repair permissions. You should be able to see what has changed. Then you will know what is giving Quark fits. You might be able to write an Automator script to fix the files so Quark doesn't die.

  • XML file transfer over the web

    A company is sending us an XML file via push technology and visual basic:
    'Set up to post to client server
    objHTTP.Open "post", “http://someURL.company.com”,
    'Set a standard XML header for the content-type
    objHTTP.setRequestHeader "Content-Type", "text/xml"
    'Send the XML.
    objHTTP.send cXML
    'Get the return message
    cClientReturn = objHTTP.responseText
    nStatus = objHTTP.Status
    cStatusText = objHTTP.statusText
    What is the best way to receive the XML from our company's end. We want to use PL/SQL code? Is Advanced Queuing a possible solution. What is the most eficient and straightforward solution?
    Thanks,
    JD

    It depends on the # of concurrent requests and what you plan to do with the doc.
    Two choices:
    1) Use XMLDB HTTP server: leverages XML DB data management (straight-forward and simple)
    2) Use OracleAQServlet: provides asynchronous message queuing

  • How to increase the speed of network file transfer

    hi ,
    In my application i want to use the file from one system to another system.
    i am using stream reader to get the file over the network , its working fine for small file,
    but i want to access file size exceed 10 MB then i faced the problem. Its get very slow the file transfer over the network.
    so i am try to use java NIO for transfer file,
    Using NIO , While i am make server and client both are same system then the file tranfer is 10MB file in 10 seconds , but i am making server and client are different machine then its take so long to transfer file ie (10 MB file in 3 minutes).
    I want to reduce the time . If any chance to reduced the file transfer time then please suggest me.
    my code is
    Server Code :
    public class NioServer implements Runnable {
      // The host:port combination to listen on
      private InetAddress hostAddress;
      private int port;
      // The channel on which we'll accept connections
      private ServerSocketChannel serverChannel;
      // The selector we'll be monitoring
      private Selector selector;
      // The buffer into which we'll read data when it's available
      private ByteBuffer readBuffer = ByteBuffer.allocate(10000);
      private EchoWorker worker;
      // A list of PendingChange instances
      private List pendingChanges = new LinkedList();
      // Maps a SocketChannel to a list of ByteBuffer instances
      private Map pendingData = new HashMap();
      public NioServer(InetAddress hostAddress, int port, EchoWorker worker) throws IOException {
        this.hostAddress = hostAddress;
        this.port = port;
        this.selector = this.initSelector();
        this.worker = worker;
      public void send(SocketChannel socket, byte[] data) {
        System.out.println("Server Send ");
        synchronized (this.pendingChanges) {
          // Indicate we want the interest ops set changed
          this.pendingChanges.add(new ChangeRequest(socket, ChangeRequest.CHANGEOPS, SelectionKey.OP_WRITE));
          // And queue the data we want written
          synchronized (this.pendingData) {
            List queue = (List) this.pendingData.get(socket);
            if (queue == null) {
              queue = new ArrayList();
              this.pendingData.put(socket, queue);
            queue.add(ByteBuffer.wrap(data));
        // Finally, wake up our selecting thread so it can make the required changes
        this.selector.wakeup();
      public void run() {
        while (true) {
          try {
            // Process any pending changes
            synchronized (this.pendingChanges) {
              Iterator changes = this.pendingChanges.iterator();
              while (changes.hasNext()) {
                ChangeRequest change = (ChangeRequest) changes.next();
                switch (change.type) {
                case ChangeRequest.CHANGEOPS:
                  SelectionKey key = change.socket.keyFor(this.selector);
                  key.interestOps(change.ops);
              this.pendingChanges.clear();
            // Wait for an event one of the registered channels
            this.selector.select();
            // Iterate over the set of keys for which events are available
            Iterator selectedKeys = this.selector.selectedKeys().iterator();
            while (selectedKeys.hasNext()) {
              SelectionKey key = (SelectionKey) selectedKeys.next();
              selectedKeys.remove();
              if (!key.isValid()) {
                continue;
              // Check what event is available and deal with it
              if (key.isAcceptable()) {
                this.accept(key);
              } else if (key.isReadable()) {
                this.read(key);
              } else if (key.isWritable()) {
                this.write(key);
          } catch (Exception e) {
            e.printStackTrace();
      private void accept(SelectionKey key) throws IOException {
        System.out.println("Server Accept ");
        // For an accept to be pending the channel must be a server socket channel.
        ServerSocketChannel serverSocketChannel = (ServerSocketChannel) key.channel();
        // Accept the connection and make it non-blocking
        SocketChannel socketChannel = serverSocketChannel.accept();
        Socket socket = socketChannel.socket();
        socketChannel.configureBlocking(false);
        // Register the new SocketChannel with our Selector, indicating
        // we'd like to be notified when there's data waiting to be read
        socketChannel.register(this.selector, SelectionKey.OP_READ);
      private void read(SelectionKey key) throws IOException {
        System.out.println("server Read : ");
        SocketChannel socketChannel = (SocketChannel) key.channel();
        // Clear out our read buffer so it's ready for new data
        readBuffer.clear();
    //    readFully( readBuffer , socketChannel ) ;
        // Attempt to read off the channel
        int numRead;
        try {
          numRead = socketChannel.read(readBuffer);
        } catch (IOException e) {
          // The remote forcibly closed the connection, cancel
          // the selection key and close the channel.
          key.cancel();
          socketChannel.close();
          return;
        if (numRead == -1) {
          // Remote entity shut the socket down cleanly. Do the
          // same from our end and cancel the channel.
          key.channel().close();
          key.cancel();
          return;
        // Hand the data off to our worker thread
        this.worker.processData(this, socketChannel, this.readBuffer.array(), numRead);
      private void write(SelectionKey key) throws IOException {
        System.out.println("Server Write ");
        SocketChannel socketChannel = (SocketChannel) key.channel();
        synchronized (this.pendingData) {
          List queue = (List) this.pendingData.get(socketChannel);
          // Write until there's not more data ...
          while (!queue.isEmpty()) {
            ByteBuffer buf = (ByteBuffer) queue.get(0);
            socketChannel.write(buf);
            if (buf.remaining() > 0) {
              System.out.println( "buf.remaining() " + buf.remaining() ) ;
              // ... or the socket's buffer fills up
              break;
            queue.remove(0);
          if (queue.isEmpty()) {
            // We wrote away all data, so we're no longer interested
            // in writing on this socket. Switch back to waiting for
            // data.
            key.interestOps(SelectionKey.OP_READ);
      private Selector initSelector() throws IOException {
        // Create a new selector
        Selector socketSelector = SelectorProvider.provider().openSelector();
        // Create a new non-blocking server socket channel
        this.serverChannel = ServerSocketChannel.open();
        serverChannel.configureBlocking(false);
        // Bind the server socket to the specified address and port
        InetSocketAddress isa = new InetSocketAddress(this.hostAddress, this.port);
        serverChannel.socket().bind(isa);
        // Register the server socket channel, indicating an interest in
        // accepting new connections
        serverChannel.register(socketSelector, SelectionKey.OP_ACCEPT);
        return socketSelector;
      private static void readFully(ByteBuffer buf, SocketChannel socket) throws IOException
        int len = buf.limit() - buf.position();
        while (len > 0)
          len -= socket.read(buf);
      public static void main(String[] args) {
        try {
          EchoWorker worker = new EchoWorker();
          new Thread(worker).start();
          new Thread(new NioServer(null, 9090, worker)).start();
        } catch (IOException e) {
          e.printStackTrace();
    }Client Code :
    public class NioClient implements Runnable {
      // The host:port combination to connect to
      private InetAddress hostAddress;
      private int port;
      // The selector we'll be monitoring
      private Selector selector;
      // The buffer into which we'll read data when it's available
      private ByteBuffer readBuffer = ByteBuffer.allocate( 10596 ) ;
      // A list of PendingChange instances
      private List pendingChanges = new LinkedList();
      // Maps a SocketChannel to a list of ByteBuffer instances
      private Map pendingData = new HashMap();
      private byte[] bufferByteA = null ;
      // Maps a SocketChannel to a RspHandler
      private Map rspHandlers = Collections.synchronizedMap(new HashMap());
      public NioClient(InetAddress hostAddress, int port) throws IOException {
        this.hostAddress = hostAddress;
        this.port = port;
        this.selector = this.initSelector();
      public void send(byte[] data, RspHandler handler) throws IOException {
        // Start a new connection
        SocketChannel socket = this.initiateConnection();
        // Register the response handler
        this.rspHandlers.put(socket, handler);
        // And queue the data we want written
        synchronized (this.pendingData) {
          List queue = (List) this.pendingData.get(socket);
          if (queue == null) {
            queue = new ArrayList();
            this.pendingData.put(socket, queue);
          queue.add(ByteBuffer.wrap(data));
        // Finally, wake up our selecting thread so it can make the required changes
        this.selector.wakeup();
      public void run()
        while (true)
          try
            // Process any pending changes
            synchronized (this.pendingChanges)
              Iterator changes = this.pendingChanges.iterator();
              while (changes.hasNext())
                ChangeRequest change = (ChangeRequest) changes.next();
                switch (change.type)
                  case ChangeRequest.CHANGEOPS:
                    SelectionKey key = change.socket.keyFor(this.selector);
                    key.interestOps(change.ops);
                    break;
                  case ChangeRequest.REGISTER:
                    change.socket.register(this.selector, change.ops);
                    break;
              this.pendingChanges.clear();
            // Wait for an event one of the registered channels
            this.selector.select();
            // Iterate over the set of keys for which events are available
            Iterator selectedKeys = this.selector.selectedKeys().iterator();
            while (selectedKeys.hasNext())
            System.out.println( " ----run 5 " ) ;
              SelectionKey key = (SelectionKey) selectedKeys.next();
              selectedKeys.remove();
              if (!key.isValid())
                continue;
              // Check what event is available and deal with it
              if (key.isConnectable())
                this.finishConnection(key);
              else if (key.isReadable())
                this.read(key);
              else if (key.isWritable())
                this.write(key);
          catch (Exception e)
            e.printStackTrace();
      private void read(SelectionKey key) throws IOException {
        System.out.println( "---------read 1 " ) ;
        SocketChannel socketChannel = (SocketChannel) key.channel();
        // Clear out our read buffer so it's ready for new data
        this.readBuffer.clear();
        System.out.println( "---------read 2 " + readBuffer.capacity()) ;
         readBuffer = ByteBuffer.allocate( bufferByteA.length  ) ;
        // Attempt to read off the channel
    //    int numRead;
        try {
    //      numRead = socketChannel.read(this.readBuffer);
          readFully( readBuffer , socketChannel ) ;
        } catch (IOException e) {
          // The remote forcibly closed the connection, cancel
          // the selection key and close the channel.
          key.cancel();
          socketChannel.close();
          return;
    //    if (numRead == -1) {
    //      // Remote entity shut the socket down cleanly. Do the
    //      // same from our end and cancel the channel.
    //      key.channel().close();
    //      key.cancel();
    //      return;
        // Handle the response
        this.handleResponse(socketChannel, this.readBuffer.array(), readBuffer.capacity() );
      private void handleResponse(SocketChannel socketChannel, byte[] data, int numRead) throws IOException {
        // Make a correctly sized copy of the data before handing it
        // to the client
        byte[] rspData = new byte[numRead];
        // Look up the handler for this channel
        RspHandler handler = (RspHandler) this.rspHandlers.get(socketChannel);
        // And pass the response to it
        if (handler.handleResponse(rspData)) {
          // The handler has seen enough, close the connection
          socketChannel.close();
          socketChannel.keyFor(this.selector).cancel();
      private void write(SelectionKey key) throws IOException {
        SocketChannel socketChannel = (SocketChannel) key.channel();
        readBuffer.flip() ;
        List queue = null ;
        synchronized (this.pendingData) {
          queue = (List) this.pendingData.get(socketChannel);
          writeFully( readBuffer , socketChannel ) ;
          // Write until there's not more data ...
          while (!queue.isEmpty()) {
    //        ByteBuffer buf = (ByteBuffer) queue.get(0);
    //        socketChannel.write(buf);
    //        writeFully( buf , socketChannel ) ;
    //        if (buf.remaining() > 0) {
    //          // ... or the socket's buffer fills up
    //          break;
            queue.remove(0);
          if (queue.isEmpty()) {
            // We wrote away all data, so we're no longer interested
            // in writing on this socket. Switch back to waiting for
            // data.
            key.interestOps(SelectionKey.OP_READ);
      private void finishConnection(SelectionKey key) throws IOException {
        SocketChannel socketChannel = (SocketChannel) key.channel();
        // Finish the connection. If the connection operation failed
        // this will raise an IOException.
        try {
          socketChannel.finishConnect();
        } catch (IOException e) {
          // Cancel the channel's registration with our selector
          System.out.println(e);
          key.cancel();
          return;
        // Register an interest in writing on this channel
        key.interestOps(SelectionKey.OP_WRITE);
      private SocketChannel initiateConnection() throws IOException {
        // Create a non-blocking socket channel
        SocketChannel socketChannel = SocketChannel.open();
        socketChannel.configureBlocking(false);
        // Kick off connection establishment
        socketChannel.connect(new InetSocketAddress(this.hostAddress, this.port));
    //    socketChannel.finishConnect() ;
        // Queue a channel registration since the caller is not the
        // selecting thread. As part of the registration we'll register
        // an interest in connection events. These are raised when a channel
        // is ready to complete connection establishment.
        synchronized(this.pendingChanges) {
          this.pendingChanges.add(new ChangeRequest(socketChannel, ChangeRequest.REGISTER, SelectionKey.OP_CONNECT));
        return socketChannel;
      private Selector initSelector() throws IOException {
        // Create a new selector
        return SelectorProvider.provider().openSelector();
      public static void main(String[] args) {
        try {
          NioClient client = new NioClient(InetAddress.getByName("healsoft1"), 9090);
          Thread t = new Thread(client);
          t.setDaemon(true);
          t.start();
          RspHandler handler = new RspHandler();
          client.readBytesFromFile( handler ) ;
        } catch (Exception e) {
          e.printStackTrace();
      private void readBytesFromFile( RspHandler handler ) throws IOException
        File file = new File( "Y:/output.txt") ;
        bufferByteA = getBytesFromFile( file ) ;
        readBuffer = ByteBuffer.allocate(bufferByteA.length ) ;
        readBuffer.put( bufferByteA , 0 , bufferByteA.length ) ;
        send(bufferByteA , handler);
        handler.waitForResponse();
      private static void readFully(ByteBuffer buf, SocketChannel socket) throws IOException
        System.out.println( "readFully  : " ) ;
        int len = buf.limit() - buf.position();
        int count = 0 ;
        while (len > 0)
          len -= socket.read(buf);
      private void writeFully(ByteBuffer buf , SocketChannel socketChannel) throws IOException
        System.out.println( "writeFully  : " ) ;
        int len = buf.limit() - buf.position() ;
        SocketChannel socket = socketChannel ;
        socket.open();
        while (len > 0)
          len -= socket.write(buf);
      private static byte[] getBytesFromFile(File file) throws IOException
        InputStream is = new FileInputStream(file);
        // Get the size of the file
        long length = file.length();
             * You cannot create an array using a long type. It needs to be an int
             * type. Before converting to an int type, check to ensure that file is
             * not loarger than Integer.MAX_VALUE;
        if (length > Integer.MAX_VALUE)
          System.out.println("File is too large to process");
          return null;
        // Create the byte array to hold the data
        byte[] bytes = new byte[(int)length];
        // Read in the bytes
        int offset = 0;
        int numRead = 0;
        while ( (offset < bytes.length)
                ( (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) )
                offset += numRead;
        // Ensure all the bytes have been read in
        if (offset < bytes.length)
          throw new IOException("Could not completely read file " + file.getName());
        is.close();
        return bytes;
      public static String printTimeWithMilliSec(long l )
        Date date = new Date( l ) ;
        SimpleDateFormat f = new SimpleDateFormat("HH:mm:ss SSS");
        return f.format(date);
    }

    Data transfer rate for a single client is unlikely to be effected by using NIO or old blocking IO. The important factor is the maximum transfer rate you can get between the sender and receiver.
    You should be able to get 0.5-1.0 MB per second for each 10 Mbit per second of available bandwidth. Your timings suggest you are getting about a 10-20 Mbit/s link speed.

  • Tiger Updates Have Broken Airport Appleshare File Transfer, Horribly Slow

    Big horrible slowdowns in file transfer over wireless have me pulling my (remaining) hair out. I have seen several other posts and here are results of what I found. Hope you can add some suggestions.
    I had given my Apple Airport base station (b) to my brother in Pakistan after I found a Belkin (g) at Staples for free (after rebates) and have been using it for a while (maybe almost 2 years). Not a pretty box but the price is beautiful and it works OK.
    My real use for it is for my eMac and a couple of older PowerBooks I keep downstaors as a "music studio" for my music and podcast recording (and transferring upstairs to my server folder over wireless) and web browsing.
    All worked OK as I would transfer the files to my PowerBook upstairs (connected Ethernet to a router connected to the wireless router or sometimes directly via Airport connection if laptop was not at my desk). Both configurations worked fine (only limitation being my eMac's (b) speed older Airport speed).
    Since 10.4.4 or 10.4.5 (as that is the last "change" I can see made on my system overall, I have discpovered I cannot even transfer a 3.5 MB file from the 10.4.5 eMac to ANY of the other machines.
    After reading several threads here it seems several people have noticed the HORRIBLE SLOWDOWN if not complete death of Airport usability for file transfer. People are being made to go around changing router settings, channel IDs etc. That sounds like typical tech support bunk to me.
    After all, if the channel ID on the wireless router is a problem why is my web browing going on at normal speed but a 120 MB file transfer just told me it will take 2023642128 hours. No, I am not kidding. That is the time it would take to get man to Mars.
    Someone else was told to hook up the machines over Ethernet. Sure, that works for machines in the same room - and is a bearable temporary solution in that case - but not in an upstairs/downstairs situation. Burning CD-Rs to transfer 120 MB files every time is also not a good way to show off Apple technology.
    So, in my humble opinion, some recent update from Apple just broke something in Airport networking or Appleshare. So, I did some more testing.
    I love Apple, getting friends to switch all the time, but annoyed at these bugs that basically render standard applications unusable. So far I have not been able to figure out what the problem is. Here is some more info I got.
    I already deleted all the network port configurations on the 10.4.5 eMac except wireless. Activity Monitor shows 0.1 to 11 kbps speed (yes, that is 0.1 to 11 Kbps not Mbps). No other apps are running, Tried connecting to different machines. All machines can transfer data at high speed except over Airport/wireless.
    I then fired up a PowerBook G3 500 10.3.9. It is slow as a machine, but it has no problems picking and dropping files on to other machines over Airport (it is sitting in the same area as the emac so signal etc. issues would effect them equally).
    Next I came upstairs and changed my 10.4.5 PowerBook G4, previously working perfectly on Ethernet,to Airport only use. Lo and behold, it could not go to the Internet nor could it do any AppleShare transfers even with a PowerMac G4 which is Ethernet only.
    There could still be two culprits, the Apple 10.4.5 update OR maybe the wireless router went bad. So I tried all of the above after changing channels on the Belkin router. Still no luck.
    It could still be the router, so:
    - I changed the HP 17" 8080 laptop from Ethernet to wireless only and it flies.
    - I switched the PowerBook G4 BACK to Ethernet and it flies.
    - I kept the PC laptop on WIRELESS and did file transfers from it to the now ETHERNET using PowerBook G4 and it works fine even PowerBook to PC and PowerBook to PowerMac both using Ethernet and 10.4.5 works fine too.
    - I now tried to get or put files from the 10.4.5 ETHERNET PowerBook G4 to PowerBook G3 10.3.9 WIRELESS and it worked fine. i.e. no problems with older OS one using wireless.
    - Then I tried 10.4.5 PowerBook G4 Ethernet to eMac wireless 10.4.5 and it would not take or drop a file, unless I was willing to wait for 3 years and 2 months.
    In other words - the ONLY common thread is that 10.4.5 with wireless/Airport use will break Appleshare file transfers.
    Obviously some planetary confluence did not suddenly corrupt all the settings in all my computers at the same as many others, who also happen to be using 10.4.5 or maybe 10.4.4 because the 10.3.9 using OLD PowerBook with 512 MB RAM does wireless file transfers faster than the 10 times faster Macs using Apple's own cards and newest software.
    Seems like a now-becoming-usual Apple update that breaks things.
    Hope you can suggest a solution so I do not have to burn CDs on the eMac for every 1 MB file I need to transfer upstairs.
    Imran

    Oosted on macfixit.com Friday, February 24 2006 @ 09:30 AM PST
    Mac OS X 10.4.5 (#9): Another fix for network slowness -- re-applying the combo updater; SIIG FireWire card not working; more
    Another fix for network slowness -- re-applying the combo updater Over the past few days we've outlined a number of fixes for network slowness that occurs after the update to Mac OS X 10.4.5, including entry of a DNS address, toggling of IPv6 and more.
    We've now received notes indicating that a tried and true workaround for various issues -- re-applying the Mac OS X 10.4.5 combo updater (as noted in our general workarounds for 10.4.5) -- can have beneficial effects in this case as well.
    MacFixIt reader Fred Moore writes:
    "After much thrashing about and wasted time, I appear to have solved both the slow web page loading as well as my email sending problems in one stroke. Guess how: download the Mac OS X 10.4.5 combo updater and reapply it. This nonsense has cost me a lot of time but everything seems to work now. IPv6 is set back to Automatic, there is no entry in the Network prefs DNS server field, and my email sending works perfectly (so far; I've sent a bunch of tests). Why didn't I just download the combo updater and apply from my hard drive at the beginning? Well, Software Update should (yes, I know, I know...) work. I'll never again use Software Update for a system update."

  • Why is my Raw file shrinking so much when I save it as a JPEG file?

    Why does my file size shrinks from a raw file of over 12MB to a large Jpeg file of less than 6MB.  Several weeks ago when I converted the same raw file I was ending up with a JPEG file of over 9MB.  What am I doinf wrong?  How can I correct this?  I am using Elements 9.

    Because JPGs are compressed, the JPG file size is not a meaningful indicator of image quality or "doing something wrong". You are advised to ignore it.

  • How to transfer images over network?

    Hello,
    I've built a program in LV 7.1 which taking a snap shot from a USB webcam and save it as JPEG file.
    As I already said I am using LV 7.1 with NI VISION 7.1.
    My program has to take the picture from the webcam and send it via serial visa connection. (TCP \ IP is also an option)
    Regards,
    Rotem

    There are lots of ways to transfer files over the network. The easiest, in my opinion, is to use TCP/IP and set up a network share or mapped drive between the two machines and then transfer the file by using copy. Of course, there are lots of situations where setting up a network share isn't apropriate.
    If network share isn't an option, and you want to use serial, you should probably use a protocol such as Xmodem, Ymodem or Zmodem to transfer the file. LabVIEW doesn't have direct support for these protocols, although I know someone sells (or at least used to sell, I couldn't find it with a quick search) a modem toolkit for LabVIEW with these protocols implemented. There are also ActiveX servers that implement these protocols that you could download or purchase and then access from LabVIEW.
    If you want to go the TCP/IP route, an FTP server would be an easy option. You'd need to run an FTP server on the target machine, but then you could just use the LabVIEW FTP VIs or call an FTP terminal through command line or ActiveX.
    Of course, you could implement your own file transfer protocol using VISA, datasocket or the TCP/IP VIs, but this last option is quite a bit of work to solve a problem when there are plenty of programs out there to solve it for you. Re-inventing the wheel if you will. While it's not all that difficult to read in a file, transfer it using one of the communication APIs, and then write it back to a file on your client machine, you'll either have to implement, or go without, a lot of the features and safeguards, like error checking, which are built into other file transfer protocols. Also, remember that you'll have to have a LabVIEW application running on each end, so you'll have to implement both halves of the solution (as opposed to options like FTP or the network share, where you only have to run a VI on one computer).
    Hope that helps,
    Ryan K.

Maybe you are looking for

  • MacBook - problems with iPhoto slideshow music

    Just got my brand new MacBook today and imported everything from old PowerBook. However now that I am trying to play a slideshow in iPhoto, the music to it will not play. Yet it will play in iTunes app itself, but not within the slideshow in iPhoto?

  • Manual bank statement -  report

    Hi SAP Gurus, Is there any standard report in SAP which can pull out the entries maintained through manual bank statement, the business transactions used for a year?? Regards, SATVIR SINGH

  • Migrating a project from Flex 4.1 to 4.6

    Hello all, Is there a better way to migrate an existing project from 4.1 to 4.6 than just copying the project files over to a new mobile project, recompiling and removing a lot of errors one by one? Thanks

  • CS6 Help Doesn't Work in Local mode

    Hi, I have downloaded the trial and installed it Mac OS Lion. The help application does not work; the omly thing that it will display is the settings window. After downloading local content and clicking done, the window disappears, but when you click

  • Itunes problems with windows?

    after installing Itunes 10.5 on Win 7 64 system, the store cannot be accessed - blank screen only.