How can you use multiple stream types with one socket?

Hi,
I'm working on a large program that currently uses Object Input/Output streams for all of the messaging in a client/server application. This works fine except when files need to be transferred. In many cases using a Object stream to send a file can be 30 times slower than using a Buffered input/output stream. I've found I can combined the two. Here are some code snippets to give you a basic idea of what's happening...
BufferedInputStream bis = new BufferedInputStream( serverSocket.getInputStream( ) );
ObjectInputStream ois = new ObjectInputStream( serverSocket.getInputStream( ) );
//this code runs on a thread on the server
while( true ){
switch( whichKindOfStreamUsedNext ){
case OBJECT_STREAM:
Object object = ois.readObject( );
doSomethingWithObject( object );
break;
case BUFFERED_STREAM:
readFromBuffer( bis );
break;
Obviously there is a lot missing here. Basically the variable whichKindOfStreamUsedNext is changed in the methods doSomethingWithObject( ) and readFromBuffer depending on what the current state of the server is and what is passed to these methods from the client.
Here is the problem. If readFromBuffer( ) does a very small task and the client sends an object through an object stream everything is okay. I've switched whichKindOfStreamUsedNext = OBJECT_STREAM before that point and by the time the client sends the object the server is waiting on Object object = ois.readObject( );. However if the method readFromBuffer( ) does a very time intensive task and it takes a while to return and meanwhile the client sends an object then the server never gets that object. Does anyone have an easy solution to this problem. (Changing the whole program to just using BufferedStreams is not a solution).
Thanks.

Thanks a lot for the response.
I guess I didn't realize I could do that.
I changed how I am doing the program anyways. Sending flags to switch streams was a little messy. but now I have a new problem. I've discovered that mixing object streams with buffered streams also leads to significant speed increases. I do that in this manner...
int ONE_MEG = 1024*1024;
ObjectInputStream ois = new ObjectInputStream( new BufferedInputStream( socket.getInputStream( ), ONE_MEG ) );
and I do the same thing for the ObjectOutputStream. It works very well when I just set up the client's output stream and the servers input stream in this manner. Upload times are increased from 60 seconds to 2-5 seconds.
Unfortunately when I try to do the same thing with the servers output stream and the clients input stream to speed up downloads I get deadlock! As soon as the socket connection is opened and I try to set up the streams in this manner I get deadlock. Does anyone have any idea why this occurs and what I can do to fix it?

Similar Messages

  • Can you have multiple iCloud's with one Apple ID?

    Can you have multiple iCloud's with one Apple ID?

    You can have multiple iclouds with multiple id's

  • How can you combine multiple PDF pages into one searchable PDF page?

    I have scanned multiple business cards and now have a PDF  file with over 500 pages (or cards). I would like to be able and create a  page with 8 cards to a page and is still searchable for text. Right now, the text is searchable. Basically have 63 pages and not 500.
    Example:
    If I wanted to find Joe Smith's card, I could search for  "Joe Smith" and it would search all of the text and bring me to the  page(s). Right now, it will bring me to that page. Is there a way to create  a page where I can have multiple cards and the text is still searchable?
    I tried to create a page in Photoshop, made 8 different layers with 8  different cards, but when saved, not only was the file way too large, but no text, or font, was detected  and there was nothing to  search for.
    Is there an option to create a page in Acrobat Professional and put 8 cards to a page?
    I have InDesign, Illustrator, Photoshop and Acrobat Professional Pro.
    Thanks,
    mr19th

    That sounds great, but I'm lost.
    I followed these steps:
    1) Open your PDF (in Adobe Acrobat Pro)
    2) Chose print
    The print/printer options pop-up will show.
    3) In the printer section, do not use your normal printer, a printer named Adobe PDF should be an option. Chose it.
    4) Under the "Page handling" section, change the Page Scaling drop-down menu to "Multiple pages per sheet".
    It works fine, but it looses all of the font information and the search no longer works. How can you do it and save the font info, so the search tool continues to operate.
    Am I missing anything?

  • Can I have multiple stream types in one object?

    For my final project in my data commucnications class I'm writing a client/server socket application that will allow multiple clients to play TicTacToe simultaneously against the game on the server. The teacher is a C/C++ jock, and knows very little Java. We're free to choose any language that will do sockets, and I love Java and don't love C++.
    I've built the GUI, and got it to the point that I can reliably connect multiple clients on different machines in the school lab to the Server object, which accepts the new sockets and creates a new thread of ServerGame to do the playing in response to the client's moves. A mousePressed() detects clicks in the grid, and modifies a string to contain the status of the game. I've used a BufferedReader and PrintWriter combination on both sides, to send the GameString back and forth, starting with "---------", then the client makes a move and it changes to "X--------" and the PrintWriter sends it over and the ServerGame makes a move to "X---O----" and send it back, etc, etc. You get the idea. I have a ways to go with the implementation of strategy stuff for the ServerGame's moves, but I like it so far. But now I realize it would be really cool to add to it.
    What I want to do, since there can be multiple players, is have a way that it can be like a TicTacToe club. At any one time, it would be nice to be able to know who else is playing and what their won/loss record is. I plan a Player object, with String name, int wins, losses, ties, gets and sets. With Textfields and a Sign In button I should be able to send the Player name to the Server, which can look up the name in a Vector of Player objects , find the one that matches, and sends the Player object for that name over to the Client, and also provide it to the ServerGame. Each player's won/loss record will be updated as the play continues, and the record will be "stored" in the Server's vector when he "logs off". Updates shouldn't be too hard to manage.
    So, with that as the description, here's the question -- most streams don't handle Objects. I see that ObjectInputStream and ObjectOutputStream do. So -- am I headed for trouble in using multiple stream objects in an application? I suppose I could just use the object streams and let them send out a serialized String. In other words, I want to add this to my program, but I don't want to lose too much time finding out for myself if it works one way or the other. I already have working code for the String. Without giving too much away, can anyone give me some general guidance here?

    Anyway, here's the present roadblock that's eating into the time I have left. I've spent many happy hours looking for what I'm missing here, and I'm stumped, real-time.
    I found it was no problem to just send everything over and back with ObjectInputStream and ObjectOutputStream. From the client I send a String with the state of the game, and can break it down and code for decisions in the server as to a response and send the new String back to the client. I now have a Player class with Strings name and password, ints wins, losses, ties. I have a sign-in in the client GUI and old "members" of the club are welcomed and matched with their Player object stored in a Vector, and new members are welcomed and added to the Vector. My idea is to make the Vector static so the clients can have access to the Vector through their individual threads of the Game in the server. That way I should be able to make it so that any one player can have in his client window a TextArea listing who's playing right now, with their won-loss record, and have it updated, real-time.
    The problem is that in my test-program for the concept, I can get a Player object to go back and forth, I can make changes in it and send it back and have it display properly at either end after a change. What I'm aiming at in the end is the ability to pass a copy of the Vector object from the server to the client, for updating the status of everyone else playing, and when there's a win or loss in an individual client, it should be able to tell its own server thread and through that update the Vector for all to access. Sounds OK to me, but what's happening is that the Vector that goes into the pipe at the server is not the same as the Vector that comes out the pipe into the client. I've tried all the tricks I can think of using console System.out.println()'s, and it's really weird.
    I build a dummy Vector in the constructor with 4 Players. I can send a message to the server that removes elementAt(0), and tell it to list the contents of the Vector there, and sure enough the first element is gone, and the console shows a printout of the contents of all the remaining Player objects and their members. But when I writeObject() back to the client, the whole Vector arrives at the client end. Even after I've removed all the Player elements one by one, I receive the full original Vector in the client. I put it into a local Vector cast from the readObject() method. I believe that should live only as long as the method. I even tried putting clear() at the end of the method, so there wouldn't be anything lingering the next time I call the method that gets the Vector from the server.
    What seems the biggest clue is that now I've set up another method and a button for it, that gets the elementAt(0) from the server Vector, changes the name and sends it back. Again, after the regular call to get the Vector sent over, it shows in the server console that one element has been removed. And one by one the element sent over from (0) is the one that was bumped down to fill the space from removeElementAt(). But in the client, the console shows 4 objects in the Vector, and one by one, starting at (0), the Player whose name was changed fills in right up to the top of the Vector.
    So something is persisting, and I just can't find it.
    The code is hundres of lines, so I hesitate to send it in here. I just hope this somewhat lengthy description tips off someone who might know where to look.
    Thanks a lot
    F

  • With Pages 5.2 how can i use multiple language types in a single document

    My Macbook Air Has the version 10.9.3
    I'm used to work with the old version of Page.
    But now I am using the new version of Pages 5.2 (1860).
    I want to know with the new version how do I use an multiple language types in a single document option.
    In the old  version of Pages I was using  Inspector -> Text -> "More" tab -> Language: British Inglese.
    In the new Pages 5.2 I do not know how to do it
    Could you help me?
    melo

    It's not possible to tag text with multiple languages in Pages 5.  Go back to Pages 4, which should still be in you iWork folder.
    For the whole doc in Pages 5, use Edit > Spellling and Grammar > Show Spelling and Grammar.

  • How can I use multiple icloud Accounts with Fotos?

    Hello.
    Yesterday, my wife and I started using the new App "Fotos" on OSX and iOS.
    What I can't figure out, and where I would like to get some insight and help, is how we should use our icloud Accounts.
    How it is right now:
    - Wife (MacBook and iPhone)
    Has her own icloud-Account ([email protected]) for Backup (iOS) and Fotosync, Keychainsync, Bookmarks. 20GB iCloud-Account (18GB free).
    - Husband (MacBook, Mac Mini and iPhone and iPad)
    Has his own icloud-Account ([email protected]) for Backup (iOS) and Fotosync, Keychainsync, Bookmarks. 20GB iCloud Account (10 GB free).
    - Husband has about 400 GB of Photos from over 10 Years on Mac Mini
    How I want it to be:
    - Husband
    upgrades to at least the 500GB Account, to use for all 400GB of Photos and Backup, Keychainsync, Bookmarks.
    - Wife
    Has her own Account ([email protected]) for Keychain and Bookmark, but uses [email protected] on MacBook and iPhone for Backup an Fotosync, so that all Photos are stored in a single one family "container". All Photos in one Place without being able to forget to put them there.
    I don't see, how I can accomplish that, since only one "real" icloud account seems to be possible in iOS, so that if i put my account in her iPhone I would get the Photo and Backup I want, but she would not be able to sync her own bookmarks an keychain any more.
    Any thought on how to resolve this?
    Am I missing something?
    Thanks for your ideas,
    thomas

    Yes, you could have multiple iCloud accounts for Mail, Contacts, Calendars, Reminders, Safari, Notes, and Find My iPhone, but only one primary iCloud account for Photo Stream, Documents & Data, and Storage & Backup.

  • How can I use multiple iTunes accounts on one phone?

    I Have an iTunes account with iTunes match enabled. I've just moved in with my gf and want to be able to share music on our phones. I've enabled her computer and put my Apple ID in and I now have all her music on my phone (thanks to iTunes match) but when I try and **** her phone it ignores all my music. How can I get all my music on her phone? The only way I have managed it is to sign out of her account on the phone and sign in with my ID but that would mean all her purchases would be charged to me etc so this isn't a solution really

    Put everything on the computer to which she syncs, and sync them to her iPhone.

  • Can i use multiple AppleID's with one iCloud Account

    Our family stores our purchases in one huge library.  We each log into our accounts separately (e.g. someone uses an iTunes gift card, someone else uses a credit card, etc.) to purchase music.  Each of us can include other's purchases in our play lists.  We also have a lot of music loaded from CD's.
    Everyone syncs their devices based on their own playlists.
    Can we use one iCloud account to keep our respective playlists up to date?  We would like everyone's purchases available to all devices.

    yes and you can use more then 2
    just don't give them the same name

  • How can I use multiple email-addresses with "Administration Email Address"

    What syntax should I use to have more email-adresses in the screen "Manage Service - Instance Settings - Email" after the field "Administration Email Address".
    I tried:
    - '[email protected]','[email protected]'
    - '[email protected], [email protected]'
    - '[email protected]; [email protected]'
    - "[email protected]','[email protected]"
    - "[email protected], [email protected]"
    - "[email protected]; [email protected]"
    Every time I get the ORA-29279 / 501.
    Please help me with the right syntax for multiple email-addresses.
    Thanx!
    reg.
    Chris

    From a google search of the docs, it looks that that field is used as a FROM address... hence it's by definition only one address.
    Administration Email Address - Defines the "from" address for administrative tasks that generate email, such as approving a provision request or resetting a password.
    From http://download.oracle.com/docs/cd/B28359_01/appdev.111/b32258/adm_wrkspc.htm
    Edited by: Tanjental on Jun 29, 2009 6:28 AM

  • How can I use multiple ipad's on one account without sharing individuals personal email accounts?

    Is it possible to have multiple ipads on one account and share info, but also allow the individual users to have personal email that is not seen on the other ipad's? We have all ipads on same icloud account because we all need to see the same ical. It seems like that's the problem. If it IS related to icloud then if we have separate icloud accounts, how would we share the main ical otherwise? Sharing the ical is very important for this business so everyone can access the daily schedule. Of course each user still wants to have private email.
    Hope this wasn't too confusing!
    Thanks!
    Doreen

    you could set up the main icloud itunes acount for ical and not have in setup on the devices
    and share the calandar with the other itunes accounts on the devices
    or only have it on one device
    devices have the users indervidual itunes icloud setup
    they should be able to access the shared "main" itunes icloud ical account once it's shared
    http://howto.cnet.com/8301-11310_39-57542557-285/three-methods-for-sharing-an-ic loud-calendar/
    if the devices are company owned you could go futher and setup find my iphone on the main itunes account
    and not on the user icloud accounts

  • How can you merge multiple daily backups into one backup for that day?

    Ok, so I had some trouble getting Time Machine to backup some new files and finally had a force a "deep traversal." But now I have 20+ backups for today before I did the "deep traversal" because I was selecting "Back Up Now" to get it to backup up the new files.
    Because it is annoying to have so many backups for one day, which differ only by incoming and outgoing emails, I am wanting to combine all the backups for today into a single backup for today. Is there any way to do this?
    Thanks!

    BibbleBobble wrote:
    Because it is annoying to have so many backups for one day, which differ only by incoming and outgoing emails, I am wanting to combine all the backups for today into a single backup for today. Is there any way to do this?
    Yes. Wait 24 hours, and Time Machine will do it for you. It keeps all backups for 24 hours, but only one (the first of the day) for a month. Thereafter, it keeps one per week, deleting the others, as long as there's room. See #12 in [Time Machine - Frequently Asked Questions|http://web.me.com/pondini/Time_Machine/FAQ.html] (or use the link in *User Tips* at the top of this forum).

  • How can you use iMessage between 3 iPads with 3 different users but only one Apple ID?

    how can you use iMessage between 3 iPads with 3 different users but only one Apple ID?

    No you do not need separate Apple ID's in order to use 3 devices with one Apple ID. I use 4 devices to Message and FaceTime and all use the same Apple ID. You do need to add additional email addresses for the other devices.
    Look at this very informative video for the instructions.
    http://macmost.com/setting-up-multiple-ios-devices-for-messages-and-facetime.htm l

  • How can you use the same e-mail address for multiple ipads?

    I have two iPads.. an iPad and an ipad 2.  I registared my new ipad 2 and now my old ipad is will not let me log on and is telling me that my e-mail address is already in use.  how can you use the same e-mail address for multiple ipads?

    And by using the same Apple ID you can also share purchases.  If you have a different Apple ID for each iPhone then you can't share purchases.

  • How can I use my time capsule with windows7

    How can I use my time capsule with windows7?

    This is asked regularly.
    https://discussions.apple.com/message/10978060#10978060
    Look at the more like this. On the right column next to the post.
    Load airport utility for windows.. which will also load bonjour for windows.
    In windows explorer type \\TCname or \\TCipaddress (replacing with the actual values.. names with spaces will give you trouble so change all names in the TC to SMB compatible or actual ip address).

  • How do you use multiple outputs on a VSTi like Kontakt or Battery?

    how do you use multiple outputs on a VSTi like Kontakt or Battery with Logic Pro 7.1? I've heard someting about using AUX busses, but can anyone please provide an actual clear, step by step basic guide?
    I've had Logic 3 months now and just don't know how to do this yet, and have yet to actually find it in the manual!!
    thx

    http://www.sonikmatter.com/wiki/index.php/Tutorial:MultiChanAudioSetup

