Different family class used for input  and output when working with sockets

I have seen more or less everywhere the following code to open a socket and to receive input and send output through it:
Socket server = new Socket("anyservername", 25):
OutputStream out = server.getOutputStream();
PrintWriter pout = new PrintWriter (out, true);
pout.println("Hello");
InputStream in = server.getInputStream();
BufferedReader bin = new BufferedReader (new InputStreamReader(in));
String response = bin.readLine();
What I do not understand is:
Why the BufferedReader needs InputStreamReader as an argument whereas printwriter does not want the OutputStreamReader as an argument but it is OK with just the OutPutStream?
I would tend to believe that they should be more or less at the same level and use the same arguments?.
In that sense if I use BufferWriter instead of PrintWriter I bet It should be OK the following code?:
OutputStream out = server.getOutputStream();
BufferedWriter bout = new BufferedWriter (out);
String myOut = bout.writeLine();
Cheers
Umbi
Edited by: Imbu on Jun 2, 2008 2:40 PM

1. Does it even compile?
2. While there is a fair amount of symmetry between reader and writer classes, don't assume it's exhaustive. Your best friend is the API:
[http://java.sun.com/javase/6/docs/api/]
3. Those were just examples. Code it the way you feel is best. I would specify charsets to make sure the encodings were platform independent. Networking and all that, don't you know...

Similar Messages

  • How can I get a sim card for Japan and will it work with my locked Iphone 6

    How can I get a sim card for Japan and will it work with my locked Iphone 6

    You cannot use a SIM card on a carrier locaked phone, other than a sim from the carrier the phone is locked to. You must first get the carrier it is locked to, to unlock your phone. Apple does not unlock phones.

  • Looking for a back up drive for photos and videos that works with time machine, prefer wireless. Time capsule has poor reviews and already have BT hub

    Looking for a back up drive for photos and videos that works with time machine, prefer wireless. Time capsule has poor reviews and already have BT hub that serves as a good router. 3gb or 4gb capacity preferred but 2 would suffice.

    Plug a NAS into the BT Hub that does TM. Look at Synology.
    You just use the wireless of the hub.
    But the cheapest solution is still the TC.

  • I have on;y one audio port can i use it for input and output at the same time?

    i have the new macbook pro 13 in and i want to connect aguitar as input and output on an amp but i have only one audio port

    You can't use the jack as an input and output simultaneously. The solution is to look for a USB or Firewire interface to get your guitar sound into the computer.

  • Re: Using JOptionPane for Input and Output

    You're going to get in big trouble with things like this: "if (memtype = P)"
    Remember that '=' is for assignment, '==' is for comparison. Furthermore, you shouldn't use '==' for comparing Strings; you should use the String's equals() method instead.

    Thank you for your reply and for the tip on using the ==,
    I have seen this used, but the language you used to explain this is still a little too technical for me and I am not too sure what you mean when you said: "you should use the String's equals() method instead. "
    what would the format of this look like?

  • Positional flat file schemas for input and output files to be generated with the required usecases

    Hello all,
    I need one help regarding the positional flat file schema which contains multiple headers, body and trailers.
    I have attached the sample input file below. This is a batched input and we have to generate the output which I have given below:
    We are unable to flat file schema which replicates the below input file. Please suggest better approach to achieve this.
    Sample Input FIle:
    010320140211ABC XYZ XYZ ABCD201402110 FSPAFSPA005560080441.02000006557.FSPA.IN AB-CD ABCD/AB-CD BETALKORT
    1020140210AN194107123459.FSPA.IN
    [email protected]
    1020140210AN196202123453.FSPA.IN
    [email protected]
    1020140210AN198103123435.FSPA.IN
    [email protected]
    1020140210AN195907123496.FSPA.IN
    [email protected]
    1020140210AN195903123437.FSPA.IN
    [email protected]
    1020140210AN193909123434.FSPA.IN
    [email protected]
    1020140210AN195607123413.FSPA.IN
    [email protected]
    1020140210AN199205123408.FSPA.IN
    [email protected]
    1020140210AN196206123499.FSPA.IN
    [email protected]
    1020140210AN196709123410.FSPA.IN
    [email protected]
    1020140210AN194708123455.FSPA.IN
    [email protected]
    1020140210AN195710123443.FSPA.IN
    [email protected]
    1020140210AN198311123436.FSPA.IN
    [email protected]
    1020140210AN196712123471.FSPA.IN
    [email protected]
    1020140210AV197005123403.FSPA.IN
    98000000000000014000000000000001000000000000015
    010320140211ABC XYZ XYZ PEDB201402111 FSPAICA 005560080441.02000006557.FSPA.IN AB-CDABCD/ABCDBETALKORT
    1020140210AN195111123491.ICA.IN
    [email protected]
    1020140210AV195309123434.ICA.IN
    98000000000000001000000000000001000000000000002
    Output FIle:
    1020140210AN195607123413.FSPA.IN
    [email protected]
    1020140210AN199205123408.FSPA.IN
    [email protected]
    1020140210AN196206123499.FSPA.IN
    [email protected]
    1020140210AN196709123410.FSPA.IN
    [email protected]
    1020140210AN194708123455.FSPA.IN
    [email protected]
    1020140210AN195710123443.FSPA.IN
    [email protected]
    1020140210AN198311123436.FSPA.IN
    [email protected]
    1020140210AN196712123471.FSPA.IN
    [email protected]
    1020140210AN195111123491.ICA.IN
    110019EPS [email protected]
    1020140210AV197005123403.FSPA.IN
    1020140210AV195309123434.ICA.IN
    98000000000000001000000000000001000000000000002
    99000000000000001
    Note: Header is a single line till BETALKORT and also there is a space before email id. That is not getting pasted properly in the files.
    Thanks and Regards,
    Veena Handadi

    Hi all,
    Header is missed from the output file for the above post:
    Please find the output file:
    010320140211ABC XYZ XYZ ABCD201402110 FSPAFSPA005560080441.02000006557.FSPA.IN AB-CD ABCD/AB-CD BETALKORT
    1020140210AN195607123413.FSPA.IN
    [email protected]
    1020140210AN199205123408.FSPA.IN
    [email protected]
    1020140210AN196206123499.FSPA.IN
    [email protected]
    1020140210AN196709123410.FSPA.IN
    [email protected]
    1020140210AN194708123455.FSPA.IN
    [email protected]
    1020140210AN195710123443.FSPA.IN
    [email protected]
    1020140210AN198311123436.FSPA.IN
    [email protected]
    1020140210AN196712123471.FSPA.IN
    [email protected]
    1020140210AN195111123491.ICA.IN
    110019EPS [email protected]
    1020140210AV197005123403.FSPA.IN
    1020140210AV195309123434.ICA.IN
    98000000000000001000000000000001000000000000002
    99000000000000001

  • Sound input and output not working

    Last night my audio was working fine. I was going to record some stuff in garage band and had a microphone plugged into the input line-in on my macbook. everything was working fine still, turned on the "auto leveling" and then put in my headphones. i then turned on the "monitor" to get the sound to actually come to my headphones. I didnt realize until after it was done but you cant have the auto level and monitor on at the same time. There was a short blast of sound in the headphones and then everything cut out. I couldnt get sound from anything, headphones, built in speakers. No sound going in either.
    I restarted my computer and if I remember correctly (maybe i'm imagining it) there was the start up chime. when I started up garageband again I got an error message reading "selected driver not found. error 10202" still no sound input or output. When trying to adjust the volume all I got was the grayed out volume thing with the little cross thingy at the bottom. I checked the sound settings and there was nothing in the input or output sound.
    I did some searching around and saw people with similar problems (none with an answer).
    This is what I've already tried:
    I reset the permissions
    I reset the PRAM
    I did a hardware check (hold d which restarting) i even did the hour long check and there was no problems.
    I tried putting headphones in an out (there was no red light in the headphone jack)
    I updated all my software (there was an update to OS X to 10.5.8)
    After the update there was no longer a startup chime, and i got no error messages when opening garage band. however there was still no input or output sound. when adjusting the volume on the screen it appears to be normal, but there is still no sound from built in speakers or headphones. I did notice there was a very faint "clicking" noise when i try and adjust the volume... like the speakers are getting power or something... but then nothing comes out. In the sound settings there everything appears to be back to normal.
    I know this is long, but I wanted to be thorough in describing my problem. I'm posting this on several boards as well.

    I'm having the exact same problem. I did install the newest version of Skype the last time my computer was running (with sound)... so not sure if the new Skype had something to do with it.
    Also, when I try to change volume with the keyboard keys, there is a little icon (circle with slash) indicating that the sound has been disabled or not allowed to be changed.
    I can't find any answers on any forums.

  • How do I use more than four PDOs when working with NI-Industr​ial Communicat​ions for CANopen?

    When I call CANopen TPDO Create.vi to create TPDO objects I can only input PDO1 through PDO4. How do I work with more than four PDOs?
    I see the other forum thread using an older version of CANopen, but it does not appear to directly translate into the newer NI-Industrial Communications for CANopen.
    http://forums.ni.com/t5/Automotive-and-Embedded-Ne​tworks/PDOs-on-a-CANopen-network/m-p/405001?requir​...

    Hi wireman,
    A good resource for CANopen is available here.  That page explains that typically in the CANopen standard, there are only 4 predefined PDOs in each direction (transmit and receive).  To use extra PDOs, additional configuration is required.  The configuration of the predefined PDO Channels refers to the COB-ID that they are linked to by default.
    According to the LabVIEW help files, the COB-ID is 'calculated' by adding the value of the PDO Channel and the Node ID, if the COB-ID is zero.  However, if the COB-ID is explicitly defined, then LabVIEW will ignore the calculation provided by the Node ID and PDO Channel.  So, if you need more than the four PDOs, you'll need to use the COB-ID input to differentiate which channel is being referenced.
    I hope this clears some things up, and please don't hesitate to ask for more advice.
    Regards,
    -Dave C
    Applications Engineer
    National Instruments

  • Safari 3 for Win and Mac not working with sites

    I work for a company that does all the IT stuff for the county of San Diego, and it was brought to our attention that the County site (and some of the sites in it) don't play nice with Safari 3 on either platform. I downloaded the latest beta, plugged in http://www.sdcounty.ca.gov , and get a bunch of boxes at the top of the window.
    The sites work fine in IE 5-7, Safari 2 and up, and Firefox. Someone on the ARStechnica forums mentioned they saw our servers (IIS and Unix/Apache) are set for uft-32. Okay, so does anyone know what we should have them set at so people (and our client) stop complaining we don't work with Safari Beta?
    Thanks for any feedback/help.
    Greg

    Thanks Tom,
    I'll look into it. We're going to change the test server to utf-8, but can't until the one guy who has admin access to the box gets back from training in about a week. Yes, they could have given admin or sudo access to a few of us, but that would have made too much sense.

  • I am unable to use the Live View function when working with JavaScript in Dreamweaver.

    I am currently trying to set up my own website with dreamweaver and am very familiar with Java and JavaScript. However, whenever I try to use the Live View function it never lets me. Additionally, I am unable to preview my work in a browser as the option to do so is greyed out.
    However, I have noticed that when using html in a project, all these functions are available. Any ideas how I can be able to use these functions?

    Is it possible you meant to say you were "very unfamiliar with Java and javascript" in your initial post?
    Javascript doesn't do anything without an html page to affect.
    Java and javascript are not the same thing, they're really not even related other than browsers can be made to render both. Java is its own programming language while javascript is basically html's helper monkey. I don't think it's even feasible to "understand javascript" without knowing html. My last post still stands, if you are coding javascript, you need an html based page to turn it into anything but plain code to a browser, so the option to view it will never come up. When you preview the page it's attached to, it will function correctly (as long as it has been attached to the page correctly).
    Java on the other hand can create programs that run without a browser at all and I've never gotten close to touching that monster.
    You may need to explain what you're trying to do and post the code here to get the help you need.

  • Makin GUI for input and output

    This is simple code for my Comp Science class at school, but I keep getting "Exception in thread "main" java.lang.NoClassDefFoundError: TrivialApplication"
    and im tryin to figure out what i did heres my code:
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import javax.swing.*;
    public class Hypotenuse {
              double side1, side2, hypotenuse;
              String Fside1, Fside2;
         public Component components()
         final JTextArea text = new JTextArea();
         final JTextField InputText1 = new JTextField();
         final JTextField InputText2 = new JTextField();
         JButton button = new JButton(" OK ");
         button.setMnemonic(KeyEvent.VK_ENTER);
         button.addActionListener(new ActionListener(){
              public void actionPerformed(ActionEvent e)
                   Fside1 = InputText1.getText();
                   Fside2 = InputText2.getText();
         JPanel InOutField = new JPanel();
         InOutField.setBorder(BorderFactory.createEmptyBorder(30,30,30,30));
         InOutField.setLayout(new GridLayout(0, 1));
              InOutField.add(text);
              InOutField.add(InputText1);
              InOutField.add(InputText2);
              InOutField.add(button);
              return InOutField;
         public static void main(String Args[]) throws IOException
             try
              UIManager.setLookAndFeel(
                   UIManager.getCrossPlatformLookAndFeelClassName());
             catch (Exception e)
              JFrame InOutFrame = new JFrame("Hypotenuse");
              Hypotenuse app = new Hypotenuse();
              Component contents = app.components();
              InOutFrame.getContentPane().add(contents, BorderLayout.CENTER);
              InOutFrame.addWindowListener(new WindowAdapter()
                   { public void windowCloasing(WindowEvent e)
                        { System.exit(0);
              InOutFrame.pack();
              InOutFrame.setVisible(true);
    }

    It compiles OK for me, but it doesn't close properly, unless I change this
    public void windowCloasing(WindowEvent e)
    to this
    public void windowClosing(WindowEvent e)

  • I own a macbook pro mid-2010 - problem-updated to mountain lion and continuously crashes and reboots when working with audio and visuals (TRIED GFXcardstatus v 2.3) sometimes helps sometimes it does not, apple info ?

    I know this is a widespread problem
    I am not from the U.S.
    what solutions does apple have for us? , are there any?
    I read there's an issue with the NVIDIA card , is there anyone I can contact? I bought it in the U.S.

    If the machine is less than 3 years old, Apple will replace the motherboard under a recall program. If it's older you may get stuck with that cost. I'd make a Genius Bar appointment and take it in.

  • SSIS: How to use one Variable as Input and Output Parameter in an Execute SQL Task

    Hello,
    i need your help,I'm working on this issue since yesterday and have no idea how to deal with it.
    As I already said in the tilte i want to start a stored procedure via a Execute SQL Task which has around 15 prameters. 10 of these should be used as input AND output value.
    As an example:
    i have three  Variable:
    var1    int        2
    var2    int     100
    var3    int     200
    the stroed procedure:
       sp_test
          @var1 int
          @var2 int output
          @var3 int output
       AS
       BEGIN
            SET @var2 = @var2 * @var1
            SET @var3 = @var3 + @var1
       END
    So in the Execute SQL Task i call the Stored Procedure as follwos:
        Exec sp_test  @var1 = ?, @var2 = ? output, @var3 = ? output
    (I use an OLE DB Connection)
    The parameter mapping is as follows:
    User::Var1        input                   numeric              0                 -1
    User::Var2        input/output         numeric              1                 -1
    User::Var3        input/output         numeric              2                 -1
    Now my problem. If i set  Var2 and Var3 as Input parameter the values are still the same after running the package. If i set them to a output value the are both Null because the procedure doesnt get any values.
    I already tried to list them a second time - like
        User::Var2        input                  numeric              1                 -1
        User::Var2        output                 numeric              1                 -1
    or i use a new variable
        User::Var2                  input                  numeric              1                 -1
        User::Var2Return        output                 numeric              1                 -1
    but i alwas get the error
    "Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done."
    Has anybody an idea how I can solve this problem?
    Thanks a lot.
    Kind Regards,
    Alice

    Hi Alain,
    thx for your answer.
    I have around 15 procedures called one after the other to calculated and modify my values. Each procedure is responsible for an other but overlapping set of variables. So i thought it would be a good idea to call them one after the other with the needed variables via a execute sql task.
    So if i use a result set, how i get my stored procedure to return 10 values? I would have to use a Function instead of a procedure, wouldn't i?
    As if i have 15 procedures this would be a lot of work.
    But thanks a lot for the idea. I think an other idea would be to create one function which calls all stored procedures and returns all the calculated values as a result set, wouldn't it?.
    Kind Regards.
    Alice

  • Selecting separate input and output devices!

    hi, i have logic pro 8 and cant find out how to select separate devises for input and output!
    for my output (and input when recording drums) i use a alesis multimix 16 (16 track firewire desc) but for recording guitars and bass and poss vocals i would like to use my line 6 x3 live as my input devise but still using the alesis for monitoring.
    is this possible? cant figure how to do it.
    any help is great help! cheers, Dan

    In Logic 9 you can easily select different input and output devices in the Preferences Devices area. In Logic 8 you must create an aggregate device -
    http://support.apple.com/kb/HT1215
    JG

  • Audio input and output at the same time

    Hello mac users.
    I have one simple question: since the new macbook has one single audio port for both input and output, how could I, for example, play my guitar AND listen to the headphones at the same time?
    I KNOW (because I've tried) that with the iPhone headphones with microphone the port CAN physically work at the same time for input and output, so the question is: what can I use to do that? Will a simple splitter do or do I have to use different tricks?
    (I know there is a thread on this already, but it doesn't provide a definitive answer)
    Thank you!

    One of the first questions to ask...
    Is the audio input stereo or mono?
    When using a headset mic you're dealing with a mono input so you at least know the Mac is capable of that.
    If it's mono, and I suspect it is, should be easy to either make or purchase a custom cable that has two female input connectors, one mono input and a stereo headphone input.
    However, I'd probably just purchase a USB audio interface, the sound, both recording and playback will be head and shoulders above the Macbooks built in internal audio.
    pancenter-

Maybe you are looking for