Reading and writng at the same time through UrlConnection

Hi,
I have written an applet that communicates with a servlet through a Urlconnection. However, the outputstream from the applet must be closed before the inputstream can receive info from the servlet. The coding is as follows :
try{
URL url = new URL("http://"+codeBase().getHost()+":8001/servlet/gameQuizServlet");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
conn.setInput(true);
conn.setUseCaches(false);
conn.setRequestProperty("Content-Type", "application/octet-stream");
out1 =new PrintStream(conn.getOutputStream());
out1.println("how are you");
out1.flush();
out1.close();
in1 = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((FromServer=in1.readLine())!=null) {
if the statement 'out1.close()' is below the 'in1.readLine()', the applet can't output the "how are you" to the servlet. (although the applet can receive info from the servlet through 'in1.readLine()).
The applet and the servlet have to communicate in an interactive mode. I have tried the command 'setAllowUserInteraction(true)' instead of 'setDoOutput(true)' but it doesn't work. How can I make the inputStream and outputStream in the Urlconnection active at the same time.
Best regards.
Hoifo

Thanks for your opinion, DrClap.
I've already written a server(using ServerSocket in server, Socket in applet) for this application but when internet user using brower behind the firewall, it stops the communications. Using HTTP is one of the ways to go through the firewall, but has limitation. Can I go through the firewall by other means?
Regards.
Hoifo

Similar Messages

  • Reading and recording at the same time with AudioUnit

    Hi,
    I am trying to read and record at the same time on the iPhone with AudioUnit. For the reading part I made an AUGraph which works fine, constructed like that:
    NewAUGraph(&_graph);
    _outputUnitComponentDescription.componentType = kAudioUnitType_Output;
    _outputUnitComponentDescription.componentSubType = kAudioUnitSubType_RemoteIO;
    _outputUnitComponentDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
    _outputUnitComponentDescription.componentFlags = 0;
    _outputUnitComponentDescription.componentFlagsMask = 0;
    AUGraphAddNode(_graph, &_outputUnitComponentDescription, &_outputNode);
    _mixerUnitComponentDescription.componentType = kAudioUnitType_Mixer;
    _mixerUnitComponentDescription.componentSubType = kAudioUnitSubType_MultiChannelMixer;
    _mixerUnitComponentDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
    _mixerUnitComponentDescription.componentFlags = 0;
    _mixerUnitComponentDescription.componentFlagsMask = 0;
    AUGraphAddNode(_graph, &_mixerUnitComponentDescription, &_mixerNode);
    AUGraphConnectNodeInput(_graph, _mixerNode, 0, _outputNode, 0);
    AUGraphOpen(_graph);
    AUGraphNodeInfo(_graph, _outputNode, NULL, &_outputUnit);
    AUGraphNodeInfo(_graph, _mixerNode, NULL, &_mixerUnit);
    _generatorUnitComponentDescription.componentType = kAudioUnitType_MusicDevice;
    _generatorUnitComponentDescription.componentSubType = kAudioUnitSubType_RemoteIO;
    _generatorUnitComponentDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
    _generatorUnitComponentDescription.componentFlags = 0;
    _generatorUnitComponentDescription.componentFlagsMask = 0;
    for(int i=0; i< [_urlList count]; i++)
    SoundBuffer* soundBufferTemp = [_bufferSoundList objectAtIndex:i];
    AURenderCallbackStruct renderCallbackStruct;
    renderCallbackStruct.inputProc = MyFileRenderCallback;
    renderCallbackStruct.inputProcRefCon = soundBufferTemp;
    AudioStreamBasicDescription* inputAsbd = [soundBufferTemp getASBD];
    err = AudioUnitSetProperty(_mixerUnit,
    kAudioUnitProperty_StreamFormat,
    kAudioUnitScope_Input,
    i,
    inputAsbd,
    sizeof(AudioStreamBasicDescription));
    UInt32 zero = 0;
    err = AudioUnitSetProperty(_mixerUnit,
    kAudioOutputUnitProperty_EnableIO,
    kAudioUnitScope_Input,
    kInputBus,
    &zero,
    sizeof(zero));
    err = AUGraphSetNodeInputCallback(_graph,
    _mixerNode,
    i,
    &renderCallbackStruct);
    This works well, for the recording AudioUnit I did the following:
    OSStatus err;
    AudioComponentDescription audioComponentDescription;
    AudioComponent audioComponent;
    audioComponentDescription.componentType = kAudioUnitType_Output;
    audioComponentDescription.componentSubType = kAudioUnitSubType_RemoteIO;
    audioComponentDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
    audioComponentDescription.componentFlags = 0;
    audioComponentDescription.componentFlagsMask = 0;
    audioComponent = AudioComponentFindNext(NULL, &audioComponentDescription);
    err = AudioComponentInstanceNew(audioComponent, &_audioUnit);
    UInt32 size;
    size = sizeof(AudioStreamBasicDescription);
    err = AudioUnitGetProperty(_audioUnit,
    kAudioUnitProperty_StreamFormat,
    kAudioUnitScope_Input,
    1,
    &_soundFileDataFormat,
    &size);
    _soundFileDataFormat.mSampleRate = 44100.00;
    AudioUnitSetProperty(_audioUnit,
    kAudioUnitProperty_StreamFormat,
    kAudioUnitScope_Input,
    kInputBus,
    &_soundFileDataFormat,
    size);
    AudioUnitSetProperty(_audioUnit,
    kAudioUnitProperty_StreamFormat,
    kAudioUnitScope_Output,
    kOutputBus,
    &_soundFileDataFormat,
    size);
    AURenderCallbackStruct renderCallbackStruct;
    renderCallbackStruct.inputProc = MyRecorderCallback;
    renderCallbackStruct.inputProcRefCon = self;
    UInt32 one = 1;
    UInt32 zero = 0;
    err = AudioUnitSetProperty(_audioUnit,
    kAudioOutputUnitProperty_EnableIO,
    kAudioUnitScope_Input,
    kInputBus,
    &one,
    sizeof(one));
    err = AudioUnitSetProperty(_audioUnit,
    kAudioOutputUnitProperty_EnableIO,
    kAudioUnitScope_Output,
    kOutputBus,
    &zero,
    sizeof(zero));
    err = AudioUnitSetProperty (_audioUnit,
    kAudioOutputUnitProperty_SetInputCallback,
    kAudioUnitScope_Global,
    0,
    &renderCallbackStruct,
    sizeof(AURenderCallbackStruct));
    err = AudioUnitInitialize(_audioUnit);
    Then in I setup a file to write in:
    - (void) openFile
    OSStatus err;
    err = ExtAudioFileCreateWithURL((CFURLRef) _soundFileUrl,
    kAudioFileCAFType,
    &_soundFileDataFormat,
    NULL,
    kAudioFileFlags_EraseFile,
    &_extAudioFileRef);
    err = ExtAudioFileSetProperty(_extAudioFileRef,
    kExtAudioFileProperty_ClientDataFormat,
    sizeof(AudioStreamBasicDescription),
    &_soundFileDataFormat);
    err = ExtAudioFileWriteAsync(_extAudioFileRef,
    0,
    NULL);
    All this things works well (I check by printing err in the log which I removed here for clarity).
    And then in the callback for recording I do the following:
    static OSStatus MyRecorderCallback(void *inRefCon,
    AudioUnitRenderActionFlags* inActionFlags,
    const AudioTimeStamp* inTimeStamp,
    UInt32 inBusNumber,
    UInt32 inNumFrames,
    AudioBufferList* ioData)
    OSStatus err= noErr;
    AudioUnitRecorder* auRec = (AudioUnitRecorder*) inRefCon;
    [auRec allocateAudioBufferList:1 size:inNumFrames*4];
    err = AudioUnitRender(auRec.audioUnit,
    inActionFlags,
    inTimeStamp,
    inBusNumber,
    inNumFrames,
    auRec.audioBufferList);
    err = ExtAudioFileWriteAsync(auRec.extAudioFileRef,
    inNumFrames,
    auRec.audioBufferList);
    return err;
    (Then I close the file after recording at the same time I close the AudioUnit)
    Now the strange thing is that all this works perfectly well in the simulator: I can record and play at the same time but on the device, the callback for recording is not ran (I check by trying to print something in the log in the callback function.) which men no writing in the file and an empty file in the end.
    Any one has any idea of what could be causing this?
    Thanks
    Alexandre

    Just in case some one might need it, I solved my problem:
    I simply needed to initialize the AudioSession before playing/recording. I did so with the following code:
    OSStatus err;
    AudioSessionInitialize(NULL, NULL, MyInterruptionListener, self);
    UInt32 sessionCategory = kAudioSessionCategory_PlayAndRecord;
    err = AudioSessionSetProperty (kAudioSessionProperty_AudioCategory,
    sizeof (sessionCategory),
    &sessionCategory);
    AudioSessionSetActive(TRUE);

  • How do I read and write at the same time using the NI-CAN channel API?

    Here's the situation.  I have one CAN bus, and I need to read and write channel data (using the channel API) at the same time both at an interval of 20 ms.  It's easy to do one or the other using the channel API, but you can't setup a channel task to do both.  It's either input or output, not both.  Is this even possible?

    Hi,
    yes , this is possible. But you have to create two tasks, one for input and one for output. see the attached example for LabVIEW.
    If you download and install NI-CAN 2.4 you will get this example and one for C and VB as well.
    DirkW
    Attachments:
    Single Sample Input Output same Port.vi ‏79 KB

  • Read and write at the same time. Or: Read while the file is being written.

    Hello
    I'm a student working on a live streaming project. The video i get should be streamed live, so i have to read the file from disk while it is written.
    When I try to do this I get an access denied or permission denied (i can provide the detailed error if you need it) which seems obvious to me. Still, is there a way around this?
    The file which i try to read is monotonically increasing in size, so it's not a 4gb file which is truncated at the end of the video recording.
    I hope someone can help
    thanks
    lukas
    Edited by: Jossnaz on Jun 25, 2008 6:26 AM

    Jossnaz wrote:
    Hello
    I'm a student working on a live streaming project. The video i get should be streamed live, so i have to read the file from disk while it is written.
    When I try to do this I get an access denied or permission denied (i can provide the detailed error if you need it) which seems obvious to me. Still, is there a way around this?
    So you are getting the Stream from one source, writing to a file, then also steaming it live to a client?
    I would use threads, 3 of them I think:
    1) Read content from the input stream and send it into two different PippedOutputStreams
    2) A consumer thread attached to the end of one of the PippedInputStreams linked to #1 that streams to the client
    3) A consumer thread attached to the end of the second PippedInputStream linked to #1 that streams to the file

  • Problem with audio of my notebook. Audio works through pc speakers and earphones at the same time

    Hi all, 
    thanks in advance for your advices.
    I have a problem with my notebook (HP pavilion g6 2305 sl).
    The problem is that when I connect my earphones the audio of my pc don't stop, hence I can hear (music, film, ...) both by earphones and speakers at the same time.
    I tried to install again the latest driver audio, but nothing was changed.
    I tried to use another pair of earphones, but nothing.
    I have noted that if I connect the Jack at my pc, but not until the end, the audio stops from the speakers and goes through the earphones, but only if the jack is not completly inserted in the notebook.
    I read a lot of forum on the web but I'm not able to find a solution for my problem.
    (ps. the problem comes out suddenly, without any signal. I don't have installed any update or new software before the problem's start)

    Right click on speaker icon, lower right screen.
    Choose playback devices.
    Select "speakers and headphones" as your default.
    Disable "communications headphones".

  • Can I watch video through my iPhone and TV at the same time?

    Can I watch video through my iPhone and TV at the same time while using the Apple composite video cables? I am planning a trip in my car and would like to play videos for my kids through their video screen while my wife watches on the iphone from the passenger seat. I didn't want to spend $50 to find out it doesn't work.
    Thanks in advance!

    It doesn't work that way, sorry. When video out is being utilized, only the movie artwork (the cover or image) is displayed, and the actual movie is not displayed on the iPhone's screen.

  • Can I play music and read a book at the same time?

    Can I play music on my iPad and read a book on my iPad at the same time?
    Little Fat Boy

    Little Fat Boy wrote:
    Why don't I try WHAT?
    Playing music and reading a book at the same time.

  • Charge ipod and listen at the same time?

    hi,
    i sit at my desk for about 8 hours at work and would like to charge my ipod at my computer via usb and listen at the same time. is this possible? it's a pc computer here at work. and it does not have itunes installed and i don't see having itunes on it as a possibility.
    i don't like having to charge it, wait about an hour, then listen for a few hours, then charge it again.
    also, do you notice any battery "leakage"? i mean, i have some battery power at night when i turn it off, (yes, i do turn it off b/c the screen goes blank) and then when i get into work and try to turn it on, i get this battery looking thing and have to charge it.
    it's possible that the ipod came on while i was walking (it's in my bag), but this happens too often for me to think that it does.

    You'll need iTunes if you want to access your iPod and listen through your PC. Also you'll need to set it to manual update, see the articles below.
    Using iPod with Multiple computers
    Managing Your Songs Manually
    When your iPod is in your pocket make sure you have the lock on to disable the controls otherwise it is liable to get switched on and use battery power.

  • IPod Touch 4g won't charge and play at the same time

    I used to have a 4g Nano that I would play in my car through an aux cable and charge through a cigarette lighter charger. I just got a 4th gen iPod Touch and it no longer lets me charge and play at the same time. If both wires are connected it will only charge and not play, once I pull the charger part out it will play through the speakers. Is there a fix to this? Do I need a different charger so that it won't think it's simply docked?

    You would need to turn off hard drive mode via iTunes iPod settings on your home system to do this. I don't know if you have this mode on or off already. I thought I read that there is a way to enable/disable hard drive mode via the iPod buttons but I don't remember how.
    Thanks,
    Steven

  • How do i start video and audio at the same time in ios

    How do i start video and audio at the same time in ios?
    I have tried a lot of different ways but i cant figure it out?
    I can get the sound and animation (timeline) to start playing.
    There is no problem to start the video and the animation at the same time.
    But i cant get both the video and the audio to start playing when i press a button.
    It works great in OSX and on windows?
    Here is an example:
    // insert code for mouse click here
    // Play an audio track
    sym.$("_1")[0].play();
    // Play a video track
    sym.$("host")[0].play();
    // Play the timeline at a label or specific time. For example:
    // sym.play(500); or sym.play("myLabel");
    sym.play("marker1");

    If the game has sound in it (and possibly even if it doesn't) it may be overriding the Music app and causing it to stop playing - in which case there is nothing that you can do about it.

  • I have a DAQ Assistant configured to read multiple channels at the same time. When I wire a graph indicator to the output, I see all of my signals jumbled together. How do I split them up into seperate signals?

    I have a DAQ Assistant configured to read 2 channels at the same
    time. When I wire a graph indicator to the output, I see the 2
    signals jumbled together. How do I split them up into seperate signals?
    When I wire any type of indicator it is showing just one output of a single channel.
    I want 2 indicators showing 2 different signals as expected from the 2 channels configured. How to do this?
    I have tried using split signal but it end up showing only 1 output from 1 signal in both the indicators.
    thanks in advance.
    Solved!
    Go to Solution.

    Yes you are right. I tried that but I did not get the result.
    I just found the way. When we launch split signal, we should expand it (split signal icon) from above and not from below. It took me a while to figure out this. 
    thanks 

  • My SB Audigy 2 card can't use headset and musicamplifier at the same time

    Hi, i just bought a SB Audigy 2 [D400] and i have downloaded drivers and programs. I run Windows XP SP2.
    The soundcard works fine but it is very very annoying that i physically have to change the jack in the green=line out jack from headset to musicamplifier when i want to use my musicamplifier and change back the jack in the green=line out from musicamplifier to headset when i just want to use the headset/headphones .
    In the shop they told my that i can connect both amplifier and headset at the same time and then with creative software control whether there is sound in the headset or in the amplifier. But i can't simple get it work.
    I tried to use the green to the amplifier and the headset/speakers in the black (line out 2) and then with creative speaker settings softeware choose headphones but still the ampliefier receive the sound and no sound in the headphones. Why? In fact no matter what configuration i try the headphones doesn't work.
    But if i change the jacks so headset is in the green line out then only headset is working and the amplifier doesn't work no matter i put it in sort=line out 2 jack or orange=line out 3 jack.
    Can somebody here tell me if it is possible or not to connect both headset and external amplifier and control by software which to play? and how?
    please help, thx.
    Michael

    If you can have an ASIO compatible music playing system, then it might be possible to have system like you wish when using Creative Audigy 2 card. Since ASIO bypasses Windows Audio System, you can use both 'drivers' (ASIO - WDM/MME/DS) side by side.
    Say you want to play a game (using headset /w mic) and someone other like to listen music at the same time. With ASIO capable system you can output your music for example to "center L/R (stereo) channels" and same time output sounds from other source (using MME/DS/WDM drivers) to normal output channel (Front L/R). Only thing is, you need to set your speakersystem to 4 or 6 (depending which other channel you're using) (and for better 'balance' to adjust "angle" on THX console. You get the THX console by installing Audigy 2 Zs software).
    Try for example http://img332.imageshack.us/img332/463/djs9mo.jpg[/img] width="406" alt="Image Hosted by ImageShack.us" >
    Another option:
    Say you want to play music through external amplifier and play game online with your headset + microphone (eg. others but you listen the music, you play games)
    --> try free http://img332.imageshack.us/img332/4589/tbp7rz.jpg[/img] width="406" alt="Image Hosted by ImageShack.us" >
    If you use ASIO on BeatPort Player you can select L/R individually from the list(s). Same rules as described earlier.
    = You can play from 2 different sources simultaoneusly (ASIO + WDM/MME/DS) to two different outputs without disturbance. The other (WDM/MME/DS) source is set 'automatically' output to (Audigy) "green" port, and the other (ASIO) to "black" or "orange" port (as set).
    .jtpMessage Edited by jutapa on 09-5-2005 05:30 AM

  • Ipod nano (5th generation) - want to use headphones and charge at the same time

    I have an ipod nano (5th generation).  Do I need a special set of headphones to use the headphone jack and charge the ipod at the same time?

    The iPod nanos have a 30 pin dock connector and a headphone jack. When you charge the iPod you use the dock connector therefore you can use and charge at the same time. You cannot use and charge the iPod shuffle at the same time. You might have the two mixed up.

  • Can I surf and talk at the same time on a verizon iphone?

    I've heard that Verizon iPhones don't allow users to talk and surf at the same time. Is that true? I'm not keen on going to AT&T. If it's true, will it ever change?

    Yes. It is true because Verizon runs on CDMA which doesn't allow for surf and talk at the same time. AT&T runs on GSM which allows for surf and talk at the same time.

  • Can I use Time Capsule and LaCie at the same time?

    Can I use Time Capsule and LaCie at the same time?

    stephaniefromarlington wrote:
    Before I answer your questions, let me first just say thank you so much for your amazing patience and helpfulness.  Whether or not we get to the bottom of this, I am very, very grateful to you. 
    We will get to the bottom of it, and you're quite welcome.  Don't feel you ought to know all this stuff -- none of us were born with it!
    By the way, in answer to your original question, yes, you can use the Time Capsule while backups are running. There's no conflict at all.
    1)  Estimated size of full backup:  205.94 GB
    2)  My LaCie has available:  11.04 GB of 359.95 GB
    That's part of the problem right there; 360 GB is a bit small to back up 206 GB.  Ordinarily, a Time Machine drive should be 2-3 times the size of the data it's backing-up, so Time Machine can keep a reasonable "depth" of old backups for you.
    It looks like Time Machine is trying to do a fairly large backup, and there just isn't enough room for it.
    But something doesn't quite add up.  Time Machine should have deleted all but your most recent backup, trying to make room for the new one.  But that would mean there should only be a bit less than 206 GB on the disk, not 360.
    A clue may be lurking in your logs.  Use the widget in #1 of Time Machine - Troubleshooting to display the backup messages from your logs.  Locate the backup in question, then copy and post all the messages here.

Maybe you are looking for

  • ITEM tab in the Approval Process overview IN srm 7.0 AND EP 7.1

    Hi Friends, I am working in SRM 7.0 with EP 7.1.. 1 . I have to remove 'ITEM' tab in the approval process overview screen which is apprearing in Portal. approval process overview screen will be appeared when 'Display / Edit Agents' Button in the Head

  • How do I edit a "fill and print form" using Acrobat XI?

    We recently upgraded to Adobe Acrobat Pro, version 11. We have some staff who previously created "fill and print" forms with Adobe Acrobat 10. However, now when they try to use version 11 to edit the form, they receive the following message: This for

  • Burning NTSC movie on PAL disk

    I decided to burn NTSC movie on a PAL disk using IDVD. The computer warned me about my action but I decided to go through with it and I got a surprise. The first DVD came out O.K but when I inserted another blank DVD for another copy, the IDVD encode

  • Unable to find BAPI in the explorer

    Hi Guys,   This maybe a common issue. But i was unable to find the solution. I am using ECC6.0. I have released the business object and the method successfully. I could also test the method. After that i generated the Business Object successfully. Bu

  • Viewing on tv

    Probably a simple question but how do I set my phone up so that I can watch videos on my tv? Do I need apples special cables?