Maybe you are looking for

  • Not Able to Find Drivers for HP Photosmart Plus e-All-in-One Printer B210e

    I have an HP Photosmart Plus e-All-in-One Printer B210e.  I went to try and get drivers for it and I either get a page that says 404 Page Not Found Try going back to Support Home The other page I get when I look for drivers is for HP Photosmart Plus

  • Need a little help with Slimbox (Lightbox clone) and Spry data sets

    Hello guys! First of all let me say that I'm not a programmer in any way, shape or form, and somehow I managed to build me a dynamic thumbnail gallery that reads data from an XML file and displays it on my webpage using a Spry data set and a slider w

  • Constrained Nonlinear Curve Fit VI: Termination Revisited (LabVIEW 8.5)

    Hello: In the Constrained Nonlinear Curve Fit VI, the Help for the VI states that if the number of iterations exceeds max iterations specified in the termination control, the fitting process terminates. Would this not indicate that if the above condi

  • ERROR TO CONNECTING MY WINDOWS PC

    DEAR SIR I AM GETTING ERROR WINDOW AS LIKE " BLACKBERRY DESKTOP SOFTWARE CANNOT COMMUNICATE WITH THE CONNECTED DEVISE"  AND SHOWING OPTIONS  RETRY AND UPDATE AND CANCEL., AND I CLICKED ON UPDATE IT WAS NOT UPDATING... BUT MY PLAYBOOK ONLY 45 DAYS OLD

  • Tracking MIG problem - page doesnt exist

    Hi Experts Please I need a help with the tracking MIG Iu2019m using the tracking ## to count the clicks in a link inside a campaign e-mail. My problem is that the link generated by SAP doesnu2019t work in some sites like www.google.com The google lin