Socket input / output stream

Does anyone know if the input / output streams returned by getInputStream() / getOutputStream() in java.net.Socket are buffered by default?

y they are buffered, but to use the buffer, you have to use available() and read(byte[] buf ...

Similar Messages

  • Buffered input/output stream

    How the buffereing is done in buffered input/output streams?
    From the API doc I got to know that they use internal buffer to store bytes before they can be read or written. But i found that File input/output stream also have methods like read(byte[]) or write(byte[]). So what is extra in buffered input/ouput streams? Does the phrase "buffered" suggests that bytes can be read from an array or be written to an array? Am i thinking the right way?

    How the buffereing is done in buffered input/output
    streams?
    From the API doc I got to know that they use internal
    buffer to store bytes before they can be read or
    written. But i found that File input/output stream
    also have methods like read(byte[]) or write(byte[]).Thouse are your buffer, not the streams'.
    So what is extra in buffered input/ouput streams?
    Does the phrase "buffered" suggests that bytes can be
    read from an array or be written to an array? Am i
    thinking the right way?No. It means that the stream either prefetches some data even if it's not requested yet, or that it withholds data that it's supposed to write until it's flushed or gets a larger chunk.

  • Object input/output stream

    Hi, i'm currently doing a software enginnering project at university. I need to understand how to save and read from files.
    I've been told to look at object input/output stream, which I have, but I can't get my head around what's written in the books. Does anyone know where i can find a good tutorial on this subject?
    thanks
    AK

    I like the tutorial on this site because it tells you what to use for what you're doing (click on Using the Streams). Hope it helps!
    http://java.sun.com/docs/books/tutorial/essential/io/index.html

  • Get multiple Input/Output Stream from same socket ?

    For a better express of my problem i will put my test example
    I have those 4 classes
    package test;
    import...
    public class ReaderExecutor extends Thread{
            private InputStream in = null;
            private static int defaultID = 0;
            private int ID = getID();
            public ReaderExecutor(InputStream in){
                this.in = in;
            public void run(){
                try {
                    int c ;
                    while ((c=in.read())!=-1)
                        System.out.println("ReaderThread " + this.ID + ":" + c);
                catch (IOException e) {
                    System.out.println("ReaderThread "+this.ID+" stopped !");
            private static int getID(){
                return defaultID++;
    package test;
    import...
    public class WriterExecuter extends Thread{
        OutputStream out = null;
        private static boolean odd = true;
        private boolean isOdd ;
        public WriterExecuter(OutputStream out) {
            this.out = out;
            isOdd = odd;
            odd = !odd;
        public void run(){
            try{
                for (int i = isOdd?1:2;i<10;i+=2){
                    System.err.println(i);
                    out.write(i);
            }catch(Exception e){
                System.out.println("WriterThread stopped !");
    package test;
    import...
    public class Main { 
        public Main() {
        public static void main(String[] args) throws Exception {
            try{
                ServerSocket ss = new ServerSocket(9090);
                System.out.println("Ascult ... ");
                Socket client = ss.accept();
                new ReaderExecutor(client.getInputStream()).start();
                //Thread.sleep(2000);
                new ReaderExecutor(client.getInputStream()).start();
            }catch (Exception e){
                e.printStackTrace();
    package test;
    import...
    public class Main1 {
        public Main1() {
        public static void main(String[] args) {
            try{
                Socket s = new Socket("localhost",9090);
                WriterExecuter t= null ;
                t = new WriterExecuter(s.getOutputStream());
                t.start();
                t = new WriterExecuter(s.getOutputStream());
                t.start();
            }catch(Exception e){
                e.printStackTrace();
    }Now if i run successive Main , Main1 i get this output
    Ascult ...
    ReaderThread 0:0
    ReaderThread 1:0
    ReaderThread 0:0
    ReaderThread 1:0
    ReaderThread 0:0
    ReaderThread 1:0
    ReaderThread 0:0
    ReaderThread 1:0
    ReaderThread 0:0
    ReaderThread 0 stopped !
    ReaderThread 1 stopped !The question is can i get other Input/Output individual streams with a separate logic functionality from the same socket?
    From this example it seems i can't :(
    Thx
    Alex

    For what you are trying to do the simplest solution is to have one socket per "stream" that is the way they are designed to be used.
    However, you can multiplex multiple stream over a single socket, but you have do the coding yourself or use a solution which does this for you e.g. JMS. (There is no support at the socket level for this)

  • Java Sockets and Output Streams

    Hi All,
    I am beginning sockets programming and I have a problem. If there is a server listening in the background for incoming connections and say for example 4 client programs programs which we shall call client1...client4 connect. How best can I capture the output streams associated with these newly created sockets so that the server can send back isome nformation to say clients1 and client4 only which is not seen by clients 2 and 3. Similarly I would like the server to send some infor to clients 2 and 3 only which is not seen by client1 and client 4.
    Currently I have the server listening part as shown below, but not too sure how to add DISTINCT output streams for 1 and 4 on one hand and 2 and 3 on the other.
    Thanks:
    // bind socket to a port number
    ServerSocket serverSocket = new ServerSocket(portNo);
    // create socket to listen to client connection
    while (true) {
    //listen to an incoming connection
    System.out.println("chatroom server waiting for incoming connections");
    Socket incomingSocket = serverSocket.accept();
    //launch new thread to take care of new connection
    chatRoomThread chatThread = new chatRoomThread(incomingSocket);
    chatThread.start();
    //go back and wait for next connection
    Please help.
    Thanks,
    Bleak

    HouseofHunger wrote:
    yes thats exactly the way I have my in and out streams, in the run method, but that doesn't help me in filtering traffic, in other words I am saying 2 clients, client1 and client4 for example should share a common in and out stream so that they will see eact other's messages... makes sense.....?No, doesn't make sense. That's the wrong design. Each socket should have its own input and output stream (yes, I know, that's been said several times before). If messages going to client1 should also be sent to client4, then whatever writes the messages to client1's output stream must also write them to client4's output stream. Trying to make those two output streams actually be the same output stream is the wrong way to do that. Just have the controller send the messages to whoever is supposed to get them.

  • Is there a way to flush out a socket's output stream without...

    ...having to close it (the stream)?
    I'm trying to implement a keep-alive feature in a simple HTTP Server application. This is a draft of the code I have trouble with:
    ==========
    //'clientSocket' is the socket obtained by the 'serverSocket.accept()' method
    OutputStream out = clientSocket.getOutputStream();
    //'message' is a string to be sent to the client
    InputStream data = new ByteArrayInputStream(message.getBytes());
    byte[] buff = new byte[2048];
    while (true)
    int read = data.read(buff, 0, 2048);
    if (read <= 0)
    break;
    out.write(buff, 0, read);
    out.flush();
    ==========
    If I don't call 'out.close()', the data will not be sent to the client.
    If I call 'out.close()', the data will be sent, but the socket will be closed too, which I don't want to. I need to be able to reuse that socket .
    Is there any way to properly push out the data to the client without having to close the output stream?

    ...having to close it (the stream)?Yes. OutputStream.flush(). But if you're not using any kind of buffered writer/output stream you don't even have to do that.
    If I don't call 'out.close()', the data will not be sent to the client.Untrue. The client will read everything that has been written If you don't close the output stream, the client will never get the EOS indication (e.g. read() returning -1). So if your client is looping until that happens it will loop forever ...
    Your problem at the moment is at the reading end.

  • Questions about input/output streams

    In the following tutorial:
    http://chortle.ccsu.ctstateu.edu/CS151/Notes/chap85/ch85_10.html
    It mentions that some methods, such as write(), writeByte(), writeBytes(), and writeChar(), return the low eight bits of the argument to the output stream. I am a little unsure of what exactly that means, might somebody be able to clarify for me?
    In addition, I've been encountering the flush() method in some of the byte- and character-streaming objects that deal with buffers. What exactly is the flush() method's purpose, and when might it be used? Thank you.

    flush pushes the data out of the buffer. the write methods write to the buffer, when the buffer is full, it flushes itself (usually), or it could block the write methods (in theory). flush just lets you make sure that it's flushed.
    I'm not sure there's any reason to worry about high and low bytes in Java most of the time. I suppose, like anything, there's times you need to, but I can't think of any offhand.

  • Problem with blocking socket.getInput/Output stream :-(

    Hi there!
    I have a typical client/server application and the problem, that opening the streams leads to clocking behaviour.
    This is how I open the streams on the server-side
    sock = ssock.accept();
    outStream = new ObjectOutputStream(new BufferedOutputStream(sock.getOutputStream()));
    inStream = new ObjectInputStream(new BufferedInputStream(sock.getInputStream()));and this is how I open it on the client-side:
            Socket sock = new Socket(host, port);
            outStream = new ObjectOutputStream(new BufferedOutputStream(sock.getOutputStream()));
            //inStream = new ObjectInputStream(new BufferedInputStream(sock.getInputStream()));If I leave the inStreeam-Statement uncommented, everything works fine, but as soon I try to catch the input-stream both, the server and the client-side block foreever.
    Any ideas whats wrong?
    Thank you in advance, lg Clemens

    Oh my god, what a brain-dead java-designer played with the thought tha creating a ObjectOutputStream does not lead to a flush() on the underlaying streams ???!!!
    Its easy if you know the way to go (same on both sides):
    1.) get the Outputstream / create the ObjectOutputStream
    2.) flush the ObjectOutputStream (so that the versioning-infp etc is exchanged)
    3.) create ObjectInputStream
    Step 2 is just extremly stupid in my eyes!
    lg Clemens

  • PaCkAgE DaTaStReAm input/output stream utilities

    I am trying to read/write Solaris installable package streams and I was wondering if someone had already invented this wheel. Since I cannot seem to find ANY documentation on the internet about the file format (and, more importantly, the header encoding) for the items in these files I was hoping someone here would have information about this.
    And, no, I am not able to exec() mkpkg, pkgtrans, etc as I may not be running on a Solaris machine.

    Wow. That was easy. The Sun package datastream format is simply two cpio files concatenated together on a 512 byte boundary. Still trying to figure out the main package header (which is also 512 bytes) and contains the "PaCkAgE DaTaStReAm" tag and the name of the package itself followed by two numbers, a '1', which hold no special meaning yet and the number of 512-byte blocks occupied by the installed package). So far my ant task is shaping up nicely and I'll be able to create Solaris packages via build.xml :D

  • Input/output stream coupler (like a pipe, but reversed)

    I could write my own class but, for standardization purposes, I was wondering if there is anything in the Java API that does this:
    I have a Reader and a Writer and I want to connect them so that as soon as data is available from the Reader, it is written directly to the Writer.
    Reader>===>Writer
    as opposed to a pipe which looks loke
    Writer>===>Reader
    Is there such a class?

    I don't know of such a class, but you have the same API docs available to you as the rest of us. If you don't see it in java.io or java.nio or java.nio(.*), then it's not in the core API. At that point, I'd check sourceforge, jakarta, mindprod. After that, I might be inclined to post here, but I'd probably just say screw it and write my own.

  • File being erased during input output stream

    I am trying to send a .txt to an ftp server. The application will send the file but it is empty on the server end AND my original! The file is still there but is 0 kb with all data deleted. I cant seem to figure out what I'm doing wrong. Any ideas?
    try{     
    URL url = new URL("ftp://username:[email protected]/file.txt;type=i");
        URLConnection con = url.openConnection();
        BufferedInputStream in =
        new BufferedInputStream(con.getInputStream());
        FileOutputStream out = new FileOutputStream("file.txt");
    int i = 0;
    byte[] bytesIn = new byte[1024];
    while ((i = in.read(bytesIn)) >= 0) {
         out.write(bytesIn, 0, i);
    out.close();
    in.close();
         catch(Exception nio){System.out.println(nio);}

    I am trying to send a .txt to an ftp server.There's the problem right there. The code you posted copies data FROM the server TO your local system.

  • Facing error in creating ObjectInput/output stream socket

    hi I am Jatandar and i am implemeint client server program which will be using object Input/Output stream to pass data through sockets . The problem is the i m getting error when the cleint connects to the server here is the server and client code , YOur help will be appreciated
    Inventory class with serializable has been implemented
    public class Client
    public static void main( String [] args )//throws IOException
    Inventory invt[];
    try
    Socket serv = new Socket( "localhost", 8000 );
    // connect to server at port 8000
              ObjectInputStream ois ;     
    ois= new ObjectInputStream(serv.getInputStream());
    invt=(Inventory[]) ois.readObject() ;
    System.out.println(invt[0]);
    catch(IOException e )
    System.out.println(" no server Found \n");
    catch(Exception e)
    System.out.println(e);
    public class A3Server
         public static void main(String arg[] ) throws IOException
              //create a Server Socet
              ServerSocket ss= new ServerSocket(8000) ;
              ObjectOutputStream oos;
              //create a clent Socker that will listen for connection
              //listen for the connection from client
              BufferedReader br=null;
              FileReader fr=null;
              LinkedList ll=new LinkedList();
              StringTokenizer stkr;
              int i=0;
              Inventory inv=new Inventory();
              Inventory invt[];
              String t[]=new String[5];
              boolean choice=true;
              String temp="",temp2;
    // i am reading a text which contain data
    //that data is stored in invt []
    //that array is transfered to clien t when it is connected
         Socket toClient= ss.accept();
    oos = new ObjectOutputStream(toClient.getOutputStream());
    oos.writeObject(invt );
         oos.close();     
              }// end of main fucniton
         }//end of Server class
    DETAIL OF ERROR
    error in natived socket write method

    hi I am Jatandar and i am implemeint client server program which will be using object Input/Output stream to pass data through sockets . The problem is the i m getting error when the cleint connects to the server here is the server and client code , YOur help will be appreciated
    Inventory class with serializable has been implemented
    public class Client
    public static void main( String [] args )//throws IOException
    Inventory invt[];
    try
    Socket serv = new Socket( "localhost", 8000 );
    // connect to server at port 8000
              ObjectInputStream ois ;     
    ois= new ObjectInputStream(serv.getInputStream());
    invt=(Inventory[]) ois.readObject() ;
    System.out.println(invt[0]);
    catch(IOException e )
    System.out.println(" no server Found \n");
    catch(Exception e)
    System.out.println(e);
    public class A3Server
         public static void main(String arg[] ) throws IOException
              //create a Server Socet
              ServerSocket ss= new ServerSocket(8000) ;
              ObjectOutputStream oos;
              //create a clent Socker that will listen for connection
              //listen for the connection from client
              BufferedReader br=null;
              FileReader fr=null;
              LinkedList ll=new LinkedList();
              StringTokenizer stkr;
              int i=0;
              Inventory inv=new Inventory();
              Inventory invt[];
              String t[]=new String[5];
              boolean choice=true;
              String temp="",temp2;
    // i am reading a text which contain data
    //that data is stored in invt []
    //that array is transfered to clien t when it is connected
         Socket toClient= ss.accept();
    oos = new ObjectOutputStream(toClient.getOutputStream());
    oos.writeObject(invt );
         oos.close();     
              }// end of main fucniton
         }//end of Server class
    DETAIL OF ERROR
    error in natived socket write method

  • IOException: Connection reset by peer: JVM_recv in socket input stream read

    hi
    I encountered a problem : a program throw out an exception:java.io.IOException: Io exception:
    Connection reset by peer: JVM_recv in socket input stream read.
    I tried my best to resolve it ,but unfortunately,i didn't know what caused the exception.
    the following is my application environment:
    I have two PC(Win2000os),one is a server which installed oracle9.2.0.2 and jdeveloper9.0.3,the another is a
    client which only intalled jdeveloper9.0.3.Two days ago,i performed a web application on my client with
    jdeveloper,and it includes some JSP and a javabean files.JSP Page finished uploading client xml file to a
    folder on server and the javabean finished loading the xml file into a xmltype column.I can make sure the
    connection is established and the javabean is OK,beacause my some jsp page can successfully use
    <jsp:usebean> tag and use the javabean's some other public interfaces,except the interface that finishs
    loading the xml file into a xmltype(clob) column.
    Then i do many tests!I changed the javabean to a java class incluse a main method beacause it is easy to
    debug.Finally i found the following code caused the exception:
    public CLOB writetoClob( CLOB clob, InputStream is )throws SQLException, IOException {
    InputStreamReader reader = new InputStreamReader( is );
    Writer writer = clob.getCharacterOutputStream( );
    char[] buffer = new char[clob.getChunkSize(  )];
    int charsRead;
    for ( charsRead = reader.read( buffer ); charsRead > -1;charsRead = reader.read( buffer ) ) {
    writer.write( buffer, 0, charsRead );
    writer.close();
    return clob;
    when it runs to writer.close(),the exception is caused!
    Then i copy the java class to the server,it runs ok!
    That is to say ,the same code,the different result!
    But when i run my web application on server with jdeveloper Embedded OC4J Server and a jsp page loaded javabean
    and run to mentioned code ,the same exception occured!
    I checked the application log in event viewer,the descriptions was:
    The data buffer created for the "AppleTalk" service in the "C:\WINNT\system32\atkctrs.dll" library is not
    aligned on an 8-byte boundary. This may cause problems for applications that are trying to read the
    performance data buffer. Contact the manufacturer of this library or service to have this problem corrected or
    to get a newer version of this library.
    I search some some resolution about this exception with web and someone sayed :
    This basically means that a network error occurred while the client was receiving data from the server. But
    what is really happening is that the server actually accepts the connection, processes the request, and sends a
    reply to the client. However, when the server closes the socket, the client believes that the connection has
    been terminated abnormally because the socket implementation sends a TCP reset segment telling the client to
    throw away the data and report an error.
    Sometimes, this problem is caused by not properly closing the input/output streams and the socket connection.
    Make sure you close the input/output streams and socket connection properly. If everything is closed properly,
    however, and the problem persists, you can work around it by adding Thread.sleep(1000) before closing the
    streams and the socket. This technique, however, is not reliable and may not work on all systems.
    In general,the following information is conclution:
    Web application runs error both on client and on server.
    If it was changed to a client java class,it only run ok on server!
    i have done anything that i can do now,i feel depressed very much!
    how can i resolve the problem!
    Any a little help will be appreciated!
    regards!
    Thanks
    Jiawei ZHAO

    How can i solve the problem.
    Thanks in advance!
    Jiawei Zhao

  • MultiThreading with Input and Output Streams

    Hi,
    I have a problem and I think it's because I'm not coding correctly. Please help me if you can understand what I'm doing wrong.
    I have a server that spawns a separate thread to go off and collect data from a serial port. It also waits to accept connections from any client and if a connection is made it will send that data to the clients connected.
    There is data constantly coming in through the serial port. It is output through a DataOutputStream so when the thread is created in the server, I pipe it into a DataInputStream. I do does because I want the server to then read in the data from the inputstream and then send it out to all my clients.
    So far, the way I have it set up seems to do this. But my problem occurs when I try to close a client connection. Instead of removing the socket connection it gives me an error that it can't send data to the client, but it shouldn't be sending data to the client because I just closed it. I realize this is probably because I'm still constantly receiving data from my inputstream and the connection was closed so it can't send that data to the client. I know I need to either close the stream or close my socket but I don't know where this needs to be done. I'm stuck on the correct way to fix this.
    My second problem is the initial connection made to receive data from the inputstream. This is probably because I'm not very familiar with how input/output streams work. But instead of just sending the client the current data being received in real time, it'll send all the data that's buffered in the inputstream. I don't want all the data that's been collecting to go to that first client. I only want the recent data that is coming through while the client is connected. Does this make sense? Because after I make a second client connection I don't have this problem because the InputStream is no longer buffered up. Should I be using something else besides the DataInputStream?
    I feel like I'm going about this the wrong way. Please advise. I'm shy about showing the code but I've included the bulk of it here in hopes that someone will see what I'm doing wrong. The only part that's left out is the thread that reads from the serial port. I don't seem to have any problems with that thread.
    Thanks,
    kim
    ===
    import java.io.*;
    import java.net.*;
    import javax.comm.*;
    import java.util.*;
    // DataServer waits for a client connection
    class DataServer
         static final int PORT = 7;
         // The ServerSocket to use for accepting new connections
         private ServerSocket ss;
         // A mapping from sockets to DataOutputStreams. This will
         // help us avoid from having to create a DataOutputStream each time
         // we want to write to a stream.
         private Hashtable outputStreams = new Hashtable();
         // The inputstream that will receive serial port data through a
         // piped inputstream
         public DataInputStream datalogger;
         // Constructor and while-accept loop all in one.
         public DataServer() throws IOException
              try {
                   // Creating pipe to convert the outputstream from the
                   // RS232 Thread to an inputstream for the server to read
                   PipedOutputStream pout = new PipedOutputStream();
                   PipedInputStream pin = new PipedInputStream(pout);
                   // The inputstream that will receive data from the RS232Thread
                   datalogger = new DataInputStream(pin);
                   // Spawn the thread that will read data through from
                   // the TINI serial port
                   new RS232Thread( pout ).start();
                   // Begin listening for connections and send data
                   listen();
              } catch (IOException ioe) {
                   System.out.println("Error >> DataServer::DataServer()");
                   System.out.println(ioe.getMessage());
                   ioe.printStackTrace();
              } finally {
                   try     {
                        System.out.println( "Closing >> DataServer::DataServer()" );
                        datalogger.close();
                   } catch (IOException i ) {
                        System.out.println( "Error2 >> DataServer::DataServer()" );
                        System.out.println(i); }
         private void listen() throws IOException
              // Create the ServerSocket
              ss = new ServerSocket( PORT );
              // Inform that the server is ready to go
              System.out.println( "Listening on " + ss );
              // Keep accepting connections forever
              while (true) {
                   // Grab the next incoming connection
                   Socket s = ss.accept();
                   // Inform that connection is made
                   System.out.println( "Connection from " + s );
                   // Create a DataOutputStream for writing data to the
                   // other side
                   DataOutputStream dout = new DataOutputStream( s.getOutputStream() );
                   // Save this stream so we don't need to make it again
                   outputStreams.put( s, dout );
                   // Create a new thread for this connection, and then foret
                   // about it
                   new ServerThread( this, s );
         // Get an enumeration of all the OutputStreams, one for each client
         // connected to the server
         Enumeration getOutputStreams() {
              return outputStreams.elements();
         // Send a message to all clients (utility routine)
         void sendToAll( byte[] b ) {
              // synchronize on this because another thread might be
              // calling removeConnection() and this would screw things up
              // while it walks through the list
              synchronized( outputStreams ) {
                   // For each client...
                   for (Enumeration e = getOutputStreams(); e.hasMoreElements();) {
                        // ... get the output stream ...
                        DataOutputStream dout = (DataOutputStream)e.nextElement();
                        // ... and send the message
                        try {          
                             dout.write( b );
                        } catch(IOException ie) {                     
                             System.out.println( "Error >> ServerThread::sendToAll()" );
                             System.out.println( ie );
         // remove a socket, and it's corresponding output stream, from the
         // list. This is usually called by a connection thread that has
         // discovered that the connection to the client is dead.
         void removeConnection( Socket s ) {
              // Synchronize so it doesn't mess up sendToAll() while it walks
              // down the list of all output streams
              synchronized( outputStreams ) {
                   // Inform about removal
                   System.out.println( "Removing connection to " + s );
                   // Remove if from our hastable/list
                   outputStreams.remove( s );
                   // Make sure it's closed
                   try {
                        s.close();
                   } catch( IOException ie ) {
                        System.out.println( "Error closing " + s );
                        ie.printStackTrace();
         // main - Opens a server socket and spins off a new thread each time
         // a new client connection is accepted on this socket.
         public static void main(String[] args) throws Exception
              System.out.println("Starting DataServer version 1.0 ...");
              try     
                   new DataServer();
              catch (IOException ioe)
                   System.out.println( "Error >> DataServer::main()" );
                   System.out.println(ioe.getMessage());
                   ioe.printStackTrace();
    class ServerThread extends Thread
         //The Server that spawned this thread
         private DataServer server;
         // The Socket connected to the client
         private Socket socket;
         //Constructor
         public ServerThread( DataServer server, Socket socket )
              // save the parameters
              this.server = server;
              this.socket = socket;
              // Start up the thread
              start();
         // This runs in a separate thread when start() is called in the
         // constructor
         public void run() {
              try {
                   // The inputstream receiving data from the global inputstream
                   // that is piped to the RS232 Thread
                   // ???? is this where i'm messing up ???
                   DataInputStream in = new DataInputStream( server.datalogger );
                   int num = 0;
                   byte[] d = new byte[1];
                   // read from the inputstream over and over, forever ...
                   while( ( num = in.read(d) ) > 0 ) {
                        // ... and have the server send it to all clients
                        server.sendToAll( d );               
              } catch (IOException ioe) {
                   System.out.println( "Error >> ServerThread::run()" );
                   System.out.println(ioe.getMessage());
                   ioe.printStackTrace();
              } finally {
                   // The connection is closed for one reason or another,
                   // so have the server dealing with it
                   System.out.println( "Closing" );
                   server.removeConnection( socket );

    A couple of things to note...
    First, you are looping infinitely in your server's constructor. Since the constructor is never completing, your server object is never completely constructed - this may cause indeterminate behaviour when you pass a reference to the server to another thread.
    Second, I would recommend fixing your issues by modifying your design somewhat. The design I would recommend (read: The design I would use) is:
    A server object, with a public listen method. The constructor spawns a thread to constantly read from the serial port and forward the data read back to the server, via a multicast (sendToAll) method.
    The listen method sets up a server socket to accept connections, and in a loop opens client sockets and stores them in a set.
    The multicast method iterates through the list of open client sockets, and for each in turn confirms that it is still open. If open, send the data down the socket's output stream; if closed, remove the socket from the set.
    Note that this design includes only two threads - the main thread listens for and accepts new socket connections, while the extra thread collects data from the serial port, multicasts it to all of the open sockets, and removes all of the closed sockets. If you require to perform any other communication with the sockets, it may be necessary to create a thread for those sockets, to facilitate reading from their input streams, but in the given design, this is not necessary.
    I hope this helps,
    -Troy

  • Using two ports or Using two Input / Outputs

    I'm explaining my project. It s almost done. I send message and data to server and it is stored in server. From the begining I'm using
    BufferedReader - PrintWriterAnd I cannot send files because they are binary. I have to use
    BufferedInputStream - BufferedOutputStreamI cannot change my input / output. So I found two solutions:
    1) Connecting from another port with another socket. -> Using this it blames the ports. I cannot transfer anything from my first port.
    2) Using another input / output streams from the same port. -> I didn't tried it . Does anyone tried this. Is it possible to do this.
    That's the end of my project. I will give the name of project who gives me a good answer :D
    Best Regards, Bulent.

    I cannot change my input / output. Why not?
    So I found two solutions:
    1) Connecting from another port with another
    er socket. -> Using this it blames the ports. I
    cannot transfer anything from my first port.Huh? Unless the server stops you, there is nothing in sockets that prevents you, as a client, from connecting to the server twice.
    2) Using another input / output streams from the
    he same port. -> I didn't tried it . Does anyone
    tried this. Is it possible to do this. Nothing stops you from using an InputStream to create two different buffered solutions.
    I wouldn't even attempt this myself. It would create a very fragile application. But you could try it. You would need to carefully control when the two connections were used and in particular when they were closed. You could do this by wrapping both in a class.

Maybe you are looking for

  • NAT migration on 8.2.4 to 9.1.2

    Hi, I have new ASA 5545-X firewall with 9.1.2 software (default) and I want to replace old 5540 with current configuration on version 8.2.4 I copied the current asa 5540 config (old ver) to new asa 5545-x and start with the current configuration (cop

  • Word Docs have become Unix Executable Files!

    The subject says it. This has happened on both my wife's iMac G5, and my MacBook Pro. Some, not all, of our Word docs, (both using 2004, running OS X.4.7) have had their icons turned into a gray console, and in "Get Info" identify themselves as "Unix

  • I can not sign in to iCloud from the control panel on my PC

    I just purchased the New iPad and decided to do the iCloud sync.  I have installed the iCloud control panel to my Windows 7 Pro computer, but when I try to sign in from the control panel it doesn't log-in.  I have waited for an hour to see if anythin

  • Code changes in Production system.

    Hi all, Due to the unavailability of the development and quality i want make code changes in production system. Please tell me is this possible and also i want know that does it effect or not? Regards, Ramprasd

  • Default memory target/SGA values in Oracle 11g

    I have a few minor questions about how Oracle assigns memory parameters when creating database. I'm working with Oracle 11gR2. Right now, I've got 4G of RAM available. When I did my install, I created a 'default' database. It assigned a memory_target