How to use wait/nofity in socket server

Dear all
that is one of sample code from a book which's use mutil connection with socket program , but i if it is possible to use wait and nofity to controle client activety by wait and notify in this sample code ?
some idea hope someone give me a help please
import java.net.*;
import java.io.*;
* Threaded Echo Server, pre-allocation scheme.
* Each Thread waits in its accept() call for a connection; this synchronizes
* on the serversocket when calling its accept() method.
* @author Ian F. Darwin.
public class EchoServerThreaded2 {
     public static final int ECHOPORT = 7;
     public static final int NUM_THREADS = 4;
     /** Main method, to start the servers. */
     public static void main(String[] av)
          new EchoServerThreaded2(ECHOPORT, NUM_THREADS);
     /** Constructor */
     public EchoServerThreaded2(int port, int numThreads)
          ServerSocket servSock;
          Socket clientSocket;
          try {
               servSock = new ServerSocket(ECHOPORT);
          } catch(IOException e) {
               /* Crash the server if IO fails. Something bad has happened */
               System.err.println("Could not create ServerSocket " + e);
               System.exit(1);
               return;     /*NOTREACHED*/
          // Create a series of threads and start them.
          for (int i=0; i<numThreads; i++) {
               new Thread(new Handler(servSock, i)).start();
     /** A Thread subclass to handle one client conversation. */
     class Handler extends Thread {
          ServerSocket servSock;
          int threadNumber;
          /** Construct a Handler. */
          Handler(ServerSocket s, int i) {
               super();
               servSock = s;
               threadNumber = i;
               setName("Thread " + threadNumber);
          public void run()
               /* Wait for a connection. Synchronized on the ServerSocket
                * while calling its accept() method. */
               while (true){
                    try {
                         System.out.println( getName() + " waiting");
                         Socket clientSocket;
                         // Wait here for the next connection.
                         synchronized(servSock) {
                              clientSocket = servSock.accept();
                         System.out.println(getName() + " starting, IP=" +
                              clientSocket.getInetAddress());
                         DataInputStream is = new DataInputStream(
                              clientSocket.getInputStream());
                         PrintStream os = new PrintStream(
                              clientSocket.getOutputStream(), true);
                         String line;
                         while ((line = is.readLine()) != null) {
                              os.print(line + "\r\n");
                              os.flush();
                         System.out.println(getName() + " ENDED ");
                         clientSocket.close();
                    } catch (IOException ex) {
                         System.out.println(getName() + ": IO Error on socket " + ex);
                         return;
}if i add end of my code like this and then the error message indicat that
java.lang.IllegalMonitorStateException: current thread not owner
try{
                    clientSocket.wait();
             }catch(InterruptedException e){
                                          clientSocket.close();
                                          clientSocket.notify();
                                        }

Why? Closing the socket will cause the client to return from reading the socket with a null or zero or EOFException. You don't need anything else.
In any case notifying the clientSocket will only wakeup threads in the current JVM that are waiting on it. This mechanism isn't magic, and it can't wake up another JVM.

Similar Messages

  • How to use fp-2010 as web server

    how to use fp-2010 as web server
    mazhar 

    Hi Mazhar,
     It is fairly straighforward to set up front panels for your RealTime executable. This knowledgebase has the information on how to do this.
    Hope this helps!
    Warm regards,
    Karunya R
    National Instruments
    Applications Engineer

  • How to use JSP in apache web server

    hi all,
    can anybody tell me how to use JSPs in Apache Web Server.
    Thanks
    sir

    You would need a servlet container to run Servlets and JSPs. And Apache's Tomcat is one such free container available. Download Tomcat from http://jakarta.apache.org and integrate with Apache WS
    HTH

  • How to use OEM to moniter sql server 2000

    Hi,
    I need to learn How to use OEM to moniter sql server 2000.
    Can anyone help me and give me some website or documents
    to read?
    So I can learn to do this job.
    Thanks.

    See Note 115302.1 in Metalink.oracle.com
    in how to use OEM Diagnostic pack addon for SQL Server
    Or search for
    oem "user events"
    to build your own monitor script.

  • How to use addwatermarkfromfile on a web server

    how to use addwatermarkfromfile on a web server. Where do you put the js on a windows 2008 server, so that the URL can pick it up when a user opens a PDF.

    You don't.  JS files can exist in three places.
    1.  In the PDF file
    2.  In the User Profile
    3.  In the Application folders
    * Note while you can execute some browser based JS to the embedded viewer in a web browser all of the API calls are non-editing.

  • How to Use Schannel for TLS Sockets on Windows?

    I need make a c++ TLS socket server running on Windows XP, and a c# TLS socket client on Windows 7.
    The reason of using Schannel TLS is that it is FIPS 140-2 validated.
    But it is not easy to find some sample code of Schannel.
    By search, I found two c++ TLS samples, but the samples use the secur32.dll, some APIs seem are FIPS non-approved.
    codeproject SSL/TLS client/server for .NET and SSL tunnelling
    http://www.coastrd.com/c-schannel-smtp C++ SSPI Schannel TLS example
    According to 140sp1000.pdf (Microsoft Windows Vista Kernel Mode Security Support Provider Interface (ksecdd.sys) Security Policy Document), following APIs are FIPS non-approved APIs.
    InitializeSecurityContextW
    ImpersonateSecurityContext
    EncryptMessage 
    DecryptMessage
    I am quite confused about two things:
    One is that the FIPS non-approved APIs of ksecdd.sys also are also non-approved in secur32.dll?
    Another question is what's the correct way of using Schannel. Are the samples using Schannel in the correct way, must the APIs InitializeSecurityContextW/EncryptMessage be used?
    I want some sample code about how to use Schannel in native c++ and managed c#.

    I'm not sure what information you are referring to that indicates InitializeSecurityContext() and EncryptMessage() are not FIPS compliant.  InitializeSecurityContext() is required API on the client side.  EncryptMessage() is the required API to
    encrypt data.  Both APIs are important APIs in SSPI.
    In .NET, you would use the SSLStream Class, https://msdn.microsoft.com/en-us/library/system.net.security.sslstream(v=vs.110).aspx .
     MSDN has sample code for both the client and server.
    There used to be an SSPI client + server sample (WebClient & WebServer) on the Windows SDK.   I don't know if it is still there.  If you can't find them, please let me know.
    thanks
    Frank K [MSFT]
    Follow us on Twitter, www.twitter.com/WindowsSDK.
     

  • How to use security roles in Weblogic server?

    Hello Gurus,
    I am new to Weblogic server and I am trying to investigate how to make
    use of security roles in weblogic server (5.1.0). Can anyone point me
    to some documentation. Specifically, I am looking for instance level,
    and method level security and how to use it.
    Thanks for taking your time to read this e-mail.
    Thank You all in advance,
    Hari.

    You should read the security information in the Servlet 2.2 specification
    that WL 5.1 implements:
    http://java.sun.com/products/servlet/download.html
    Chapter 11 deals with declarative and programmatic security, and includes a
    section on roles:
    11.4 Roles
    A role is an abstract logical grouping of users that is defined by the
    Application Developer or
    Assembler. When the application is deployed, these roles are mapped by a
    Deployer to security
    identities, such as principals or groups, in the runtime environment.
    A servlet container enforces declarative or programmatic security for the
    principal associated with
    an incoming request based on the security attributes of that calling
    principal. For example,
    1. When a deployer has mapped a security role to a user group in the
    operational environment. The
    user group to which the calling principal belongs is retrieved from its
    security attributes. If the
    principal's user group matches the user group in the operational environment
    that the security
    role has been mapped to, the principal is in the security role.
    2. When a deployer has mapped a security role to a principal name in a
    security policy domain, the
    principal name of the calling principal is retrieved from its security
    attributes. If the principal is
    the same as the principal to which the security role was mapped, the calling
    principal is in the
    security role.
    Cameron Purdy
    http://www.tangosol.com
    "Hari" <[email protected]> wrote in message
    news:[email protected]..
    Hello Gurus,
    I am new to Weblogic server and I am trying to investigate how to make
    use of security roles in weblogic server (5.1.0). Can anyone point me
    to some documentation. Specifically, I am looking for instance level,
    and method level security and how to use it.
    Thanks for taking your time to read this e-mail.
    Thank You all in advance,
    Hari.

  • How to use SSL certificates in OSX Server

    I have setup OSX server with a host name that is pointed properly to my OSX server. My question is about using certificates that were purchased through my domain registrar.
    I bought a cert and after the validation process, I was given a link to download 4 certificate files.
    AddTrustExternalCARoot.crt
    DV_NetworkSolutionsDVServerCA2.crt
    DV_USERTrustRSACertificationAuthority.crt
    [domain name].crt
    So after downloading these and opening them one by one, I installed them in the keychain as a system cert.
    The part I cant figure out is how to use the domain cert instead of the one that the server creates upon completion of setup (the self signed one).
    On the certificate selection in the sidebar, I can choose Import a certificate identity, but when I drag my domain cert into the box, it shows up as a non-identity cert and the Import button is still grayed out. I dragged all four certs there and all of them show as non-identity certs.
    If I go down the path of the Get a Trusted Certificate, it takes me through the CSR request which I dont think I need since i have my certificates already.
    Am I missing a step? Or do I need to export from the keychain, then import into the server application? Seems like the new certificates should show up in the server application. Any help would be greatly appreciated.

    I got the answer and wanted to post for anyone that happened to have this question.
    During the SSL cert setup, it asks where your domain is hosted and since it was hosted by Network Solutions, I chose that option which doesnt do the CSR request. I had to choose Other/VPS.
    Once I did that, I was able to generate a CSR in the server application and get my certificate issued again by pasting the request code on my registrars website. Once I received those certs, I dragged my domain cert into the Pending one listed in the certificate list.
    Also I chose Apache/ModSSL as the type of server. Hope that helps and new people like myself in setting up the server application.

  • How to use 'Wait'/'Delay' in Swing

    Hi all,
    I want to simulate an interation between two peers,
    that exchange information among each other.
    The idea is to have a JPanel where JLabel("Text") are
    added in a fixed but consecutive intervals. Something like
    <Add label>; <Delay/wait a second>;<Add other label>; <Delay>;.....
    Is there an easy/simpler way to do this without using
    threads?
    Does Swing have a simple way to do what I want?
    Can you recomend a link for this?
    Pls note that I don't want to block my entire application.
    Thanks in advance for the help,
    Jorge

    Here is a link to the Swing tutorial on "How to Use Timers":
    http://java.sun.com/docs/books/tutorial/uiswing/misc/timer.html
    And here is a link to to thread that uses a Timer to 'continuously scroll text':
    http://forum.java.sun.com/thread.jsp?forum=57&thread=291161

  • How to use more than one application server during initial load?

    Hi,
    we plan to use more than one application server in CRM during initial download in order to increase the number of parallel requests and to decrease the time for the initial load. Is there a way to allocate requests to more than one server? Is is possible via multiple rfc connections for consumer CRM in CRMRFCPAR?
    Thanks.
    Alexander Schiffer

    Hi Naresh,
    thanks for your answer. It has solved my problem. SMLG is the transaction that I was looking for.
    Two more OSS notes that helped me to guide our basis into the right direction:
    OSS 593058 - New RFC load balancing procedure
    OSS 1413986 - SMLG: Possibility to select a favorite type for Ext.RFCs
    Thanks again.
    Alexander Schiffer

  • How to use toplink in the tomcat server?

    Hi,
    I want to use Toplink in the tomcat server. I am connecting to oracle database using DataSource.
    Can any body help me, what are the setup required to use the toplink in the tomcat?
    Please help me if any body has idea on the same.

    Take a look at this other forum posting: Tomcat acquire dataSource [TOPLINK-7060]
    --Shaun                                                                                                                                                                                                                               

  • How to use connection pooliing in welogic server

    How to use connection pooliing in welogic server

    Ummmm, once you have an open connection to something, you add it to a pool so the next time you need to connect to it, you don't have to redo all of the overhead of creating the connection.
    :-)

  • How To Use Reporting Services On SQL Server 2000 ?

    Hi all .
    Today , I has a issue .
    Normal , if the customer use SQl Server 2005 , it is no proplem , so if use SQL Server 2000 ,  Now , I want to use Reporting services on SQL Server 2000 , but , I am searching  on Internet , so I know , if I want to use SQL 2000 reporting server , I must have license of SQL server 2000 .
    is Every body  idea for this issue  ? .
    Please help me .
    Thanks alot .

    Ok ,anyway thanks alot ,.

  • Please tell me how to use the Simple bluetooth client server example.

    Hi i used the simple bluetooth client server example in labview 7.1. Iam getting an error saying your system does not support the network operation.  I have following doubts also.
    1. Should i pair the device before running the labview.
    2. Should i enable the file transfer wizard in the software given with the bluetooth adapter.
    Please help
    Thank you
    R.Prem kumar 
    09940446193

    Hi R.Prem,
    Could you please let me know what error code is associated with this error message? Also could you please provide a description of the setup you are currently using? Thanks!
    Best regards,
    Steven

  • How to use 2 instances of DI Server

    Hi,
    we need two use two instances of DI server (on two different servers) to connect to two different companies at the same time without closing connection every time.
    To do this we have bought two licenses of DI Server. Unfortunately it seems that the first DI server occupies both licenses.
    Is there any setup we are missing?
    regards
    Fabio

    I guess you could setup a new license server. The idea is to have on license server for each of your DI Server, this should avoid one di server of using all your license...

Maybe you are looking for