Properly closing socket and killing thread in cmd window

Hey all,
I'm creating my socket connection in a program that i am running in a cmd window. For what i need in my prog, i have a loop that tries to connect every 5 seconds, and even after that, I need to continue looping to check and try to connect.
The only way i can end the program is to cntrl-c or X out of the program. What i need to know is there a way to properly clean up the thread and close the socket w/o any memory leak issues?
Thanks

What i need to know is there a
way to properly clean up the thread and close the
socket w/o any memory leak issues?All modern popular use OSes clean sockets, threads and memory (normal) when the application exits for any reason at all.

Similar Messages

  • Cannot paste in a cmd window

    I recently lost the ability to paste inside a CMD window.  I have always had this capability and can still do it from other machines.  Quick Edit and Insert modes are on.  I can copy and paste anwhere else in the UI.  I can copy and paste within the CMD window.  I just cannot copy and paste from outside the CMD window to within the cmd window.  I live inside the CMD window so it is a real nuisance to have lost this.  Any ideas?  Also, this happens regardless of permissions.  Same results on this system whether or not I have admin priivileges and happens if I run a standard cmd window or if I run as an Administrator.  Does not matter whether I right click in the cmd window or Edit\Paste.  When I do Edit\Paste, Paste is available and not greyed out but it does not do anything.  If go to say notepad, I can paste the contents there, so I know the data is still in the clipboard.  Any help would be greatly appreciated.

    One additional observation.  If I disable UAC and reboot, I can then paste in the cmd window.  Once I re-enable UAC I lose the ability to paste in the cmd window.  I can't keep UAC disabled becasue it is against company policy.  And it worked fine for over a year with UAC enabled. The has to be some registry setting or local policy that controls this.  I just can't seem to find anything on it.  I have found others in various forums reporting the same problem but have never yet seen any solution. 

  • How to kill parent and child thread in sequnece

    Hello freinds,
    I have one class FirstClass which creates one thread Pserver and Pserver creates three threads then how to kill parent Pserver and child threads.........

    define a method that requests that the parent thread terminate itself, and within the code called when the thread is shutting itself down, have it do something similar to its child threads: call methods that request they shutdown themselves.
    One common way to do this is to interrupt the thread.

  • Implementing sockets and threads in a jframe gui program

    Hi, I am trying to find a solution to a problem I am having designing my instant messenger application.
    I am creating listening sockets and threads for each client logged into the system. i want to know if there is a way to listen to other clients request from the main gui and then if another client tries to establish a connection with me for example, a thread is created for that client and then my chat gui opens automatically has soon has the other client sends his or hers first text message to me.
    I am relatively new at socket programming has I am currently studying along this area. I know how to create threads and sockets but I am having trouble finding out a solution to my problem. Here is the code that I have done so far for the listening method from my main gui, and the thread class of what I have done so far.
    listening socket:
         private void listeningSocket()
                ServerSocket serverSocket = null;
                boolean listening = true;
                try
                    //listen in port 4444;
                    serverSocket = new ServerSocket(4444);
                catch(IOException x)
                    JOptionPane.showMessageDialog(null, "cannot listen to port 4444", null, JOptionPane.ERROR_MESSAGE);
                while(listening)
                    client_thread w;
                    try
                       w = new client_thread(serverSocket.accept(), jTextArea1);
                       Thread t = new Thread(w);
                       t.start();
                    catch(IOException x)
                         JOptionPane.showMessageDialog(null, "error, cannot start new thread", null, JOptionPane.ERROR_MESSAGE);
            }thread class:
    import java.io.*;
    import java.net.*;
    import javax.swing.*;
    import java.sql.*;
    import java.awt.event.*;
    * @author jonathan
    public class client_thread extends Thread
         //define new socket object
        private Socket client_user = null;
        private JTextArea textArea;
        public client_thread(Socket client_user, JTextArea textArea)
            this.client_user = client_user;
            this.textArea = textArea;
        public void run()
            BufferedReader in = null;
            PrintWriter out = null;
            String error = "error has occured, messege was not sent";
            String messege = null;
             try
                //create input and output streams
                in = new BufferedReader(new InputStreamReader (client_user.getInputStream()));
                out = new PrintWriter(client_user.getOutputStream(), true);
                while(true)
                   //read messege sent by user
                   messege = in.readLine();
                    //display messege in textfield
                   out.println(messege);
                   textArea.append(messege);
            catch (IOException e)
                //error messege
                JOptionPane.showMessageDialog(null, error, null, JOptionPane.ERROR_MESSAGE);
    }

    Seems like all you need to do is create a new dialog for each socket that is established. Your current design looks like it will attempt to use the same textarea for all the sockets.
    I would say in your thread class do the following:
    MyConversationDialog dialog = new MyConversationDialog();
    while(true)
                   //read messege sent by user
                   messege = in.readLine();
                    //display messege in textfield
                   out.println(messege);
                   dialog.setVisible (true);
                   dialog.addMessage (message);
                }

  • Sockets and thread communication multiplexing?

    Hello,
    I need to implement a server which will have a maximum of 10 clients connected.
    I wanted to go for classic blocking I/O because I won't have much clients.
    My problem is that even if I accept() some sockets and then create a thread for each socket,
    then I still need to communicate some data to the other threads, problem is that I am blocked
    on the read() operation, how could I address this problem?
    I mean, lets say I am thread1 and blocked on read() on my socket, now thread7 wants to tell
    me something like a chat message coming from client he handles, how could thread7 manage
    to wake thread1 and send him a message somehow?
    I do not want to deal with NIO stuff if possible because I do not need to scale, I just have a
    problem because I am stuck on the read.
    I will run on Windows.
    Thanks for help.
    Edited by: Marzullo on Jul 15, 2010 1:05 PM

    Fully answered in [your other thread|http://forums.sun.com/thread.jspa?threadID=5445070&messageID=11020688#11020688].
    Please don't multipost, as it can lead to people wasting their time repeating others' answers.

  • Socket and Thread Problem

    When reading an Inputstream received after a connection has been established (throught a Socke connect) between a Server ands a Client , messages are being lost when a wait method is call. A client sents message which have to be processed and response sent back to the client . The message are encoded and as the code below shows each message ends with a '":" .Not only one message is sent at a time. and when messages are sent the client sometimes expect replies. This means that when a message is read , it be being processed by a Processor and until the reply has be sent this the thread reading the messages has to wait. when a reply is sent and the thread is waken up, the remaining the messages in the Input stream gets lost but the loop is not also exited since the end of the file is never reached.
    Solution:
    1. read a command message. if you find end of message, process the message and wait until you are notify and continue with the next command line
    public class Sender extends Thread {
         private Socket socket;
         private Processor processor = newProcessor();
         private boolean DEBUG = false;
         public Sender (Socket socket) {
              super();
              this.socket = socket;
              start();
         public void run() {
              while (true) {
                   if (processor .getStateOfProcess()&& socket != null) {
                        InputStream input = null;
                        try {
                             input = socket.getInputStream();
                             if (processor .dispatchMessage() != null) {
                                  socket.getOutputStream().write(
                                            CacheManager.dispatchMessage());
                                  processor .ClearMessage();
                        } catch (IOException ex) {
                        int i = 0;
                        char oldChar = ' ';
                        char c = ' ';
                        StringBuffer buffer = new StringBuffer();
                        try {
                             while ((i = input .read()) != -1) {
                                  c = (char) i;
                                  buffer.append(c);
                                                    if (c == ':' && oldChar != '\\') {
                                       processor .process(buffer.toString());
                                       buffer = new StringBuffer();
                                       c = ' ';
                                                              try {
                                            synchronized (this) {
                                                 wait();                         
                                       } catch (InterruptedException e1) {
                                                       if (processor.dispatchMessage() != null) {
                                            socket.getOutputStream().write(
                                                      CacheManager.dispatchMessage());
                                            processor.ClearMessage();
                                  oldChar = c;
                                    } catch (IOException e) {
       public void wakeup() {
              synchronized (this) {
                   notify();
    } This thread leaves that wait when the wakeup method is called in the Processor class.
    Question
    can some one help me figure out way and where the messages are being lost after the first message has been processed. why can the other message not be seen even other messages are still sent.
    What can be a possible solution
    thanks

    I didn't follow all of that, but I can see one serious error in your concurrent. You should always test the condition you're waiting for inside the synchronized block - otherwise you can't be certain that wait() is called before the corresponding notify() / notifyAll() call.

  • Does closing socket with close() also closes the outputStream and inputStre

    hi i have a simple query
    does closing socket with close() also closes the outputStream and inputStream() associated with the socket

    Yes.

  • Detecting (And Killing) Abandoned Threads

    Hi All,
    I'm going to try to make my question as simple as possible: I'm trying to use the service guardian to automatically detect an abandoned thread and kill the originating process. So basically I set up a test that ends up with an abandoned thread and configured service Guardian... but it didn't work :D
    What I first did is setting the guardian's timeout to be very short (6 seconds). When I do that, what I get is:
    2010-03-26 10:03:29.389/0.859 Oracle Coherence GE 3.5.3/465 <Info> (thread=main, member=n/a): Loaded cache configuration from "file:/C:/workspaces/POC/InvocableTest/bin/coherence-cache-config.xml"
    2010-03-26 10:03:29.952/1.422 Oracle Coherence GE 3.5.3/465 <D5> (thread=Cluster, member=n/a): Service Cluster joined the cluster with senior service member n/a
    2010-03-26 10:03:35.295/6.765 Oracle Coherence GE 3.5.3/465 <Error> (thread=Cluster, member=n/a): Attempting recovery (due to soft timeout) of Guard{Daemon=TcpRingListener}
    2010-03-26 10:03:35.904/7.374 Oracle Coherence GE 3.5.3/465 <Error> (thread=Cluster, member=n/a): Terminating guarded execution (due to hard timeout) of Guard{Daemon=TcpRingListener}
    Coherence <Error>: Halting JVM due to unrecoverable service failure
    2010-03-26 10:03:36.904/8.374 Oracle Coherence GE 3.5.3/465 <Error> (thread=Termination Thread, member=n/a): Full Thread Dump
    ThreadCluster
         java.lang.Object.wait(Native Method)
         com.tangosol.coherence.component.util.Daemon.onWait(Daemon.CDB:18)
         com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.onWait(Grid.CDB:6)
         com.tangosol.coherence.component.util.Daemon.run(Daemon.CDB:39)
         java.lang.Thread.run(Unknown Source)
    So that's before the thread gets abandoned... it seems that it detects a deadlock when starting coherence. But that's ok, I know the service guardian is working. The problem comes when I set the timeout to something more realistic: 35 seconds for instance. I run my test, the thread gets to an abandoned state and the service guardian does not see it :(
    Any Ideas?
    h4. My override config is:
    <coherence>
    <cluster-config>
         <service-guardian>
              <timeout-milliseconds system-property="tangosol.coherence.guard.timeout">6000</timeout-milliseconds>
              <service-failure-policy>exit-process</service-failure-policy>
         </service-guardian>
    </cluster-config>
    <logging-config>
    <severity-level system-property="tangosol.coherence.log.level">5</severity-level>
    <character-limit system-property="tangosol.coherence.log.limit">0</character-limit>
    </logging-config>
    </coherence>
    Thanks!
    Fernando
    Edited by: ZeoS on Mar 26, 2010 7:13 AM

    it's an Invovable running on the server.
    The description in the debugger is: InvocationServiceWorker
    Maybe this helps:
    10-03-26 12:03:41.279/72.663 Oracle Coherence GE 3.5.3/465 <Error> (thread=Abandon, member=1): A worker thread "InvocationServiceWorker:0 executing task "Message "InvocationRequest"
    FromMember=Member(Id=1, Timestamp=2010-03-26 12:02:29.866, Address=10.31.106.86:8088, MachineId=32598, Location=site:someSite.com,machine:ZeoSWorkStation,process:1084, Role=TestInvocableExpiration)
    FromMessageId=0
    Internal=false
    MessagePartCount=0
    PendingCount=0
    MessageType=1
    ToPollId=0
    Poll=null
    Packets
    Service=InvocationService{Name=InvocationService, State=(SERVICE_STARTED), Id=3, Version=3.1, OldestMemberId=1}
    ToMemberSet=MemberSet(Size=1, BitSetCount=2, ids=[1])
    NotifySent=false
    InvocationRequest{Query, Task=TestInvocableExpiration.SocketInvocable@16b352c}
    }", did not respond to 8 interrupt requests. The execution was canceled. The thread is abandoned...
    Fernando

  • When closing my Firefox window, all processes are not closing requiring me to open task manager and kill the process before using Firefox again. Received recent upgrade and hasn't worked right since then.

    I open Firefox, use it, then close the window. Try to reopen Firefox and it fails with a message that a previous process is still running. Requires me to open Task Manager and kill the old process.

    Try to wait a bit longer before reopening Firefox to give Firefox more time to close completely.<br />
    Try to use "Firefox/File > Exit" (Mac: "Firefox > Quit"; Linux: "File > Quit") to close Firefox if you are currently doing that by clicking the close X on the title bar.
    See "Hang at exit":
    *http://kb.mozillazine.org/Firefox_hangs
    *https://support.mozilla.com/kb/Firefox+hangs

  • Socket and Security Policy

    I've tried to set experiment with Socket communication in Flex, but I keep hitting problems. Approach 1: in a Flex web app, I load a crossdomain security policy from a server. I then open a socket and write a few bytes to the server. In my server, I do not get the expected output on the stream--in fact, I get nothing at all--until I close the Flex application, at which point I get a seemingly inifinite stream of the bytes '0xEFBFBF'. Here's a hexdump view of a fragment of the data Flash Player sends to the server after I close the Flex app:
    00000130  ef bf bf ef bf bf ef bf  bf ef bf bf ef bf bf ef  |................|
    00000140  bf bf ef bf bf ef bf bf  ef bf bf ef bf bf ef bf  |................|
    00000150  bf ef bf bf ef bf bf ef  bf bf ef bf bf ef bf bf  |................|
    Approach 2: I then tried it in air, but although the connection seems to initiate properly and I can go through the above trivial client-server interaction, after a few seconds, I get a SecurityErrorEvent. From what I've been able to follow of the docs, Air applications are trusted in this respect, and should not need to load security policy, right? I tried to add a call to Security.loadPolicy(), but it seems to be ignored. This is the message flow:
    Received [class Event] connect
    Received [class ProgressEvent] socketData
    Received [class Event] close
    Received [class SecurityErrorEvent] securityError
    Security error: Error #2048: Security sandbox violation: app:/main.swf cannot load data from localhost:5432.
    The Air version of my client code is below:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:Script>
        <![CDATA[
            var str:Socket;
            private function handleClick(e:Event):void {
                Security.loadPolicyFile("xmlsocket://localhost:2525");           
                str = new Socket('localhost', 5555);
                var message:String = 'hello';
                for (var i:int = 0; i < message.length; i++) {
                    str.writeByte(message.charCodeAt(i));               
                str.writeByte(0);
                str.flush();
                str.addEventListener(Event.ACTIVATE, handleEvent);
                str.addEventListener(Event.CLOSE, handleEvent);
                str.addEventListener(Event.CONNECT, handleEvent);
                str.addEventListener(Event.DEACTIVATE, handleEvent);
                str.addEventListener(IOErrorEvent.IO_ERROR, handleEvent);
                str.addEventListener(ProgressEvent.SOCKET_DATA, handleEvent);
                str.addEventListener(SecurityErrorEvent.SECURITY_ERROR, handleEvent);           
            private function handleEvent(e:Event):void {
                 trace("Received", Object(e).constructor, e.type);
                 if (e is ProgressEvent) {
                     var strBytes:Array = [];
                     while(str.bytesAvailable > 0) {
                         var byte:int = str.readByte();
                         strBytes.push(byte);
                     trace(String.fromCharCode.apply(null, strBytes));
                 } else if (e is SecurityErrorEvent) {
                     trace("Security error:", SecurityErrorEvent(e).text);
        ]]>
    </mx:Script>
    <mx:Button label="test" click="handleClick(event)"/>   
    </mx:WindowedApplication>
    The server is in Java and is as follows:
    import java.net.*;
    import java.io.*;
    public class DeadSimpleServer implements Runnable {
        public static void main(String[] args) throws Exception {
            if (args.length != 2) {
                throw new Exception("Usage: DeadSimpleServer policy-port service-port");
            int policyPort = Integer.parseInt(args[0]);
            int servicePort = Integer.parseInt(args[1]);
            new Thread(new DeadSimpleServer(policyPort,
                                            "<?xml version=\"1.0\"?>\n" +
                                            "<cross-domain-policy>\n" +
                                            "<allow-access-from domain=\"*\" to-ports=\"" + servicePort + "\"/>\n" +
                                            "</cross-domain-policy>\n"
                       ).start();
            new Thread(new DeadSimpleServer(servicePort, "world")).start();
            while (true) Thread.sleep(1000);
        private int port;
        private String response;
        public DeadSimpleServer(int port, String response) {
            this.port = port;
            this.response = response;
        public String getName() {
            return DeadSimpleServer.class.getName() + ":" + port;
        public void run() {
            try {
                ServerSocket ss = new ServerSocket(port);
                while (true) {
                    Socket s = ss.accept();
                    System.out.println(getName() + " accepting connection to " + s.toString());
                    OutputStream outStr = s.getOutputStream();
                    InputStream inStr = s.getInputStream();
                    int character;
                    System.out.print(getName() + " received request: ");
                    while ((character = inStr.read()) != 0) {
                        System.out.print((char) character);
                    System.out.println();
                    Writer out = new OutputStreamWriter(outStr);
                    out.write(response);
                    System.out.println(getName() + " sent response: ");
                    System.out.println(response);
                    System.out.println(getName() + " closing connection");
                    out.flush();
                    out.close();
                    s.close();
            } catch (Exception e) {
                System.out.println(e);
    Am I missing something? From what I understand, either of these approaches should work, but I'm stuck with both. I have Flash Player 10,0,15,3 and am working with Flex / Air 3.0.0 under Linux.

    So... apparently, with the Air approach, this is what I was missing: http://www.ultrashock.com/forums/770036-post10.html
    It'd be nice if FlashPlayer gave us a nicer error here.
    I'm still trying to figure out what the heck is going on in the web app (i.e., non-Air Flex) example. If anyone has any suggestions, that would be very helpful.

  • Problem with socket and Flash

    I have a chat application where the client is written in Flash 9 and it connects an XMLSocket to my java server.
    Those that know Flash 9 know that it first makes a policy file request and all you have to do is provide a small chunk of xml stating the desired port and domain.
    To get a better understanding I adding some thread tracking to the server app. Now when I run the following:
    String policy_response = "<?xml version=\"1.0\"?><cross-domain-policy><allow-access-from domain=\"*\" to-ports=\"6000\" secure=\"false\" /></cross-domain-policy>"+ "\0";
    ErrorBroker.addError("name: " + this.currentThread().getName());
    String mes = "";
    if(cs.incoming.ready())
         mes = cs.readln();
         ErrorBroker.addError( this.currentThread().getName()+ " ready: " + mes);
    if(mes.equals("<policy-file-request/>" + "\0"))
         ErrorBroker.addError( this.currentThread().getName()+ " policy hit");
         cs.send(policy_response);
    counter++;
    ErrorBroker.addError( this.currentThread().getName()+" counter: " + counter);and the results I get are the following:
    name: Thread-34
    Thread-34 in ready: <policy-file-request/>
    Thread-34 policy hit
    Thread-34 counter: 1
    Thread-34 after read2: <policy-file-request/>
    END OF processClient()
      Closing socketThere is no second connection though there should be. On the flash end I get nothing..no message stating a connection made or lost.
    Now if I have the server as such:
    ErrorBroker.addError("name: " + this.currentThread().getName());     
    String mes = "";
    /* ---- policy response sent BEFORE readLine() ---- */
    cs.send(policy_response);
    if(cs.incoming.ready())
         mes = cs.readln();
         ErrorBroker.addError( this.currentThread().getName()+ " in ready: " + mes);
    if(mes.equals("<policy-file-request/>" + "\0"))
         ErrorBroker.addError( this.currentThread().getName()+ " policy hit");
    counter++;
    ErrorBroker.addError( this.currentThread().getName()+" counter: " + counter);The one difference being that the policy reply happens before any read.
    I get these results:
    name: Thread-34
    Thread-34 in ready: <policy-file-request/>
    name: Thread-35
    Thread-34 policy hit
    Thread-35 counter: 1
    Thread-34 counter: 2
    Thread-35 after read2:
    Thread-34 after read2: <policy-file-request/>
    io error1: java.lang.StringIndexOutOfBoundsException:String index out of range: 0
    END OF processClient()
    END OF processClient()
      Closing socket
      Closing socketDoes this make sense to anyone? How is it that if I do a readLine before sending the policy request file that nothing happens but I send after a readLine the second socket shows up.
    Any help is GREATLY appreciated.

    The second case does appear to be a threading issue.....but what bothers me the most is why I get nothing from flash when I readLine first. This doesn't seem to be an issue with anyone else and I've seen many examples (though almost all were written in PHP) that are exactly the same. Read first...look for the policy request...then reply accordingly.
    This is a small chat application running on Tomcat 5.5.
    It worked well back when I ran it with Flash 8 but since I upgraded to Flash 9 (had to...no other way around) I now have to deal with this policy issue (apparently it pissed off quite a few developers).

  • Conflict between socket and RMI

    Hi
    I wrote a program in client-server using socket and it was fine. I also wrote a client-server program using RMI. Fine as well. But after I connected the client-server using socket (open socket, send-receive messages, close socket), then use RMI. I got java.rmi.NotBoundException.
    Would anyone have a look and provide your feedback please? Thanks.
    big J
    *****************this is Server.java ***************************
    package single;
    import java.io.*;
    import java.rmi.Naming;
    import java.rmi.RemoteException;
    import java.net.*;
    import java.rmi.*;
    public class Server
    extends Thread {
    public static final int SOCKETPORT = 5555;
    private String serverName;
    public Server() throws IOException {
    System.out.println("*** socket opened ***");
    serverName = new String("localhost");
    ServerSocket serverSocket = new ServerSocket(SOCKETPORT);
    Socket socket = serverSocket.accept();
    InputStream is = socket.getInputStream();
    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is));
    System.out.println(bufferedReader.readLine());
    OutputStream os = socket.getOutputStream();
    PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(os), true);
    printWriter.println("from server");
    os.close();
    is.close();
    socket.close();
    System.out.println("*** socket closed ***");
    public void runServer() {
    System.out.println("*** start of run():RMI ***");
    System.setSecurityManager(new SecurityManager());
    try {
    RMIInterfaceImpl rMIInterfaceImpl = new RMIInterfaceImpl();
    Naming.bind("//" + serverName + ":9999/RMIInterface", rMIInterfaceImpl);
    catch (RemoteException ex) {
    catch (MalformedURLException ex) {
    catch (AlreadyBoundException ex) {
    System.out.println("*** end of run():RMI ***");
    public static void main(String args[]) throws Exception {
    Server server = new Server();
    server.runServer();
    ******************this is Client.java **************************
    package single;
    import java.io.*;
    import java.net.*;
    import java.rmi.Naming;
    public class Client {
    private String serverName;
    private final static int SOCKETPORT = 5555;
    public Client() throws IOException {
    serverName = new String("localhost");
    Socket socket = new Socket(serverName, SOCKETPORT);
    OutputStream os = socket.getOutputStream();
    PrintWriter printWriter=new PrintWriter(os, true);
    printWriter.println("from client");
    InputStream is = socket.getInputStream();
    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is));
    System.out.println(bufferedReader.readLine());
    is.close();
    os.close();
    socket.close();
    public void runClient() throws Exception {
    System.out.println("*** start of runClient():RMI ***");
    System.setSecurityManager(new SecurityManager());
    RMIInterface rMIInterfaceImpl = (RMIInterface) Naming.lookup(
    "//" + serverName + ":9999/RMIInterface");
    String str = rMIInterfaceImpl.print();
    System.out.println(str);
    rMIInterfaceImpl.serverSide();
    System.out.println("*** end of runClient():RMI ***");
    public static void main(String args[]) throws Exception {
    Client client = new Client();
    client.runClient();
    ***************** this is RMIInterface.java ***********************
    package single;
    import java.rmi.Remote;
    import java.rmi.RemoteException;
    interface RMIInterface
    extends Remote {
    String print() throws RemoteException;
    void serverSide() throws RemoteException;
    ********************* this is RMIInterfaceImpl.java ***************
    package single;
    import java.rmi.RemoteException;
    import java.rmi.server.UnicastRemoteObject;
    public class RMIInterfaceImpl
    extends UnicastRemoteObject
    implements RMIInterface {
    public RMIInterfaceImpl() throws RemoteException {}
    public String print() {
    return new String("hello world");
    public void serverSide(){
    System.out.println("this should appear in serverside");

    I think you have a timing problem between your client and server. As soon as your client and server programs have finished their socket communication, they will both do their "runServer"/"runClient" methods. If the client attempts to lookup the server before the server has registered itself via Naming.bind(), I would expect that's why you're getting a NotBoundException in the client.
    You probably wouldn't use the design of your test client/server for something significant, but a quick and dirty way to make this work might be to have the client call Thread.sleep() for a few seconds before trying to do the lookup.

  • Closing Sockets

    Hi all,
    Im having a big problem with the closing of sockets.
    I have a simple program which handles the sending / receiving and monitoring of HTTP traffic.
    My program has a 'sender' part which opens a socket, writes a request (using the socket output stream), reads the response (using the socket input stream, until read() == -1 ) and then closes the streams and socket.
    The 'receiver' part simply receives socket connections, reads the content (until read() == -1), writes a response, and then closes the streams and socket.
    The monitor part is a simple 'tunnel'. For each received socket connection, a connection is made to a server.
    Two threads then operate like this:
    T1) While read from client != -1, write to server
    T2) While read from server != -1, write to client
    Seems simple enough, and sort of works.
    The problem I have is cleanly closing all sockets without screwing up either the tunnel or a client.
    I try not to close the streams / sockets at the 'logical' times, but for some reason any combination I try results in Socket Closed exceptions during a read in either the tunnel or the client.
    There is a fair amount of code - so I dont expect anyone to wade thru it to find the problem, but Im just wondering if anyone has:
    1) Had similar problems and found a solution
    2) Can point me in the direction for more details on the mechanics and implications of closing socket streams
    The java docs seem very sketchy on this subject!!
    Thanks for your help!

    Thanks for the response (2 dukes for the fast reply - plenty more available on this one though!)....
    Does this mean that there is no 'clean' way to accomplish the transfer task?
    I think both examples will work, but I have a couple of issues:
    This exception is quite normal and indicates that another thread abruptly forced your socket closed or you tried to read or write after closing it yourself. You must catch it.The problem I have with this is that under these circumstances, it is a 'SocketException' which is thrown. The API says that this is thrown if 'there is an error in the underlying protocol, such as a TCP error'. So to be sure I was dealing with the right problem, I'd have to start parsing the exception text looking for "Socket Closed".
    Im keener on option 2:
    providing signalling between your threads Sounds like this is what I need.... Again there is a catch though.
    See, the thread handling the client will be in a blocking read (it will have read everything from the client, and written it to the server. However, as the client socket isn't closed yet, it doesn't know its time to stop). So, Im back to using exceptions again (Im assuming I'd have to do an interrupt?).
    I thought I could get round this on the client side by closing the output stream after writing everything (would signify to the reader thread that all is done).
    This, however, just results in the socket getting closed (my ignorance of the underlying mechanics of sockets showing through here...).
    Further, I want my 'monitor' to work with all request / response based systems - so I cant write a termination sequence on the client side to indicate end of input.
    So - Im really stuck with using exceptions as flags then??

  • MASSIVE OS X Server crashing!  Please help me!  SMB crashes and kills OSXS

    OSX Srvr 10.4.7 on a Mac Pro. I dont know what I did or missed versus every other server I've ever done, but I've got a major problem on my hands. Once a day my users have their access shut off, and i have to re-enable them. Every other morning, smb will crash so hard it kicks everyone off, then workgroup mgr won't respond anymore, and i have to hard power off the computer. This is running my company of roughly 23 users, and this replaced a Windows Server 2003. Not a good impression so far. I have logs I'm happy to post or email to anyone. They're huge, so I've obviously loused something up big time.
    We're doing simple Windows file Sharing, Apple File Sharing, VPN, and eventually FTP. It's also running Kerio Mail Server. Someone please help me!
    Here are some log examples to start with.
    crashreporter.log:
    Wed Sep 20 17:49:42 2006 crashdump[16094]: crashdump started
    Wed Sep 20 17:49:42 2006 crashdump[16094]: Started writing crash report to: /Library/Logs/CrashReporter/smbd.crash.log
    Wed Sep 20 17:49:42 2006 crashdump[16094]: Finished writing crash report to: /Library/Logs/CrashReporter/smbd.crash.log
    Wed Sep 20 17:49:42 2006 crashdump[16097]: crashdump started
    Wed Sep 20 17:49:43 2006 crashdump[16097]: Started writing crash report to: /Library/Logs/CrashReporter/smbd.crash.log
    Wed Sep 20 17:49:43 2006 crashdump[16097]: Finished writing crash report to: /Library/Logs/CrashReporter/smbd.crash.log
    system.log:
    Sep 20 17:49:42 Genesis1 crashdump[16094]: smbd crashed
    Sep 20 17:49:42 Genesis1 crashdump[16094]: crash report written to: /Library/Logs/CrashReporter/smbd.crash.log
    Sep 20 17:49:43 Genesis1 crashdump[16097]: smbd crashed
    Sep 20 17:49:43 Genesis1 crashdump[16097]: crash report written to: /Library/Logs/CrashReporter/smbd.crash.log
    Sep 20 17:51:56 Genesis1 kernel[0]: (16266: ps)tfp: failed on 0:
    Sep 20 17:51:57 Genesis1 kernel[0]: (16267: ps)tfp: failed on 0:
    Sep 20 17:51:58 Genesis1 kernel[0]: (16268: ps)tfp: failed on 0:
    Sep 20 17:51:59 Genesis1 kernel[0]: (16269: ps)tfp: failed on 0:
    Sep 20 17:52:00 Genesis1 kernel[0]: (16270: ps)tfp: failed on 0:
    Sep 20 17:54:21 Genesis1 servermgrd: servermgr_dns: no name available via DNS for 192.168.200.250
    Sep 20 17:54:21 Genesis1 servermgrd: servermgr_dns: no hostname set and unable to detect via DNS, services may not function properly - use changeip to repair
    log.smbd:
    [2006/09/20 17:56:27, 0] /SourceCache/samba/samba-100.4/samba/source/lib/utilsock.c:write_socketdata(446)
    writesocketdata: write failure. Error = Broken pipe
    [2006/09/20 17:56:27, 0] /SourceCache/samba/samba-100.4/samba/source/lib/utilsock.c:writesocket(471)
    write_socket: Error writing 124 bytes to socket 6: ERRNO = Broken pipe
    [2006/09/20 17:56:27, 0] /SourceCache/samba/samba-100.4/samba/source/lib/utilsock.c:sendsmb(663)
    Error writing 124 bytes to client. -1. (Broken pipe)
    [2006/09/20 17:56:27, 0] /SourceCache/samba/samba-100.4/samba/source/lib/utilsock.c:write_socketdata(446)
    writesocketdata: write failure. Error = Broken pipe
    [2006/09/20 17:56:27, 0] /SourceCache/samba/samba-100.4/samba/source/lib/utilsock.c:writesocket(471)
    write_socket: Error writing 53 bytes to socket 6: ERRNO = Broken pipe
    [2006/09/20 17:56:27, 0] /SourceCache/samba/samba-100.4/samba/source/lib/utilsock.c:sendsmb(663)
    Error writing 53 bytes to client. -1. (Broken pipe)
    Please reply here or consider emailing me: [email protected]
    I'm desperate!
    Mac Pro dual 2.66 Xeon   Mac OS X (10.4.7)  

    Hi Bill.
    First please note:
    "servermgr_dns: no name available via DNS for 192.168.200.250
    Sep 20 17:54:21 Genesis1 servermgrd: servermgr_dns: no hostname set and unable to detect via DNS, services may not function properly - use changeip to repair"
    Your first issue is you need to fix DNS.
    Something needs to be providing forward and reverse DNS lookup for your OS X Server.
    You might not have known this, but now you do: OS X Server -must- have working DNS. You don't need to run DNS on your OS X Server, but it needs working DNS.
    DNS configuration is a bit beyond the scope of this reply, however.
    In the meantime, edit /etc/hosts and do not touch any existing entries
    but add the following line:
    192.168.200.250 Genesis1
    and kill -HUP lookupd. If you're not sure how, perhaps just restart the computer.
    Next up, edit
    /System/Library/LaunchDaemons/smbd.plist , adding the line in bold below:
    <key>ProgramArguments</key>
    <array>
    <string>/usr/sbin/smbd</string>
    <string>-F</string>
    </array>
    Of course, the text in the file itself should NOT be "bold" formatted
    Be very sure to check the permissions on that file, and to leave them the same, or restore them if they change. It's really best to use nano/vi/emacs to edit the file, if you must use a GUI app, then go with TextWrangler or SubEthaEdit, both of which can be found at versiontracker.com
    Let us know how it goes, and I'll send this to your email as well.

  • XSD OTD compilefailure String literal not properly closed by double-quote

    Java CAPS 5.1.3
    I have created a XSD to describe a simple XML file. After this I created an OTD from the exported XSD file.
    This OTD is being used in a JCD. During the build of the Deployment Profile I get the error: :Compile failed: xsd.XSD_MB235401907.X_all_B: Line 69: String literal is not properly closed by a double-quote
    All steps have been preferformed within the same eDesigner and the same repository.
    I have verified the XSD file with netbeans and can not see a problem with the file itself.
    Any ideas to resolve this compile failure?
    The XSD is:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:tns="http://ams1saa011:12000/repository/repository/Recieve/MessageBroker/WISE_WTE/repository1423024:117d46f486a:-8000/XSDDefinition1" targetNamespace="http://ams1saa011:12000/repository/repository/Recieve/MessageBroker/WISE_WTE/repository1423024:117d46f486a:-8000/XSDDefinition1">
        <xsd:element name="MessageBroker">
            <xsd:complexType>
                <xsd:sequence>
                    <xsd:element name="IN" maxOccurs="unbounded">
                        <xsd:complexType>
                            <xsd:all>
                                <xsd:element name="MSGFN" type="xsd:string" default="IN"/>
                                <xsd:element name="DIR" type="xsd:string" default="\"/>
                                <xsd:element name="FILEMASK"
                                    type="xsd:string" default="*.DAT"/>
                                <xsd:element name="MAPID" type="xsd:string" default="MS000"/>
                                <xsd:element name="RCVPRN" type="xsd:string"/>
                                <xsd:element name="RCVPRT" type="xsd:string"/>
                                <xsd:element name="RCVPFC" type="xsd:string"/>
                                <xsd:element name="SNDPRN" type="xsd:string"/>
                                <xsd:element name="SNDPRT" type="xsd:string"/>
                                <xsd:element name="MESTYP" type="xsd:string"/>
                                <xsd:element name="MESCOD" type="xsd:string"/>
                                <xsd:element name="MESFCT" type="xsd:string"/>
                                <xsd:element name="TEST" type="xsd:boolean" nillable="true"/>
                            </xsd:all>
                        </xsd:complexType>
                    </xsd:element>
                </xsd:sequence>
                <xsd:attribute name="dateTime" type="xsd:dateTime"/>
            </xsd:complexType>
        </xsd:element>
    </xsd:schema>The complete error stack trace is:
    com.stc.codegen.framework.model.CodeGenException: error generating otd for CMap1_jcdMB_Recieve_SAP_Inbound1:Compile failed: xsd.XSD_MB235401907.X_all_B: Line 69: String literal is not properly closed by a double-quote
         at com.stc.codegen.OTDImpl.model.OTDCodeletFactory$OTDCodelet.postFileGeneration(OTDCodeletFactory.java:767)
         at com.stc.codegen.frameworkImpl.model.CodeGenFrameworkImpl.processCodelets(CodeGenFrameworkImpl.java:653)
         at com.stc.codegen.frameworkImpl.model.CodeGenFrameworkImpl.process(CodeGenFrameworkImpl.java:1544)
         at com.stc.codegen.frameworkImpl.model.DeploymentVisitorImpl.process(DeploymentVisitorImpl.java:405)
         at com.stc.codegen.frameworkImpl.model.DeploymentVisitorImpl.process(DeploymentVisitorImpl.java:308)
         at com.stc.codegen.frameworkImpl.model.DeploymentVisitorImpl.traverseDeployment(DeploymentVisitorImpl.java:268)
         at com.stc.codegen.driver.module.DeploymentBuildAction.loadCodeGen(DeploymentBuildAction.java:923)
         at com.stc.codegen.driver.module.DeploymentBuildAction.access$1000(DeploymentBuildAction.java:174)
         at com.stc.codegen.driver.module.DeploymentBuildAction$1.run(DeploymentBuildAction.java:599)
         at org.openide.util.Task.run(Task.java:136)
         at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:599)
    Caused by: java.lang.RuntimeException: Compile failed: xsd.XSD_MB235401907.X_all_B: Line 69: String literal is not properly closed by a double-quote
         at com.stc.javac.Javac.compile(Javac.java:227)
         at com.stc.otd.codegen.BaseXsdDtdGenerator.compileFromJarfile(BaseXsdDtdGenerator.java:254)
         at com.stc.otd.codegen.BaseXsdDtdGenerator.compile(BaseXsdDtdGenerator.java:52)
         at com.stc.otd.xsd.codegen.XsdParserGenerator.compile(XsdParserGenerator.java:182)
         at com.stc.otd.codegen.BaseXsdDtdGenerator.generate(BaseXsdDtdGenerator.java:166)
         at com.stc.otd.codegen.BaseXsdDtdGenerator.generate(BaseXsdDtdGenerator.java:90)
         at com.stc.codegen.OTDImpl.model.CollabOTDGenerator.generateCollabOTDJavaFiles(CollabOTDGenerator.java:233)
         at com.stc.codegen.OTDImpl.model.OTDCodeletFactory$OTDCodelet.processOTDJars(OTDCodeletFactory.java:861)
         at com.stc.codegen.OTDImpl.model.OTDCodeletFactory$OTDCodelet.postFileGeneration(OTDCodeletFactory.java:666)
         ... 10 more

    You may need to escape the default slash "\\".
    I'd suggest importing the xsd into the jcaps xml schema editor and verifying that way and then creating the otd by node export.
    Regards,
    Rupert

Maybe you are looking for

  • Error message downloading BB Desktop Manager

    For some reason I get a constant error message (not defined) when trying to download BB Desktop Manager. Any advice ?

  • Self-assigned IP address problem - My solution

    I am new to this board and created an ID just to write this post. When I searched for this self-assigned IP problem, I found almost 1 million results on Google so obviously I am not alone. I have this problem off and on on the wireless network at hom

  • How to send Java Mail with EXCEL attachment?

    I tried the following: ByteArrayDataSource bs = new ByteArrayDataSource (is, "application/excel"); as my datasource (all other apis are fine) But when I send this message with this datasource as attachment,I get a ParseException with the VM complaini

  • Problem with video display with FinalCut

    When I view a media in the canvas window or the viewer window, the image is very dark (very very dark). When I view the same media through quicktime or the finder, the image is clear. What is the cause of this problem???

  • Sound not loading

    I have the following code: myVars = new LoadVars(); myVars.load("http://charlesnewmanpubl.com/Sweethearts_On_Parade_BRGK.txt"); myVars.onData = function(src){      myVars.decode(src)      //trace(myVars.faFile);      var faFile:String;      var sound