Sockets in Applet

Hello,
Is it possible to connect to another web-server in Java Applet via sockets?
Best Regards, Dmitry.

and is it possible to do with JSP?

Similar Messages

  • Embed a socket in applet

    I want to embed a socket in an applet so that when I write a string from the other socket(this socket suppose to be an application not applet) which connect with the applet socket,the string can be print on the applet webpage.
    can anyone tell me how to make it?
    Thanks

    You can create (if local web browser security allows) a socket connection between the applet and the server from which the applet came from.
    This means that an applet from www.my-applet.com can only create socket connections to www.my-applet.com and not www.give-me-a-virus.com
    Basics: My applet is on www.my-applet.com and I have a server that gives a message to my applet (such as news headlines or stock info) listening on port 1234.
    import java.net.*;
    import java.io.*;
    Socket myconnection = new Socket("www.my-applet.com", 1234);
    BufferedReader in = new BufferedReader(new InputStreamReader(myconnection.getInputStream());
    String messageForApplet = in.readLine();
    appletLabel.setText(messageForApplet);
    repaint();
    in.close();
    myconnection.close();Now, this code will throw an IOException that needs to be caught.

  • How to use sockets in applets?

    hi,
    i wrote the following applet:
    http://spidey.bei.t-online.de/rest/java/jtv/jTV.html
    its a little applet which asks tvtoday.de for the movies which are running on the channels/time and day you specified and puts them into the table
    as a normal java application everything works fine
    but as an applet i always get an exception that im not allow to open sockets to tvtoday.de
    how comes? and is there a way to fix that?
    thx

    Applets are only allowed to create sockets back to the host that they originally came from. This is a security measure - otherwise, a trojan horse applet could be downloaded through a firewall, then open connections and do malicious things to hosts that were supposed to be protected by the firewall.
    I am not sure if there is a way the solve this. Perhaps you could sign your applet and let java pop up a "Let this applet open sockets elsewhere?" window (similar to what java web start can do), but I personally don't know of such a system.

  • Working with sockets with applets

    Hello, I am working in my account on a web server, and I am trying to develop a chat using applets. My program works great on the command line, but the applets cannot create a socket because of a SocketPermission problem. I have read about this problem a lot, and I found that applets will only create a socket with the server the applet originates from. I have still not had any success in allowing my applet to create a socket to connect to a server.
    I would appreciate any advice concerning this problem!
    Thanks so much!
    Christina

    If you are calling the HTML page containing the Applet as http://localhost then the Applet has to open a socket back to local host.
    Make sure you call the applet using the full ip address of the where the web server is running. This should match the socket ip address you are trying to open inside the Applet.

  • Simple server/client socket in applets code.

    Can anyone please help me with Java sockets ? I want to create an applet that simply checks if it's still online. This means that i'll be using this applet thru modem(that is, dial-up connection). All i want the applet to do is send a signal to the server and the server answer back that it is still online. The server should be able to handle multiple sends and receives. I need just a simple code for me to work on (both server and client). The client doesn't have to send any special message to the server and vice versa.
    Thanks.

    Below is the code for both Applet and Servlet .I think this will solve your problem.
    Applet:
    import java.applet.*;
    import java.awt.*;
    import java.io.*;
    import java.net.*;
    public class OnlineApplet extends Applet implements Runnable
         private static Thread thread;
         private static HttpURLConnection URLConn;
         public void init()
              try
                   //Connect to the URL where servlet is running.
                   URL url = new URL("http://localhost/servlet/OnlineServlet");
                   URLConn = (HttpURLConnection)url.openConnection();
                   URLConn.setDoInput(false);
                   URLConn.setDoOutput(true);
              catch (Exception ex)
              thread = new Thread(this);
         public void start()
              thread.start();
         public void paint(Graphics g) {}
         public void stop() { }
         public void destroy() { }
         public void run()
              while(true)
                   try
                        thread.sleep(1000 * 60);
                        sendConfirmation();
                   catch (Exception ex)
         private void sendConfirmation() throws Exception
              DataOutputStream dos = new DataOutputStream(URLConn.getOutputStream());
              dos.writeChars("Fine");
              dos.flush();
              dos.close();
    Servlet:
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;
    public class OnlineServlet extends HttpServlet implements Runnable
         public static Hashtable hsh;
         private static Thread thread;
         public void init(ServletConfig scon) throws ServletException
              hsh = new Hashtable();
              thread = new Thread(this);
         public void service(HttpServletRequest req, HttpServletResponse res)
              String strHostName = req.getRemoteHost();
              if(hsh.containsKey(strHostName))
                   updateHash(strHostName);
              else
                   hsh.put(strHostName, System.currentTimeMillis() + "");
         private void updateHash(String strHostName)
              hsh.remove(strHostName);
              hsh.put(strHostName, System.currentTimeMillis() + "");
         public void run()
              while(true)
                   try
                        thread.sleep(1000 * 120);
                   catch (Exception ex)
                   validateUsers(System.currentTimeMillis());
         private void validateUsers(long msec)
              Enumeration keys = hsh.keys();
              int size = hsh.size();
              while(keys.hasMoreElements())
                   String strKey = keys.nextElement().toString();
                   String strLong = hsh.get(strKey).toString();
                   long lg1 = Long.parseLong(strLong);
                   if((lg1 - msec) > 100000)
                        // This means there is no response from user . That means he is not online. So you can remove from hashtable.
                        hsh.remove(strKey);

  • Using sockets with Applet

    Hey,
    I have a website which has an applet on one of the pages. I put in code that uses a socket to connect to MY computer. ( i want to use my computer as a server which stores data/accounts/etc) A SecurityException was thrown when I tested the applet. Is what I'm trying to do possible? or does something like this have to connect to a server which is on my website?
    Thanks

    I believe you can run something like this by signing the applet.
    And then the user has the option of allowing or disallowing a signed applet to do that kind of thing. I don't know which is the default.

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

  • Sockets in Applets

    hi i am trying to open Socket in an Applet but i am not succesful kindly tell me any way or tell me any
    alternative
    i will be very thankful

    you have to sign your applet before to open a Socket...
    other: you just can open a connection to the server where the applet comes from.

  • Win socket with applet socket by byte type data network

    Server is windock
    Client is applet
    How do i receive and send byte type data..
    What i do using sock type?
    UDP? just i use Inputstream, Outputstream?
    and i some warring..
    Packet Buffering...
    how do i?
    plz help me...

    Hi
    Search the Forum for "socket", start reading other people questions and answers, i am sure that after spending few hours you will find some answers.
    Noah

  • Am I able to use Sockets in applets

    I developed a server-client application in java using datagrams, and decided to try to convert the client application into an applet.
    The problem was that the applet wouldn't run in a browser but it worked if I used javas appletviewer!
    Tryed both JDK1.1.8 and JDK1.3.1!
    Browser = IE5
    Am I able to do any networking with browser at all?

    My applet only connects to the server (and port) it was served from! But it still doesn't work... It works fine in an appletviewer but in a Browser I won't even get my GUI up :(
    Hmmm... OK! I'll try to make a TCP connection from Applet to my server application, I've done it once before but as an application, the server then had to be multithreaded so it could work with multiple users simuntaniusly... the reason I switched over to datagram packages is that I could make the server single threaded!

  • Applet crossdomain timeout

    Hi,
    I getting some problems deploying an unsigned applet that use JavaScript integration and sockets, the applet is a chat client demo.
    https://demo.zeroc.com/chat/applet/
    I have added crossdomain.xml file
    https://demo.zeroc.com/chat/applet/crossdomain.xml
    https://demo.zeroc.com/crossdomain.xml
    Are this both necessary?
    Seems that the applet try to access crossdomain file in the ip of my local computer
    network: Connecting http://192.168.50.2/crossdomain.xml with proxy=DIRECT
    network: Connecting socket://192.168.50.2:80 with proxy=DIRECT
    Any ideas what could cause that? to be clear this is while accessing the applet in https://demo.zeroc.com/chat/applet/index.html and 192.168.50.2 is the ip of the compunter running the web browser. The second time i try to run it success
    See the java console output.
    basic: New window ID: 10004e2
    basic: Value of xembed: 1
    basic: Referencing classloader: sun.plugin.ClassLoaderInfo@22c95b, refcount=1
    basic: setWindow: call before applet exists:10004e2
    security: Accessing keys and certificate in Mozilla user profile: null
    security: JSS is not configured
    basic: Added progress listener: sun.plugin.util.GrayBoxPainter$GrayBoxProgressListener@169ca65
    basic: Loading applet ...
    basic: Initializing applet ...
    basic: Starting applet ...
    basic: completed perf rollup
    network: Cache entry not found [url: https://demo.zeroc.com/chat/applet/ChatDemoAppletGUI.jar, version: null]
    network: Connecting https://demo.zeroc.com/chat/applet/ChatDemoAppletGUI.jar with proxy=DIRECT
    network: Connecting socket://demo.zeroc.com:443 with proxy=DIRECT
    security: Loading Root CA certificates from /opt/sun-jdk-1.6.0.15/jre/lib/security/cacerts
    security: Loaded Root CA certificates from /opt/sun-jdk-1.6.0.15/jre/lib/security/cacerts
    security: Loading SSL Root CA certificates from /opt/sun-jdk-1.6.0.15/jre/lib/security/cacerts
    security: Loaded SSL Root CA certificates from /opt/sun-jdk-1.6.0.15/jre/lib/security/cacerts
    security: Loading certificates from Deployment session certificate store
    security: Loaded certificates from Deployment session certificate store
    security: Checking if certificate is in Deployment denied certificate store
    network: Connecting https://demo.zeroc.com/chat/applet/ChatDemoAppletGUI.jar with cookie "bblastvisit=1255442210; bblastactivity=0"
    network: Downloading resource: https://demo.zeroc.com/chat/applet/ChatDemoAppletGUI.jar
    Content-Length: 817,306
    Content-Encoding: null
    network: CleanupThread used 4833 us
    network: Wrote URL https://demo.zeroc.com/chat/applet/ChatDemoAppletGUI.jar to File /home/pepone/.java/deployment/cache/6.0/19/272ab6d3-7e68dfdf-temp
    security: Blacklist revocation check is enabled
    network: CleanupThread used 3 us
    liveconnect: JavaScript: calling Java system code
    liveconnect: JavaScript: default security policy = https://demo.zeroc.com
    liveconnect: JavaScript: UniversalBrowserRead enabled
    liveconnect: JavaScript: default security policy = https://demo.zeroc.com
    liveconnect: the url of the applet is https://demo.zeroc.com and the permission is = false
    liveconnect: JSObject::call: name=setState
    liveconnect: the url of the applet is https://demo.zeroc.com and the permission is = false
    liveconnect: JavaScript: calling Java system code
    liveconnect: JavaScript: default security policy = https://demo.zeroc.com
    liveconnect: JavaScript: calling Java system code
    liveconnect: JavaScript: default security policy = https://demo.zeroc.com
    network: Cache entry not found [url: https://demo.zeroc.com/chat/applet/org/apache/tools/bzip2/CBZip2InputStream.class, version: null]
    network: Connecting https://demo.zeroc.com/chat/applet/org/apache/tools/bzip2/CBZip2InputStream.class with proxy=DIRECT
    network: Connecting socket://demo.zeroc.com:443 with proxy=DIRECT
    security: Loading certificates from Deployment session certificate store
    security: Loaded certificates from Deployment session certificate store
    security: Checking if certificate is in Deployment denied certificate store
    network: Connecting https://demo.zeroc.com/chat/applet/org/apache/tools/bzip2/CBZip2InputStream.class with cookie "bblastvisit=1255442210; bblastactivity=0"
    network: Cache entry not found [url: http://[fe80:0:0:0:21b:24ff:fe50:240e%2]/crossdomain.xml, version: null]
    network: Connecting http://[fe80:0:0:0:21b:24ff:fe50:240e%2]/crossdomain.xml with proxy=DIRECT
    network: Connecting socket://%5bfe80:0:0:0:21b:24ff:fe50:240e%252%5d:80 with proxy=DIRECT
    java.security.PrivilegedActionException: java.net.SocketTimeoutException: connect timed out
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.deploy.net.CrossDomainXML.check(CrossDomainXML.java:363)
    at com.sun.deploy.net.CrossDomainXML.check(CrossDomainXML.java:150)
    at sun.plugin.security.ActivatorSecurityManager.checkConnect(ActivatorSecurityManager.java:206)
    at java.net.NetworkInterface$1checkedAddresses.<init>(NetworkInterface.java:90)
    at java.net.NetworkInterface.getInetAddresses(NetworkInterface.java:110)
    at IceInternal.Network.getLocalAddresses(Network.java:902)
    at IceInternal.Network.getLocalAddress(Network.java:819)
    at Ice.Util.generateUUID(Util.java:212)
    at ChatDemoGUI.Coordinator.login(Coordinator.java:113)
    at ChatDemoGUI.ChatDemoApplet$1.run(ChatDemoApplet.java:84)
    Caused by: java.net.SocketTimeoutException: connect timed out
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
    at java.net.Socket.connect(Socket.java:525)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:161)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:394)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:529)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:233)
    at sun.net.www.http.HttpClient.New(HttpClient.java:306)
    at sun.net.www.http.HttpClient.New(HttpClient.java:323)
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:860)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:801)
    at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:726)
    at com.sun.deploy.net.CrossDomainXML$2.run(CrossDomainXML.java:367)
    ... 11 more

    at java.net.NetworkInterface.getInetAddresses(NetworkInterface.java:110)
    at IceInternal.Network.getLocalAddresses(Network.java:902)
    at IceInternal.Network.getLocalAddress(Network.java:819)
    at Ice.Util.generateUUID(Util.java:212)
    My code shouldn't be doing that, i fixed that code and all is working fine now.

  • Can I User IO in Applet?

    Hi Everybody,
    I am new to applet.
    Can I user IO or Socket in Applet?
    Thanks in Advance

    You could not access any of client resources from applet, unless your applet is "SIGNED"
    to sign applet you can refere to java tutorial page:
    http://java.sun.com/docs/books/tutorial/deployment/jar/signindex.html
    Thanks
    Ahmad Elsafty

  • How applet transfers data over HTTP

    hello,
    I found out that you cannot you sockets in applets (cannot create a socken on the client side) so I want to know how to transfer data over HTTP. What class should I use or some short example would be of much help.

    You can make connections back to the same server the applet came from. If you need to make connections directly to other servers, then you can sign the applet, which will lift the security restrictions (provided users accept your signature as trustworthy).

  • How to run server application on that talks to applet in embeded in webpage

    i have a client(applet) and server application that are designed to communicate via sockets. the applet will run from a webpage and i know how to publish that. but the problem is the server application. i have been told that it too should run on my host, but how can i specify that and how to find out whether or not my host allows such a thing.
    any clarifying reply would be highly appreciated.
    sam

    If thinking about a Java solution, look at JSP/Servlet technology. (i.e. http://jakarta.apache.org)
    In short, servlets a classes that run in a container accesible by HTTP.
    There is also J2EE, wich uses RMI to perform this task.

  • Advice needed: New Applet to talk to ServerSocket

    Hi,
    I have to write this from scratch, so please feel free to re-direct me in a whole new direction. Here's what I have to do:
    1. We generate some real time information (numerical) which I have to display to my clients in an applet in grid format (tabular)
    2. The data changes maybe 4-5 times a minute and the client applets should pick up these changes and display them with no more than 10-15 second delay.
    3. I already have a serversocket application which can send this information over TCP/IP sockets. Applets can make socket connections and readLine() from here.
    4. The number of applets simultaneously accessing this data could be 1000 or more.
    5. I am comfortable doing the server side development but am very weak as far as writing applets.
    Questions:
    1. How should I go about writing the applet to display the dynamically changing information?
    2. How can I hide the port number where the applet connects - i.e. prevent the port number from being revealed via a decompiler?
    3. How can I make it very difficult for someone to first download and then decompile my JAR file? I have seen sites that use "CABBASE" and keep code in CAB files. Can I package my class files in the CAB files instead of JAR files? Will it help?
    4. What else can I do to keep unauthorized entities from accessing the real time raw feed from my serversocket app?
    Thanks!

    4. The number of applets simultaneously accessing
    this data could be 1000 or more.You should probably set up more than one server to distribute the load of all these clients
    1. How should I go about writing the applet to
    display the dynamically changing information? 1. Initiate your applet
    2. Register your connection with the backend data provider
    3. Have a thread listen for updates, then update your applet
    2. How can I hide the port number where the applet
    connects - i.e. prevent the port number from being
    revealed via a decompiler?It's a little tricky. I believe the guys who created Mocha also SELL software for making java classes undecompilable.
    How useful would your applet code be without the backend data? Would anyone really be interested in trying to redistribute it maliciously?
    Honestly, your first line of defense should be to try to set up some sort of connection filter, where either your clients have to log in before getting to your applet, or the backend ServerSocket (or whatever) checks to make sure the IP of the incoming request is authorized.
    3. How can I make it very difficult for someone to
    first download and then decompile my JAR file? I have
    seen sites that use "CABBASE" and keep code in CAB
    files. Can I package my class files in the CAB files
    instead of JAR files? Will it help?I doubt it. CAB is just about the same thing as a jar.
    4. What else can I do to keep unauthorized entities
    from accessing the real time raw feed from my
    serversocket app?
    Thanks!

Maybe you are looking for

  • PL/SQL component align right

    Hi guys, I was wondering if there was a way to align "Reports Region" PL/SQL components next to each other. I have 2 belonging to the same parent but they are displayed below each other. I tried float:right in my HTP.p code and align=right in the "Re

  • After deleting "Envelope Index" files Mail cannot re-index

    I followed the common suggestion of deleting "Envelope Index" files to speed up mail, but after restarting Mail, it freezes when re-indexing my archive: it blocks after indexing just 6,000 messages out of my 600,000 messages (I have a pretty big emai

  • Finder opens small window

    Every time I open the Finder, it opens in a very small window which I then have to widen. I close it, re-open it, and it's the small window again. Every time. Is there any way to get the Finder to open in a larger window, the size I closed it in?

  • When do I need to redeploy a Shared Variable?

    I am using 2 network shared variables to share data between cfp-2220s.  The shared variables are both clusters of several deifferent data types.  Do I need to redeploy the shared variable everytime I add or remove a variable from one of these cluster

  • Delete personal domain from iWeb

    now that .mac moved to .me when ever i post a site it publishes to the personal domain that is listed in my profile but i don't want it published there but rather to the automatic url that mac provides (i.e. http://web.mac.com/username/Site...) how d