Need of closing the Socket to complete read at client

Hi all,
I have aproblem of reading a byte array from a socketconnection.
My code is work but there is a small issue.
Basically my problem is there is a need of closing the socket at the server to complete the reading of the byte array at client
following is the server code which write the bytearray.
ServerSocket  serversocket = new ServerSocket(Integer.parseInt(resources.getString("PORT")));
Socket clientSocket = s.getServersocket().accept();
DataOutputStream dt = new DataOutputStream(clientSocket.getOutputStream());
dt.write(getImageasByteArray());     // getImageasByteArray returns a byte array
//clientSocket.close();          // if not close clientSocket reading of the byte array not worksAs I mentioned above if the clientSocket is not closed the reading of the byte not completed at the client.
client code which read the byte array
SocketConnection sock = (SocketConnection) Connector.open("socket://" + hostname);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream inputStream = sock.openInputStream();
int c = 0;
while ((c = inputStream.read()) != -1)
     baos.write(c);
System.out.println("read complete"); // this read complete never execute if not clientSocket is closed at serverI can't close the clientSocket because there are several threads at server some reads incoming commands and some write based on the commands.
so please help me
thank You

Thank You again for answering
my client is a j2me platform and it print this stackrace
my code
DataOutputStream dt = new DataOutputStream(clientSocket.getOutputStream());
dt.write(ImageUtil.getImageasByteArray(img).length);
dt.write(ImageUtil.getImageasByteArray(img));   //send byte array
DataInputStream in = new DataInputStream(sock.openInputStream());    // openInputStream not getinputStream
int length = in.readInt();
System.out.println("read length=" + length);
byte[] arr = new byte[length];  // read size
in.readFully(arr); 
java.lang.NegativeArraySizeException
        at net.chamika.mobility.client.CanvasKey.keyPressed(CanvasKey.java:90)
        at javax.microedition.lcdui.Canvas.callKeyPressed(Canvas.java:1121)
        at javax.microedition.lcdui.Display$DisplayAccessor.keyEvent(Display.java:2209)
        at javax.microedition.lcdui.Display$DisplayManagerImpl.keyEvent(Display.java:2952)
        at com.sun.midp.lcdui.DefaultEventHandler.keyEvent(DefaultEventHandler.java:249)
        at com.sun.midp.lcdui.AutomatedEventHandler.keyEvent(AutomatedEventHandler.java:620)
        at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.handleVmEvent(DefaultEventHandler.java:699)
        at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(DefaultEventHandler.java:608)server ends arrays size as 5340
client read it as -587212545
Please help me.

