Ssl-sockets and classloading

hi,
i use rmi using ssl-sockets. the server rebinds to the
rmiregistry -> it works fine but
when i try to connect from client (browser ie) -> the needed classes (RMISSLCLientSocketFactory...)
could not loaded
whats the problem??
mike

hi,
i use following code to test rmi with ssl-sockets:
interface:
import java.rmi.*;
public interface StringTag extends java.rmi.Remote
          public String appendX(String s) throws RemoteException;
server:
import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.registry.*;
public class StringTagImpl extends UnicastRemoteObject implements StringTag
          public StringTagImpl() throws RemoteException
                    super(0, new RMISSLClientSocketFactory(), new RMISSLServerSocketFactory());
          public String appendX(String s) throws RemoteException
                    return (s + "xxx");
          public static void main(String[] arg)
               System.setProperty("java.security.policy", "F:\\rmi\\security.policy");
               System.setSecurityManager(new RMISecurityManager());
               try{
                    Registry reg = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
                    StringTagImpl so = new StringTagImpl();
                    reg.rebind("StringTag", so);
                    System.out.println("StringTag bound in registry");
               catch(Exception e){
                    System.out.println("StringTagImpl: \n" + e);
applet:
import java.awt.*;
import java.rmi.*;
public class StringTagApplet extends java.applet.Applet
String tagged;
public void init()
          try
                    String host = "127.0.0.1";
                    int port = 1099;
                    StringTag st = (StringTag)Naming.lookup("//" + host + ":" + port + "/" + "StringTag");
                    tagged = st.appendX("The String: ");
          catch(Exception e)
                    System.out.println(e);
                    e.printStackTrace();
public void paint(Graphics g)
          g.drawString(tagged,25,30);
clientsocket:
import java.rmi.server.*;
import javax.net.ssl.*;
import java.io.*;
import java.net.*;
public class RMISSLClientSocketFactory implements RMIClientSocketFactory, Serializable{
     public Socket createSocket(String host, int port) throws IOException{
          SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault();
          return factory.createSocket(host, port);          
serversocket:
import java.rmi.server.*;
import javax.net.ssl.*;
import java.io.*;
import java.net.*;
public class RMISSLServerSocketFactory implements RMIServerSocketFactory, Serializable{
     public ServerSocket createServerSocket(int port) throws IOException{
          SSLServerSocketFactory factory = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
          return factory.createServerSocket(port);
the html-file:
<HTML>
<title>String appending</title>
<center><h2>Append X and Y</h2></center>
The result of appending to the Strings is:
<p>
<applet codebase="." code="StringTagApplet" width=500 height=120>
</applet>
</html>
policy:
grant
     permission java.security.AllPermission;
all files are in the same folder.
the class-file(RMISSLClientSocketFactory) could not loaded from client!
when i make a new instance from RMISSLClientSocketFactory before line:
StringTag st = (StringTag)Naming.lookup("//" + host + ":" + port + "/" + "StringTag");
--> the client could not loaded class StringTag ...and so on
i dont know why it not work!!
i were very happy to solve this problem!!

Similar Messages

  • SSL Sockets and Applets

    Overview: I need to make an Applet communicate with a server using an SSLSocket and I can't figure out how to include a truststore when running the applet in a web browser.
    Background:
    The applet communicates perfectly using regular non-secure sockets. I am now porting it to use secure sockets (SSLSocket, SSLServerSocket from JSSE).
    The applet communicates perfectly using secure sockets when run in appletviewer with the truststore file in the classpath. I have specified the appropriate truststore properties in the Applet as follows:
         System.setProperty("javax.net.ssl.trustStore", "truststore");
         System.setProperty("javax.net.ssl.trustStorePassword", "password");
    This works when run using appletviewer when the "truststore" file is in the classpath, and now I need to make it work in a web browser.
    Problem: How do I include the "truststore" file with an Applet?
    I have tried including it in the .jar file, which seems conceptually similar to including it in the classpath, which worked with appletviewer. However, including it with the .jar file doesn't work. The exception I get is:
    javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: No trusted certificate found
    Any ideas on how I can include the truststore file or suggestions on another approach that will accomplish the same thing?
    Thanks a lot!
    -Jeff Dyck

    Hi,
    I'm in the same boat.
    Thought I had a solution. I'm running an applet that opens an SSL socket back to the web server it came from
    URL url = new URL("https://" + baseUrl);
    URLConnection connection = url.openConnection();
    connection.setDoOutput(true);
    connection.setDoInput(true);
    -then just open streams. Info related to this at
    http://java.sun.com/products/plugin/1.3/docs/https.html
    Essentially, I'm taking advantage of the SSL connection made during the initial web page/applet load ([SSL_RSA_WITH_RC4_128_MD5 is what my HTTPS server wanted )
    The down side is that GET/POST are the only actions supported (refer to the link).
    I'm looking for a solution that specifies HOW I ACCESS my local browser's security so I don't get
    j'avax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: No trusted certificate found'.
    Hope someone replies...
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Applet(using SSL sockets) application in browser

    hello everyone,
    I am new to this forum, and this is my first forum in this site, please help me,
    My problem is,
    I have done an applet application which uses the SSL sockets, and it is working fine if i use the appletviewer tool, with the arguments of policy and URL, when i run this command "appletviewer -J-Djava.security.policy=mypolicy.policy URL of my html page" in the command mode its working fine.
    I have wrote HTML file for running the applet, and when i used it in the browser i was not able to get output , i was getting the error "NoTrustedCertificates found", i have setted the properties of truststore and password in the program itself like,
    System.setProperty("javax.net.ssl.trustStore", System.getProperty("java.home")+"cert");
    System.setProperty("javax.net.ssl.trustStorePassword", "pwd");
    and i also used the policy tool. I have stored my certificate along with the jar file, and i was getting this error
    can anyone please help me, or suggest me the right way to reach my target.
    Thanx in advance

    Hai,
    I have made my client applet running from the remote system, and the client was establishing SSL sockets, and there is a problem in Handshake, NO TRUSTED CERTIFICATE found was the error, and i had loaded the certificates ( one is used for signing the certificate, and the other is used for the SSL sockets authentication ) in my applet client code i have setted the system properties like
    System.setProperty("javax.net.ssl.trustStore", System.getProperty("java.home")+"\\lib\\security\\cert");
    System.setProperty("javax.net.ssl.trustStorePassword", "pwd");
    and this is the certificate which is used for SSL sockets authentication, and i stored the cert in the "jre\lib\security\" directory, and im using the jdk1.4.2_05 version.
    At the client side the error is
    Network Error: sun.security.validator.ValidatorException: No trusted certificate found.
    at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.a(Unknown Source)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(Unknown Source)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(Unknown Source)
    at com.sun.net.ssl.internal.ssl.SunJSSE_az.a(Unknown Source)
    at com.sun.net.ssl.internal.ssl.SunJSSE_az.a(Unknown Source)
    at com.sun.net.ssl.internal.ssl.SunJSSE_ax.a(Unknown Source)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(Unknown Source)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.j(Unknown Source)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(Unknown Source)
    at com.sun.net.ssl.internal.ssl.AppOutputStream.write(Unknown Source)
    at java.io.OutputStream.write(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Caused by: sun.security.validator.ValidatorException: No trusted certificate found
    at sun.security.validator.SimpleValidator.buildTrustedChain(Unknown Source)
    at sun.security.validator.SimpleValidator.engineValidate(Unknown Source)
    at sun.security.validator.Validator.validate(Unknown Source)
    at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source)
    at com.sun.net.ssl.internal.ssl.JsseX509TrustManager.checkServerTrusted(Unknown Source)
    At the server side the error is
    javax.net.ssl.SSLHandshakeException: Received fatal alert: certificate_unknown
    at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.a(Unknown Source)
    at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.b(Unknown Source)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.b(Unknown Source)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(Unknown Source)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.j(Unknown Source)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(Unknown Source)
    at com.sun.net.ssl.internal.ssl.AppInputStream.read(Unknown Source)
    at com.ClientNeg.run(ClientNeg.java:76)
    at java.lang.Thread.run(Unknown Source)
    i was not able to understand what went wrong , so any one please help me in doing my work.
    Thanx
    dwurity

  • Some General Questions about using SSL sockets

    1 Since both SSL and TLS rely on public-key cryptography, can I use it efficiently for encrypting large amount of data transfer within a network? Or I�ll be better off using secret key.
    2 If I understand correctly, I can install client/server certificate (public key) along with the software installation. Is that right? In other words, I don�t have to create them programmatically.
    3 To convert our unsecured client/server application, is it enough to replace plain sockets with SSL sockets and use a self signed certificate for the server? (Ours is a closed network and we don�t require any client authentication).
    4 How does SSL handles server to server communications?
    5 How do you encrypt data ( some of the fields) in a text file?
    Thank you all.

    hey there.
    1.yes you can use it to encrypt large amounts of data, and heres why:
    when you use SSL, it uses public key encryption to first tranfser across a private key. then from then on the data is simply private key encrypted, which is relatively fast and easy.
    2. Yes, you may chose to make them programatically or not
    4. the question doesn't really make sense. In the end, what is a Server and what is a Client is up to your application. From SSL's point of view, you just have two machines with Sockets on either side that are connected. You can use SSLSocket.setClientMode(boolean) to choose which of those socket will act as the "server" for the purpose of the authentication handsake.

  • Help with SSL SOCKETS

    hi,
    i seem to have a problem with establishing an ssl socket between 2 machines. This problem has to do with certificates as the runtime error i get specifies.
    So i figured out there must be a concept that i'm misssing.
    So why do i have to place a certificate on my client? how can i generate it? where do i place it?
    Can anyone please provide me with a sample code that establishes an sslsocket connection.
    thnx a million

    A good place to start is:
    http://java.sun.com/j2se/1.4.1/docs/guide/rmi/socketfactory/SSLInfo.html
    There is a code example, but you will also need to follow the guide in the other link below to create the required key files.
    Don't base your knowledge of SSL RMI sockets solely on what I say here, as I'm fairly new to this so I may express myself wrong. But here is a 30,000 foot overview of what I did to get them to work:
    If you are using RSA on your SSL connection, a public and private key are required. For this to work, you must create a key (keystore) via Java's "keytool.exe" tool using the '-genkey' option (the keystore should eventually reside on your server). You will then create a certificate from that keystore using the '-export' option of the keytool. Lastly, you will import the certificate into your client's store of accepted certificates (the file java\lib\security\cacerts) via the '-import' option of keytool.
    For a full description, you need to read:
    http://java.sun.com/j2se/1.4/docs/guide/security/jsse/JSSERefGuide.html
    the section from this page on using keytool:
    http://java.sun.com/j2se/1.4/docs/guide/security/jsse/JSSERefGuide.html#CreateKeystore
    The example shows using a new custom file for the truststore, but I imported the certificate into Java's cacerts file instead. I was unable to find the certificate if it was not in this file, but I very well may have been doing something wrong.

  • Setting cipher suites for ssl sockets

    Hi
    While setting cipher suites for ssl serversocket and socket, there may be lot of stream ciphers and block ciphers in the list. (also there may or may not be anonymous cipher suites).
    How does the ssl socket decide which cipher suite to use?
    Sorry for this newbie question.
    Thank you.

    Have you read the JSSE Reference Guide? It has a really good description of how the SSL handshake works. Part of the "Client Hello" step includes sending all the cipher-suites the client has enabled. The server picks the "best" of that set, that the server also supports, and sends it back as part of the "Server Hello". Both sides switch to that set.
    Now, what "best" means isn't defined. I'm not sure what criteria the server uses to determine that. Maybe someone else reading the thread can chime in.
    Grant

  • Problem with SSL socket(SSLSocketFactoryImpl.createSocket())

    Hello,
    I'm trying to create a ssl socket but I get an exception, I really don't know why. I have alredy include the certificate via keytool to my jdk. And I'm able to get html header with URLConnection with the code below
    import java.net.URL;
    import java.net.URLConnection;
    public class testClass {
         public static void main(String[] args) throws Exception {
              try{
                   URL url = new URL("https://ippbx1:8443/axl/");
                   String userPassword = "****" + ":" + "****";
                   String encoding = new sun.misc.BASE64Encoder().encode (userPassword.getBytes());
                   URLConnection c = url.openConnection();
                   c.setRequestProperty("Authorization", "Basic " + encoding);
                   for (int i=0; ; i++)
                        String name = c.getHeaderFieldKey(i);
                        String value = c.getHeaderField(i);
                        if (name == null && value == null)     // end of headers
                             break;        
                        if (name == null)     // first line of headers
                             System.out.println("Server HTTP version, Response code:");
                             System.out.println(value);
                             System.out.print("\n");
                        else
                             System.out.println(name + "=" + value);
              catch (Exception e) {}
    }and I get the following result :
    Server HTTP version, Response code:
    HTTP/1.1 200 OK
    Server=Apache-Coyote/1.1
    Pragma=No-cache
    Cache-Control=no-cache
    Expires=Thu, 01 Jan 1970 01:00:00 CET
    Set-Cookie=JSESSIONIDSSO=77670D5480DAD295C6519E812F9FED64; Path=/
    Set-Cookie=JSESSIONID=B71BDB730FA5B3B431D3B16C41E190E3; Path=/axl; Secure
    Content-Type=text/html;charset=ISO-8859-1
    Content-Length=233
    Date=Wed, 10 Jun 2009 15:17:10 GMTBut when I try to make a socket :
    import java.io.*;
    import java.net.*;
    import javax.net.SocketFactory;
    import javax.net.ssl.SSLSocketFactory;
    public class axlforward {
         public static void main(String[] args) {
    String address = "https://ippbx1:8443/axl/";        
              int portnum = 8443;
    try
                   SocketFactory socketFactory = SSLSocketFactory.getDefault();
                   Socket socket = socketFactory.createSocket(address, portnum);
    } catch (Exception e) {e.printStackTrace();} I get the following
    java.net.UnknownHostException: https://ippbx1/axl/
         at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:177)
         at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
         at java.net.Socket.connect(Socket.java:519)
         at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:550)
         at com.sun.net.ssl.internal.ssl.SSLSocketImpl.<init>(SSLSocketImpl.java:353)
         at com.sun.net.ssl.internal.ssl.SSLSocketFactoryImpl.createSocket(SSLSocketFactoryImpl.java:71)
         at axlforward.main(axlforward.java:89)I have a VB program that connects to the socket(with Inet1.Protocol = icHTTPS and Inet1.Execute strURL, "Post", strFormData, strFormHdr methods) and do what I want but I need to do it in Java but I'm not able to find the error.
    the server socket is a Cisco callManager Service(AXL Web Service) which receives and html+SOAP request and sends back an xml response and this server socket is running correctly with no problem.
    Thanks for your help.

    Jdevelopper8709 wrote:
    Thanks for your reply.
    I now can access to my socket and get the information I want with:
    SocketFactory socketFactory = SSLSocketFactory.getDefault();
                   socket = (SSLSocket) socketFactory.createSocket("ippbx1", 8443);In fact the problem was a username/password issue.
    Thanks.I quote from reply #1 "The address is just "ippbx1" and not "https://ippbx1:8443/axl/". The protocol is not part of the IP address.".

  • I receive an error in Firefox 4.0 Beta 11: Secure Connection Failed An error occurred during a connection. Renegotiation is not allowed on this SSL socket. (Error code: ssl_error_renegotiation_not_allowed) Anyone know how to fix this?

    I have installed the Firefox 4.0 Beta 11 (+updates), I try to connect to our https: website and I receive the following error:
    Secure Connection Failed An error occurred during a connection.
    Renegotiation is not allowed on this SSL socket.
    (Error code: ssl_error_renegotiation_not_allowed)
    I have installed this certificate on Firefox 3.6.13 and I am able to connect to our HTTPS site but it will not work with the Beta 4.0 11

    I read about this for ages. I had problems setting up a certificate for my online banking. This one solution genuinely worked for me (finally!) ...Fingers crossed it will for you too:
    1) In the address bar type in '''about:config''' ...Firefox will say it's dangerous, but I just went ahead anyway lol - It's fine. Thank god there's always an edit-undo!
    2) Copy and paste this into the ''filter'' at the top: '''security.ssl.allow_unrestricted_renego_everywhere'''
    3) Then change ''false'' to ''true'' (I think I just clicked it, and it changed)
    That's it! Refresh your bank page, and it should work!
    (Spanish source: '''http://translate.google.com/translate?sl=es&tl=en&js=n&prev=_t&hl=en&ie=UTF-8&layout=2&eotf=1&u=http%3A%2F%2Fwww.fedora-ve.org%2F2011%2F09%2F14%2Ferror-error-code-ssl_error_renegotiation_not_allowed-en-firefox-4-x.html&act=url''')

  • Issue porting WebLogic 8.1 SSL Socket code to WebLogic 9.2

    I did not write this code, but am trying to port the code from Weblogic 8.1 to Weblogic 9.2. The code comes from a custom OpenLDAPAuthenticator, that uses a SSL Socket to connect to an LDAP server.
    The following lines are used:
    Socket socket = SSLSocketFactory.getDefaultJSSE().createSocket(host, port);
    if (socket instanceof SSLSocket) {
      SSLContextWrapper sslcontextwrapper = SSLContextManager.getInstance().getDefaultSSLContext();
      sslcontextwrapper.forceHandshakeOnAcceptedSocket((SSLSocket) socket);
    }Does anyone know what this forceHandshakeOnAcceptedSocket method does, and if there is way to write this in WebLogic 9.2?
    Thanks

    I did not write this code, but am trying to port the code from Weblogic 8.1 to Weblogic 9.2. The code comes from a custom OpenLDAPAuthenticator, that uses a SSL Socket to connect to an LDAP server.
    The following lines are used:
    Socket socket = SSLSocketFactory.getDefaultJSSE().createSocket(host, port);
    if (socket instanceof SSLSocket) {
      SSLContextWrapper sslcontextwrapper = SSLContextManager.getInstance().getDefaultSSLContext();
      sslcontextwrapper.forceHandshakeOnAcceptedSocket((SSLSocket) socket);
    }Does anyone know what this forceHandshakeOnAcceptedSocket method does, and if there is way to write this in WebLogic 9.2?
    Thanks

  • Creating a TSL/SSL socket connection to a server

    Hi
    Is it posible to create a TSL/SSL socket connection to a server with as3 - webapp, I foundSecureSocket but it seems like it is only for Air, and is not in the flex 4.5 sdk?
    Then NetConnection has it, but can you use it with a server that we have created our self? I think I read that if we use flashremoting, we can?
    We are using As3Crypto but there is a lot of overhead on using this, as it is not native code.

    bump

  • Need help on Socket and HTTP

    Hi,
    I need help ... please ... I have to use socket and not HTTPURLConnection
    I try to connect with a socket to a web server (apache2) and request one page but two times.
    The first time it works well but the second one it doesn't ... I get a null message.
    Why ?
    Does the server close the socket as soon as the page is sent ?
    If it doesn't how I can continue sending and receiving data on the same socket ?
    Here is my code:
    package test;
    import java.net.*;
    import java.io.*;
    public class Test
    private String laRequete = new String(
    "POST http://localhost:5577/Test/ HTTP/1.0\r\n"+
    "Host:localhost:5577\r\n"+
    "\r\n");
    PrintWriter laSortie;
    BufferedReader lEntree;
    Socket laSocketTCP;
    public Test()
    String tmp;
    try
    laSocketTCP = new Socket("localhost", 5577);
    laSortie = new PrintWriter(laSocketTCP.getOutputStream());
    lEntree = new BufferedReader(new InputStreamReader(laSocketTCP.getInputStream()));
    laSortie.println(laRequete);
    laSortie.flush();
    // Premier essai OK
    System.out.println(lEntree.readLine());
    while((tmp = lEntree.readLine()) != null)
    System.out.println(tmp);
    // Second essai => Not OK
    laSortie.println(laRequete);
    laSortie.flush();
    System.out.println(lEntree.readLine());
    while((tmp = lEntree.readLine()) != null)
    System.out.println(tmp);
    catch (Exception e)
    e.printStackTrace();
    public static void main(String args[])
    Test tp = new Test();
    Here is the result of the execution
    HTTP/1.1 200 OK
    Date: Wed, 29 Sep 2004 08:35:35 GMT
    Server: Apache/2.0.51 (Win32)
    Last-Modified: Wed, 29 Sep 2004 08:27:57 GMT
    ETag: "23a46-9a-56c93f9a"
    Accept-Ranges: bytes
    Content-Length: 154
    Connection: close
    Content-Type: text/html; charset=ISO-8859-1
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> Index Test 1 </TITLE>
    </HEAD>
    <BODY>
    Test 1
    </BODY>
    </HTML>
    null
    Thanks, bye.

    Send an HTTP 1.1 request instead of a 1.0 request.
    HTTP 1.0 does not support keeping the connection open, so yes, the server closes the connection.
    Dave.

  • Cannot access to any site with ssl connection and fail to open safari and keychain, unless restart computer and login in with Guest account.

    when Update to 10.7.2 ,I cannot access to any site with ssl connection and fail to open safari and keychain, unless restart computer and login in with Guest account.
    OS:10.7.2
    Macbook Pro 2010-mid 13inch

    I also have the same problem, however if I use Firefox or Opera sites with ssl connection work fine. Still, I can't use Google Chrome (ssl), Safari (ssl), the Mac app store (generally), or the iTunes store (generally). Both the iTunes store, Safari and the app store won't respond, and Chrome displays this error: (net::ERR_TIMED_OUT). The problem persists regardless of what network I'm using. Also, when trying to access the keychain or iCloud, the process will not start (will hang). I didn't have these problems at all before updating to 10.7.2.
    Sometimes rebooting helps, and sometimes not. If the problem disappears by rebooting, then it only lasts a few minutes before it reappears. It is very frustrating, especially since there doesn't seem to be any obvious or consistent way of which to fix it.
    I'm also using a Macbook Pro 13-inch mid 2010.

  • 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.

  • Problem with the socket and the standard output stream

    Hy, I have a little problem with a socket program. It has the server and the client. The problem is that the client at one point in the program, cannot print messages in the console.
    My program does the next: the server waits connections, when a client connects to it, the server gets outputstream to the socket and writes two strings on it. Meanwhile, the client gets the inputstream to the socket and reads on it with a loop the two strings written by the server . The strings are printed by the client in the console. The problem starts here; once the read strings are printed ,I mean, after the loop, there are other System.out.println in the client but the console doesnt print anything . It curious that only when I comment on the server code the line that says: "br.readLine()" just before the catch, the client prints all the System.out.println after the loop but why?
    Here is the code:
    Server code:
    public class MyServerSocket {
    public MyServerSocket() {
    try{
    ServerSocket server= new ServerSocket(2000);
    System.out.println("servidor iniciado");
    Socket client=server.accept();
    System.out.println("Client connected");
    OutputStream os=client.getOutputStream();
    PrintWriter pw= new PrintWriter(os);
    String cadena1="cadena1";
    String cadena2="cadena2";
    pw.println(cadena1);
    pw.println(cadena2);
    pw.flush();
    InputStream is=client.getInputStream();
    InputStreamReader isr= new InputStreamReader(is);
    BufferedReader br= new BufferedReader(isr);
    br.readLine(); //If a comment this line, the client prints after the loop, all the System.out....
    catch (IOException e) {
    // TODO: handle exception
    public static void main(String[] args) {
    new MyServerSocket
    Client code:
    public class MyClientSocket {
    public MyClientSocket () {
    try{
    Socket client= new Socket("localhost",2000);
    InputStream is=client.getInputStream();
    InputStreamReader isr= new InputStreamReader(is);
    BufferedReader br= new BufferedReader(isr);
    String read;
    while((read=br.readLine())!=null){
    System.out.println(read);
    //These messages are not printed unless I comment the line I talked about in the server code
    System.out.println("leido");
    System.out.println("hola");
    }catch (IOException e) {
    public static void main(String[] args) {
    new MyClientSocket
    }

    You are right but with this program the loop ends. As you see, the first class, the Server, writes to the socket one text file. The second class, the client, reads the text file in his socket written by the server and writes it to a file in his machine.
    NOTE: The loop in the client ends and the server doesnt make any close() socket or shutdownOutput() .
    public class ServidorSocketFicheromio {
         public ServidorSocketFicheromio() {
    try{
         ServerSocket servidor= new ServerSocket(2000);
         System.out.println("servidor iniciado");
         Socket cliente=servidor.accept();
         System.out.println("cliente conectado");
         OutputStream os=cliente.getOutputStream();
         PrintWriter pw= new PrintWriter(os);
         File f = new File("c:\\curso java\\DUDAS.TXT");
         FileReader fr= new FileReader(f);
         BufferedReader br= new BufferedReader(fr);
         String leido;
         while((leido=br.readLine())!=null){
              pw.println(leido);
         pw.flush();
         }catch (IOException e) {
         * @param args
         public static void main(String[] args) {
              new ServidorSocketFicheromio();
    public class ClienteSocketFicheromio {
         public ClienteSocketFicheromio() {
    try{
         Socket cliente= new Socket("localhost",2000);
         File f = new File("G:\\pepe.txt");
         FileWriter fw= new FileWriter(f);
         PrintWriter pw= new PrintWriter(fw);
         InputStream is=cliente.getInputStream();
         InputStreamReader isr= new InputStreamReader(is);
         BufferedReader br= new BufferedReader(isr);
         String leido;
         while((leido=br.readLine())!=null){
              pw.println(leido);
              System.out.println(leido);
              System.out.println("leido");
              System.out.println("hola");
              pw.flush();
         }catch (IOException e) {
         public static void main(String[] args) {
         new ClienteSocketFicheromio();/
    }

  • Problems with sockets and InputsStreams

    Hi,
    I ve this code:
    InputStream is = null;
    boolean ok=true;
    while(ok){
    //sc is an object instance of socketConnection
    is = sc.openInputStream();
    return this.parse(is);
    //is.close();
    return "";
    and this exception is produced:
    java.io.IOException: no more Input Streams available.
    This exception is produced in the line:
    is = sc.openInputStream();
    I m connecting to a server and this server sends data throw a socket... but the problem is that when i m reading from this socket and this socket doesn t have data in it...
    how could i solve this problem...?
    Thanks,
    Diego

    That would be the "real" code:
    public String process()throws IOException{
    InputStream is = null;
    is = sc.openInputStream();
    String result= this.parse(is);
    is.close();
    any suggestions?
    Thanks,
    Diego

Maybe you are looking for

  • Can't open any libraries on start-up

    Won't open any iPhoto libraries; says needs latest update (assume this is 3.5.1) and my version is 3.4.5.  SW update history says this was downloaded on 11-16-13 and therefore won't let me update from app store site.  caught in a loop.

  • Profile for ODI

    are the profile defined in the ODI security manager the default one or you can define your own parameters. can some one send me some link or some document which can show me how to define profile and user authorization. Thanks to you all .

  • Level 1 Notification Not working on Folder Emails.

    Hello Everyone I am in a strange situation where my Level 1 Notification doesnt work. Not working. 1. If there is an email which comes into my inbox and if there is a rule which is set on my Lotus Domino (Desktop) to save a copy in lets says XYZ fold

  • Change of IP in RAC

    Hi, Thanx a lot for this discussion forms as i am getting the response very quickly. What happens in RAC environment if i change my instances public IP /virtual IP. Does it affects ???? If it doesn't what and where are the changes have to be made?? T

  • How do i import this kind of template?

    how do i import a oscommerce template into dreamweaver to start editing it?