Similar Messages

  • How the client to detect  the server has closed the socket?

    if the server closed the socket by an unnormal way, for example, closing the socket compulsively. Then the client will show the "IOException:java.net.SocketException: Connection reset" message,
    how the client to avoid such an error message to the user/customer, I mean , what the client can deal with such a message?
    where to put the dealing code?
    try{ int receivedLength=in.read(receivedBytes);
    }catch(SocketException e){
    // put the code here? }
    catch(IOException e){
    }

    Do you know how to prove it---"a socket read should
    always always always have a timeout";As ejp said (IMHO ...) it's his opinion and doesn't need proof. I respect his opinion, but I often write code that doesn't set this.
    Instead I use 2 threads per connection, and don't care if the read thread goes to sleep, since I can still write. If you only have one thread per connection, you better ensure that the read will end in a relatively short amount of time, even if your partner decides it's time to go for lunch.
    how the length of this timeout will be? That is a business decision, it all depends on the expected time between received messages and is application dependent.
    is it a field of the socket?If you are using blocking mode sockets you set this with setSoTimeout. If you are using non blocking mode NIO you specify it on the select call, although the soTimeout should also work there, although I've never tried that.

  • I can't install Firefox 5. It downloads & starts the wizard. I follow the prompts till it says it needs to restart the computer 'to complete a previous upgrade of firefox' . I say yes and it restarts and there is no sign of firefox and no error message.

    The very first time I tried this there was a red message that flashed on the screen too fast to read it. I have Windows 7 and AVG. My son's computer also has Windows 7 and AVG and his upgrade went without a hitch. It deleted my old version of firefox (3.6.12) so now I'm using IE. Windows installed a lot of updates just before I tried upgrading firefox. I have tried turning my firewall down. I have gone to the file in downloads and double clicked it and it does the same thing. It always says it needs to restart the computer even though I have closed all other applications. Should I just give up and try reinstalling an older version of Firefox? Thanks

    It is probably because you are not properly closing Firefox. Restarting your system would make sure that Firefox had terminated, but you do not have to do that.
    To properly close Firefox on Windows systems, use
    :File > Exit or "Firefox:" button > Exit
    When you get the message "Firefox is already running" it is too late, and you must force termination of Firefox through the Windows Task Manager before restarting Firefox. Windows 7 has a keyboard shortcut to save you a step "Ctrl+Shift+Esc" then on "Processes" tab, select "firefox.exe" and use the "End Process" button. More thorough would be to right-click on the "firefox.exec" and choose "End Process Tree".
    You would find firefox.exe in a Mozilla folder in your program files, but y0u would not want to delete it there, you would need to use the Control Panel which you have already identified and do it from there -- but generally you would not need to do that, and there is nothing in what you have posted to indicate that you should. But if you did do that, then don't let the install start Firefox for you as you would want to use you existing desktop icon or method of starting Firefox, and should decline having Firefox install start Firefox for you. When the install starts then invoke Firefox in your normal manner. This should eliminate problems of creating a new profile rather than using your old profile.

  • HT4972 Tried to acquire NBC 2012 Olympics app.  App noted that I need to acquire the iOS5 to complete the free install.  Did the update (sync) via my pc computer.  After update (sync), still can't acquire the app noted earlier.  Pls advise.  Thanks

    I have an iPad2.  Tried to acquire NBC 2012 Olypic app.  Unsuccessful for the reason that it is recommending an iOS5.  I updated (sync) my iPAD2 via my pc laptop computer.  Still asking for an iOS5.  Please advise on what I need to do.  Thanks

    Are you sure that the update was successful? Go to Settings>General>About>Version. Does it show that you are running iOS 5.1.1 in there? If it does show that you have iOS 5.1.1 on the iPad, try restarting or resetting the iPad and then try to download it again.
    Restart the iPad by holding down on the sleep button until the red slider appears and then slide to shut off. To power up hold the sleep button until the Apple logo appears and let go of the button.
    Reset the iPad by holding down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider - let go of the buttons.

  • Why the socket is closing

    Hi ,
    I would like to send the MimeMessage object via socket connection. To do do that i have written the following code fragment
    Socket s = new Socket("localhost",3200);
    OutputStream os = s.getOutputStream();
    MimeMessage mimemessage
    //some code to create MimeMessage
    mimemessage.writeTo(os);
    os.close() // this is important step
    In this code fragment if i didnt close the output stream the message is not being delivered to the server side. But when i close the output stream it is closing the socket connection with the stream connection.
    What i neeed is i will be sending mimemessage objects via socke asynchronously. For that purpose i would like to keep the outputstream of the socket keep opent always. But how can i send the mimemessage object via socket without closing the stream.
    I tried os.flush() also. but no result.
    Please help me.
    thanks in advance,
    Sridhar reddy .R

    I am not using any server n server is simple java server socket.
    here is the code for server
    public class MyServer extends Thread
    public static void main(String[] a)
    ServerSocket sss= newServerSocket(3200);
    while(true)
    Socket s = ss.accept();
    new MyServer(s).start();
    public MyServer(Socket socket)
    this.socket = socket;
    is = socket.getInputStream();
    public void run()
    while(true)
    Properties prop = System.getProperties();
    Session session = Session.getInstance(prop, null);
    MimeMessage mimemessage = new MimeMessage(session,objectStream);
    // do some operations on this message

  • Connection reset when closing the client program.

    when closing the client program I get the error message Connection Reset
    at ServerThread.run(SeverThread.java:244)
    which is the following file
    i've marked the 244: on this file on the left of the file.
    after this I have the client program which is called Client.java
    the error happens when I close the client program and the error is on the serverthread side of the application. Please anyone help out with this one.. Thanks.
    //SererThread.java
    import java.net.*;
    import java.io.*;
    import java.util.Date;
    import java.util.Calendar;
    import javax.swing.*;
    public class ServerThread extends Thread {
    private Socket socket = null;
    String outputStrings = "";
    public ServerThread(Socket socket) {
         super("ServerThread");
         this.socket = socket;
         Calendar c = Calendar.getInstance();
         int hr = c.get(Calendar.HOUR_OF_DAY);
         int hour=hr-1;
         int min = c.get(Calendar.MINUTE);
         int sec = c.get(Calendar.SECOND);
         String timeOfConnect [] = new String[100];
         int conCtr = 0;
    int curState = 0;
         String entries [][] = new String[5][100];
    public String getInput(String theInput) {
    String sentToClient = null;
         Calendar c = Calendar.getInstance();
         int hr = c.get(Calendar.HOUR_OF_DAY);
         int hour=hr-1;
         int min = c.get(Calendar.MINUTE);
         int sec = c.get(Calendar.SECOND);
         int day = c.get(Calendar.DAY_OF_WEEK);
         int month = c.get(Calendar.MONTH);
         int year = c.get(Calendar.YEAR);
         int pm = c.get(Calendar.PM);
         String strHr = Integer.toString(hour);
         String strMin = Integer.toString(min);
         String theInputSeg = "";     
         if(theInput!= null)     
         for(int a=0;a<theInput.length();a++)
              char inputCharArray [] = theInput.toCharArray();
              if(inputCharArray[a]==';')
                   theInputSeg = theInput.substring(0,a);
    if (curState == 0) {
    if(c.PM==1&& hour == 8)
         sentToClient = "yes";
    curState = 1;
    } else if (curState == 1) {
         for(int a=0;a<3;a++)
                   //System.out.println("theInput:" + theInput);
                   //System.out.println("a:" + entries[0][a]);
                   //System.out.println("a:" + entries[1][a]);               
                   //if()
                   if(theInputSeg.equalsIgnoreCase("CUSCarissa_Calton25242526")||theInputSeg.equalsIgnoreCase("CUSSan_Htat27242526")
                        ||theInputSeg.equalsIgnoreCase("CUSSadam_Husien20909990"))
                   //if(theInput.equalsIgnoreCase(entries[0][a])||theInput.equalsIgnoreCase(entries[1][a]))
                        System.out.println("buy...");
                        curState = 0;
                        sentToClient = "Bye.";
                   else
                        System.out.println("buy...!");
                        curState = 0;
                        sentToClient = "Hello.";
    return sentToClient;
    public void run() {
         int next = 0;     
         BufferedWriter bw = null;
         byte [] b = null;
         BufferedWriter bw1 = null;
         try{
    //JOptionPane.showMessageDialog(null,"Sizz");
    String fileNameStr = "C:\\San Server Data\\cInputCustData.txt";
    File f = new File(fileNameStr);
    long size = f.length();
    b = new byte[(int)size];
    FileInputStream fis = new FileInputStream(f);
    BufferedInputStream bis = new BufferedInputStream(fis);
    int count = 0, index = 0;
    int byteRed = 0;
    int sizeInt = (int)size;
    while (bis.available() > size-1)//16848 )
    bis.read(b,index,(int)size);
    //int bytesRead = bis.read(b,index,(int)size2);
    //size2 -= count;
    //index += count;
    //System.out.println( "hello:" + b[index]);
    //index++;
    //bis should be closed in a finally block.
    bis.close() ;
    catch(IOException io)
    System.out.println("Oh oh io error");
         //System.out.println("cInputCustData: \n" + new String(b));
         String bStr = new String(b);
         char charbStr []= bStr.toCharArray();
         String header []= new String[5];
         int ctr = 0;
         int e = 0;
    boolean first = true;
         for(int q=0;q<5;q++)
              for(int u=0;u<100;u++)
                   entries[q]= new String("");                    
         //System.out.println("b: " + bStr);
         for(int s=0; s<charbStr.length;s++)
              if(s<charbStr.length-1)
              if(charbStr[s]==':'&&charbStr[s+1]==':')
                   //System.out.println(" s0: " + s);                    
                   for(int ss=s+2;ss<s+12;ss++)
                        //System.out.println("ss: "+ ss + " s: " + s);                         
                        if(charbStr[ss]==':')
                             //System.out.println("in");     
                             header[ctr] = bStr.substring(s,ss);               
                             //System.out.println("1ss: " + ss + " s: " + s);          
                             for(int c=ss+1;c<charbStr.length;c++)               
                                  if(charbStr[c]==':')
                                       //System.out.println("ctr: " + ctr + " " +"entries[0]" + entries[0][0]+ "\n"+ entries[0][1] + "\n" + entries[1][0] + "\n" + entries[1][1]);
                                       if(ss<charbStr.length)entries[ctr][e++] = bStr.substring(ss+1,c);
                                       //System.out.println("c:" + c);
                                       ss= c;
                        ctr++;
                        e=0;
              //System.out.println("header: " + header);                         
                                  //System.out.println("entires[0]0: " + entries[0][0]);
                                  //System.out.println("entires[0]1: " + entries[0][1]);
                                  //System.out.println("entires[1]0: " + entries[1][0]);
                                  //System.out.println("entires[1]1: " + entries[1][1]);
                                  //System.out.println("entires[2]0: " + entries[2][0]);
                                  //System.out.println("entires[2]1: " + entries[2][1]);
              String timeConnect[][] = new String[5][100];
              char myChars[] = null;
              for(int d=0;d<5;d++)
                   for(int f = 0;f<100-1;f++)
                        for(int cs=0;cs<entries[d][f].length();cs++)
                             if(!(entries[d][f].equals("")))
                                  myChars = entries[d][f].toCharArray();
                             for(int a=0;a<entries[d][f].length();a++)
                                  if(myChars[a]==';')
                                       for(int k=a;k<entries[d][f].length();k++)
                                            timeConnect[d][f]= entries[d][f].substring(a,k);
                                       //     System.out.println("time: " + timeConnect[d][f]);
         //for(int o=0;o<5;o++)
              //System.out.println("Header["+o+"]" + header[o]);
         try {
         PrintWriter output = new PrintWriter(socket.getOutputStream(), true);
         BufferedReader input = new BufferedReader(
                        new InputStreamReader(
                        socket.getInputStream()));
         String inLine, outLine;
         outLine = getInput(null);
         output.println(outLine);
         while ((inLine = input.readLine()) != null) {
    244: outLine = getInput(inLine);
              output.println(outLine);
              System.out.println(inLine);
              outputStrings += inLine;
              //if(inLine.equals("Hello."))break;
              timeOfConnect[conCtr++]= " " Integer.toString(hour)":"+Integer.toString(min)+":"+Integer.toString(sec);
              if(c.PM==1){System.out.println("HL");timeOfConnect[conCtr-1]+="PM";}
              System.out.println(timeOfConnect[conCtr-1]);
              outputStrings += "\n"+ timeOfConnect[conCtr-1];
              //System.out.println("output");     
              try {
                   //FileWriter fw1 = new FileWriter("C:\\San Server Data\\Connectlog.txt");
                   bw1 = new BufferedWriter(new FileWriter("C:\\San Server Data\\Connectlog.txt",true));
                   //PrintWriter pw2 = new PrintWriter(bw1);
                        System.out.println(outputStrings);
                        //pw2.println(outputStrings);
                        if(next == 0)          
                             bw1.write(outputStrings);
                        if(next == 1)
                             bw1.write(outputStrings+ " D");
                        bw1.newLine();
                        bw1.flush();
                   //pw2.close();
                        catch (IOException io) {
                   System.out.println("Oh oh, Got and IOException error!"+io);
                        finally{
                             if(bw1 != null) try{
                                  bw1.close();
                             catch(IOException io)     
         output.close();
         input.close();
         socket.close();
    if(next == 0)next = 1;
         else if(next == 1)next = 0;
         //WONCUS1 won = new WONCUS1();
         //String m[] = new String[1];      
         //won.main(m);
         //won.start();     
         } catch (IOException err) {
         err.printStackTrace();
    //Client.java
    public class Client {          
    public static Socket Socket = null;
    public static BufferedReader i = null;
         public static PrintWriter o = null;
         public static String packetString = "CUSCarissa_Calton25242526"; //product id
         public static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    public static String fromServer;
    public static String fromUser;
    public static void main(String[] args) throws IOException {
         int ars=0;
         if (args.length > 0)
              ars = Integer.parseInt(args[0]);
    try {
         Socket = new Socket("localhost", 4444);
    o = new PrintWriter(Socket.getOutputStream(), true);
    i= new BufferedReader(new InputStreamReader(Socket.getInputStream()));
    } catch (UnknownHostException err) {
    System.err.println("Can not find Server!");
    System.exit(1);
    } catch (IOException e) {
    System.err.println("Couldn't get initialisation files to be represented in true statement!");
    System.exit(1);
    while ((fromServer = i.readLine()) != null) {
         //int hour = Integer.parseInt(fromServer);
         //System.out.println("Server: " + fromServer);
         System.out.println("Server: " + fromServer);     
         if (fromServer.equals("Bye."))
    break;
         if (fromServer.equals("Hello."))
    break;
    fromUser = packetString;
         if (fromUser != null) {
    System.out.println("Client: " + fromUser);
    //o.println(fromUser);
              String getComp = InetAddress.getLocalHost().getHostName();
              String ip = InetAddress.getLocalHost().getHostAddress();
              o.println(fromUser+";"+getComp + " " + ip);
              //o.println(getComp + " " + ip);

    "onclose event of application", at least do something such as call wait() on ReadersWhy? Who is going to notify() it?
    and close the Sockets and then Readers/WritersI won't even ask why about that because it is 100% dead wrong. Close the outermost Writer or OutputStream. That flushes the output, closes the socket, and closes any input streams or readers. Taking your advice the flush() cannot occur. But the evidence is that he is closing the socket: in fact the operating system does that anyway. Possibly he needs to take the advice about closing the Writer/OutputStream, to cause the flush(), which might stop the server from writing. But that depends on the application. If it's legal in the application protocol for the client to exit while the server is still writing he will just have to put up with the 'connection resets', or at least interpret them properly rather than just logging them as an error.
    If your using a window(GUI) you can use the main frame with a Window closing event.And that's completely irrelevant because the error happens on the server.

  • How to send to the socket EOF flag? Only socket.close() works fine :)

    I send a binary file from server socket to client socket. And I have some problem with client (but actually with server :) ).
    That is my server code which sends a file:
    OutputStream os = null;
    FileInputStream fis = null;
    try{
        fis = new FileInputStream( "some-file.png" );
    } catch ( FileNotFoundException e1 ) {}
    try {
        os = socket.getOutputStream();
        int c = -1;
        while( ( c = fis.read() ) != -1 ) {
            os.write( c );
        os.flush();
    //    os.close();
    } catch ( IOException e2 ) {}And that is client which receives a file:
    try {
        int sChunk = 8192;
        InputStream is = socket.getInputStream();
        FileOutputStream out = new FileOutputStream( "file.png" );
        byte[] buffer = new byte[ sChunk ];
        int length;
        while ( ( length = is.read( buffer, 0, sChunk ) ) > -1 )
            out.write( buffer, 0, length );
        out.close();
    } catch ( IOException e ) {
    }A client's while never continues cause I don't know how to send EOF from server.
    If I do: "os.close();" at the end of server sending - it works... But.. It closes my socket! But I want to work with socket after that :)
    How to send correct EOF flag from server? I think it's the root of all problems here..
    Edited by: JavaProger on Mar 22, 2009 4:43 PM

    os = socket.getOutputStream();
    int c = -1;
    while( ( c = fis.read() ) != -1 ) {
    os.write( c );
    }That's about as inefficient as it could be. Try this:
    int count;
    byte[] buffer = new byte[8192];
    while ((count = fis.read(buffer)) > 0)
    os.write(buffer, 0, count);
    os.close();
    Hmm, you're doing that in the client, why not in the server?
    } catch ( IOException e2 ) {}Never ignore an exception. In this case you should close the socket.
    } catch ( IOException e ) {See above.
    A client's while never continues cause I don't know how to send EOF from server.You can't send an EOF from the server. You can cause an EOS (end of stream on the socket) at the reader, by closing the socket, or shutting down its output, but then you can't send anything else on the socket. You have two choices:
    (a) use a connection per file. If the files are large the overhead is minimal.
    (b) use an application protocol to tell the reader when the file is complete. Typically this takes the form of sending the file length as a long first, and taking care to read exactly that many bytes when reading, which takes a bit of care, especially on the last buffer. Another way is to send the length ahead of each buffer, sending zero after the last buffer. You can do all this with the methods of DataInputStream and DataOutputStream.

  • Detecting unsent data when closing a socket

    I'm currently using a non-blocking socket to send data to a remote server. Whenever the application detects that the connection has been closed remotely, it will close the local connection, however netstat reports that there is unsent data still in the TCP/IP buffers.
    What I'd like to do is check within the application whether there is any unsent data at the time the socket is closed. I've read that SO_LINGER can be used in such circumstances and then checking the return code on closing the socket, but it's unclear whether this will work in non-blocking mode.

    Instead of closing the PrintWriter just flush it. Then do shutdownOutput, then close either the PrintWriter or the socket - you don't need to do both.

  • Im in the military and im deployed right now i got a ipod touch but it wont let me down load apps . i put all my billing info in and my address but it keeps telling me to contact the support to complete my transaction

    im in the military and im deployed right now i got n ipod touch but it wont let me download apps . i put all my billing info and address in but it keeps telling me that i need to contact the support to complete my transaction

    it keeps telling me that i need to contact the support to complete my transaction
    Then contact Support.
    http://apple.com/support/itunes/contact/

  • Need help on the below query.

    Hi All,
    I've a query given below..
    SELECT W.WONUM,
         W.STATUS,
         WS.CHANGEDATE,
         EH.OLD_RATE
         FROM
         WORKORDER W,
         WOSTATUS WS,
         ESTIMATE_HEADER@GQMFOF EH
    WHERE WS.CHANGEDATE BETWEEN '01-Oct-2009' AND '1-Nov-2009'
    AND W.WONUM = WS.WONUM
    AND EH.OLD_RATE = 'N'
    AND WS.WOSTATUS = 'CLOSE';
    I would like to get All the data which status =closed in the month of Oct for Old rate,
    So for this i am writing the query above. But not getting the o/p.
    It is giving me that " Table/View doesn't exist.
    There 2 schemas MAXIMO,GQMMGR..
    DBlinks are GQMFOF,MAXFOFNC..
    Can anyone help me while writing the above query...
    Regards,
    gr.

    A question was asked in your other thread. But the problem was you dint care to give an answer.
    Dont open duplicate post.
    I need help on the below problem..

  • Trouble getting the socket object to work

    I'm trying to pull an external XML file into InDesign, so I know I need to use the Socket object. I went to the documentation and copied/pasted the code from there:
    reply = "";
    conn = new Socket;
    // access Adobe’s home page
    if (conn.open ("www.adobe.com:80")) {
    // send a HTTP GET request
    conn.write ("GET /index.html HTTP/1.0\n\n");
    // and read the server’s reply
    reply = conn.read(999999);
    conn.close();
    When I ran it, I received this error message:
    So, I'm stuck! Either Adobe's code sample has an error, or, more likely, there's something wrong on my end. If I had to guess, I'd guess that it's some kind of proxy problem, but I don't know for sure and don't know how to find out.
    Can anyone help? The principles of the Socket object make sense to me, but if I can't get even the sample to work, I don't really have anywhere to go with this.

    i know that's not the swf object. But I tried to use that
    little tutorial and it isn't like one size fits all. The previous
    code i used had a bunch of parameters that are not present in this
    swf object thing.
    Any advice would be great.

  • Extending the Socket class...

    I need some help. The class below, SimpleSocket, extends the built-in
    Socket class and adds two methods to it. These methods are meant to
    make the class a bit more user-frienly but simplifying the reading-from
    and writing-to a Socket object. Here it is:
    bq. import java.net.*; \\ import java.io.*; \\ public class SimpleSocket extends Socket { \\ BufferedReader in; \\ PrintWriter out; \\ public void println(String line) throws IOException \\ { \\ if (out == null) { out = new PrintWriter(this.getOutputStream(), true); } \\ out.println(line); \\ } \\ public String readLine() throws IOException \\ { \\ if (in == null) { in = new BufferedReader( new InputStreamReader(this.getInputStream())); } \\ return in.readLine(); \\ } \\ }
    If I want to create a new SimpleSocket, it's easy - I can instantiate it like a normal Socket:
    bq. SimpleSocket socket = new SimpleSocket(host,port); // assume host & port have been defined
    Now, lets say I have a Socket object that I didn't created - for
    example, a Socket returned from the ServerSocket class - like this:
    bq. ServerSocket serverSocket = new ServerSocket(port); \\ Socket clientSocket = serverSocket.accept(); // returns the socket for communicating with a client
    Now that I have a regular Socket object, is there some what to
    "upgrade" it to a SimpleSocket? Something like this: (pseudocode):
    bq. clientSocket.setClass(SimpleSocket); // this is pseudocode
    Or, could I make a SimpleSocket constructor that accepted a Socket
    object as a parameter and then used it instead of creating a new
    object? Like this: (psuedocode):
    bq. public SimpleSocket(Socket S) \\ { \\ super = S; // this is pseudocode \\ }
    Any ideas would be greatly appreciated.
    Lindsay
    Edited by: lindsayvine on Sep 15, 2007 10:50 PM

    lindsayvine wrote:
    Ok, this makes sense and this is what I will probably do. However, there are three limitations to this method that I don't like:
    1. I would like to be able to pass the SimpleSocket object around as a normal Socket. I would like SimpleSocket to be castable to a Socket.Would you? What for? Are you sure? Would input and output streams not be better objects to pass around? You might well have the requirement you say you have, but I say it's an assumption to be challenged, at the very least
    2. I would like every method of the Socket object to be available - this would means that I have to rewrite out every method in SimpleSocket - instead of just saying "hey SimpleSocket, you should have every method Socket has"Yep. But using inheritance simply to avoid some typing is no reason to use inheritance. This is all providing that you need to have every method available. Remember, if any dependent code needs the underlying socket object, your interface can always expose it
    3. If I do write out every method, but then the Socket object gets new methods in future versions of Java, I will have to add the new ones.Likewise, in the case of such a change to java.net.Socket, your subclass has a very real chance of breaking. Again, consider if your code needs to exactly replicate everything a Socket does
    Can you think of any way around these problems?
    Sure. Re-think your design

  • I closed the cover on my IPad with a draft email open.  Now I can only edit the email but cancel and send are grey and nothing else in email seems to work.  What to do?

    I closed my iPad cover with a draft email open.  When I reopened the cover, the cancel and send buttons are grey and all I can do is edit the email.  The email app seems frozen.  What do I do?

    Try closing the Mail app completely and see if it works properly when you re-open the app : from the home screen (i.e. not with the Mail app 'open' on-screen) double-click the home button to bring up the taskbar, then press and hold any of the apps on the taskbar for a couple of seconds or so until they start shaking, then press the '-' in the top left of the Mail app to close it, and touch any part of the screen above the taskbar so as to stop the shaking and close the taskbar.
    If that doesn't work (or if you can't get to the homescreen) then do a reset : press and hold both the sleep and home buttons for about 10 to 15 seconds (ignore the red slider), after which the Apple logo should appear - you won't lose any content, it's the iPad equivalent of a reboot.

  • Need to suspend the account

    Dears,
    I have an Month contract with BT for unlimited Broadband and Unlimited Calls.
    Now I am leaving my current address. And travelling outside UK for couple of months.
    I asked to suspend the account for couple of months till back and move to a new UK address. That I don't want the new tenant to use the telephone and service for free while I am paying for that.
    BT informed me that I cant suspend the account and I will need either to cancel and pay about 300 pound ( which I don't want to do ) or to move to another address ( which I don't currently have ).
    I can continue paying for the contract while I am away . But I want to stop the service till I am back . Is that possible.
    Please advice urgent.
    Regards
    Ramycoo

    Hi,
    If you haven't got the address after 60 days then you'd need to close the account down completely, there's no way to leave it suspended longer than that I'm afraid. It's also a bad idea to order outgoing calls barred on your line and then just leave it running. You'll still be paying a monthly charge for your services, as as soon as somebody moves into your old house and orders a service in their name it will automatically close down your account and charge you whatever the early termination charges are.
    You can give the address of someone who already has a phone service as long as they are happy for you to - when you give their address they'll receive a letter letting them know that you plan to take their phone services over on the day you give to BT, so as long as you remember to cancel or change your order before the service is due to go live you won't have a problem.
    Good luck!

  • Information message when the job gets completed

    Hi,
      In foreground if i click a button a background job is scheduled.Now my need is when the job gets completed i need to inform the user that the job got completed.How to get that information message once it gets completed.Plz help

    check sy-subrc value after completion of the job.....
    if sy-subrc = 0.
        message i398(00) with 'You have succeeded'.
    endif.

Maybe you are looking for

  • SSL VPN IP Address Assignment from IAS radius server

    Can I use SSL VPN IP Address Assignment from IAS radius server?it can be done with acs server.are there some differ from the acs and IAS?

  • DVD from HD720 is extremely pixelated- Please Help

    Hi I've shot a project with HD (HM171 on a P2 Card) and edited as DVCPRO HD 720 I've made the film as a multi image (3 layers/images on one screen) and tried exporting to DVD Studio Pro on a number of formats but all results are very heavily pixelate

  • Order of Installation?

    I am setting up a proof of concept 11g Release 1 Fusion Middleware environment, but I'm a bit confused regarding the installation order. I am coming to this environment with a background with OracleAS 10g Release 2. I have found various quick install

  • Format of setting proxy server

    Hi All, can anyone tell me what is the format of setting the proxy server as , i m just giving the http:\\username:password@ipaddress:8080 but this is not working. I used the same ip address,which i used in my ie settings Thanks & Regards, Nandini Th

  • How to troubleshoot JVM performance issues

    We recently had a performance issue with our application running on Java 1.4.2 on Windows where the CPU utilization was extremely high. Using the +PrintClassHistogram option I was able to determine that a char array was utilizing more than 500 megaby