Communicating with server from an Applet.

Hi, i've written a tetris game in an applet.
But i want some way of saving the high scores of everyone on the server.
Is they anyway to communicate the final score back to the server from the applet?
I tried saving the scores to a text file but apparently the file would appear on the client.

Here is some code that you may find useful. This works for the more flexible serialized object approach. For a query string, you would simply do a post on the servlet with the appropriate URL that includes the query string. However, I have found the following serialized object approach to be more convenient.
import java.net.*;
import java.io.*;
This function sends an "AppletRequest" object to the servlet and gets the response back from the servlet in the form of a "ServletResponse" object.
protected static ServletResponse talkToServlet(AppletRequest aReq) {
ServletResponse sr = new ServletResponse();
try {
// Replace the following URL by the URL of your servlet
servletURL = new URL("http://myservleturl/");
servletConn = servletURL.openConnection();
servletConn.setUseCaches (false);
servletConn.setRequestProperty("Content-Type",
"application/octet-stream");
servletConn.setDoInput(true);
servletConn.setDoOutput(true);
} catch (MalformedURLException ex) {
System.out.println("MalformedURLException"+ex.getMessage());
} catch (IOException ex) {
System.out.println("IOException"+ex.getMessage());
} catch (Exception ex) {
System.out.println ("GeneralException: " + ex.getMessage());
try {
outputToServlet = new ObjectOutputStream(servletConn.getOutputStream());
outputToServlet.writeObject(aReq);
outputToServlet.flush();
outputToServlet.close();
} catch (Exception ex) {
System.out.println("GeneralException1: "+ex.getMessage());
try {
try{
inputFrServlet = new ObjectInputStream(servletConn.getInputStream());
sr = (ServletResponse) inputFrServlet.readObject();
inputFrServlet.close();
} catch (EOFException ex) {
System.out.println("EOFException: "+ex.getMessage());
} catch (IOException e) {
System.out.println("IOException: "+e.getMessage());
e.printStackTrace();
} catch (ClassNotFoundException e) {
System.out.println("ClassNotFoundException: "+e.getMessage());
} catch (Exception e) {
System.out.println("GeneralException2: "+e.getMessage());
return(sr);

Similar Messages

  • Communicating with EJB from an applet

    Hello there
    can anyone please clarify an issue for me please? I would like to know if it's possible to call and EJB directly from an applet, without going via jsps or servlets. The J2EE specification says that "All J2EE components except applets, can be clients of RMI-IIOP objects. (Some products might also allow applets to use RMI-IIOP, but this capability is not required)." It appears to be the same situation for JDBC connections also. Would anyone please know how some products allow applets to be clients of RMI-IIOP and what exactly is required?
    many thanks!

    Hi gurus....
    I have the same question....
    can anyone out there throw some light on the topic ?
    many thanks,
    Calherj

  • Create a new file on server from an applet

    Hello!
    I 'm trying to create a text file on server from an applet, i have permissions to write on server and i'm running in apache, my code is
    public void write () {
    try{
    URL url = new URL("http://localhost/bnm/hello.txt");
    URLConnection urlcon = url.openConnection();
    urlcon.setDoOutput(true);
    urlcon.setUseCaches(true);
    PrintWriter pt = new PrintWriter
    (new OutputStreamWriter (urlcon.getOutputStream()));
    String str = new String(URLEncoder.encode("this is output applet ")) ;
    pt.print(str);
    pt.flush();
    catch(Exception e)
    e.printStackTrace();
    The result is nothing, the file isn�t created, but the code don't throw exceptions.
    Ah! in other example, i can read a file of server fro m the applet, the problem is to write
    Anybody, knows the matter??
    Excuse my poor english :P
    Thanks for all.

    I had the same needs and didn't know whether this was possible, due to applets security restriction. So I searched the Web and found some contradictory information. I will explain what I think is the situation, to give you an answer, but also so that other people can tell me whether I understood correctly.
    1) Unless you sign it, an applet cannot write files directly, either client-side or server-side. All what it can do to access a file server-side (except .jar files ?) is opening a http connection, which allows only to retrieve data. When I try to run code such as yours, I get this exception :
    java.net.UnknownServiceException: protocol doesn't support output
         at java.net.URLConnection.getOutputStream(URLConnection.java:679)
    2) As Ares_Man points out, what it can do is opening a http connection not directly with the file you want, but with a server-side script (JSP, PHP, CGI,...) which will be allowed to write files on the server. You can use POST or GET parameters to pass to the script what you are going to write.
    This simple code worked for me (it executed the script toto.php):
              try{
                   URL toto=new URL(getCodeBase(),"toto.php");
                   InputStream f=toto.openStream();
                   f.close();
              catch(Exception e){
                   e.printStackTrace();
    Probably it's a good idea to do a URLConnection.setCache(false) though, to be sure that the script toto.php will be executed.
    3) I don't know how you can pass serialized objects as parameters. So if more than text informations are to be written, I would tend to make the script store them into a database instead of files. That way, you could pass any SQL query as parameter, maybe along with a password parameter for security. I don't know whether this is secure enough.

  • Error message on iweb, no communication with server

    I have three websites on my iweb and hosted by Go Daddy. The main site will not download, error message no communication with server yet other two work fine. I have been to Apple Genius and talked to Go Daddy three times and all is supposedly in order but still will not work. I am able to download on Cyberduck
    but using Iweb would be so much simpler. How can it work on two websites and not the third? Help!

    If the main site, with the URL - http://www.domain-name.com - is not downloading in the browser, it will be because the external index.html file is not present in the root folder on the server.
    The other sites will work because they have the folder-name in the URL ...
    http://www.domain.com/Folder-Name/
    ... where Folder-Name is the name of the site in iWeb.
    Its just a question of republishing the main site if you are using the iWeb FTP and use the settings shown on this page....
    http://www.iwebformusicians.com/iWeb/Publish-Website.html
    If you can use an FTP application, publish the site to a local folder and upload the external index.html file only, to the root folder on the server.

  • Opening a text file in server from an applet running in the client

    Friends,
    I want to open a text file in the server(The server machine uses tomcat 4.1.12 server)from an applet running in the client machine;
    The applet invokes a servlet that opens the text file;this text file is opened in the server machine; but I want it to be opened in the client machine where the applet is running.
    Plese help me to get around this.

    You can open the textfile on the servlet and then send the information to the client (applet) as stirngs. The must then applet convert the stirngs into some object or simply display the information in someway. But then the text file that you are opening must be stored in some relevant tomcat directory e.g. on the server. If you want to open a file on the clients computer, you get into signed applets.

  • Java.lang.InstantiationException: Error communicating with server:

    Hello everybody, I am an easy Helloworld application, the deploy is fine, but when I execute the client it appears the next error:
    java.lang.InstantiationException: Error communicating with server: Lookup error:
    java.net.ConnectException: Connection refused: connect; nested exception is:
    java.net.ConnectException: Connection refused: connect; nested exception
    is:
    javax.naming.NamingException: Lookup error: java.net.ConnectException: C
    onnection refused: connect; nested exception is:
    java.net.ConnectException: Connection refused: connect
    at com.evermind.server.ApplicationClientContext.createContext(Applicatio
    nClientContext.java:300)
    at com.evermind.server.ApplicationClientInitialContextFactory.getInitial
    Context(ApplicationClientInitialContextFactory.java:190)
    at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
    at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
    at javax.naming.InitialContext.init(Unknown Source)
    at javax.naming.InitialContext.<init>(Unknown Source)
    at hello.HelloClient.main(HelloClient.java:33)
    NamingException: Error reading application-client descriptor: Error communicatin
    g with server: Lookup error: java.net.ConnectException: Connection refused: conn
    ect; nested exception is:
    java.net.ConnectException: Connection refused: connect; nested exception
    is:
    javax.naming.NamingException: Lookup error: java.net.ConnectException: C
    onnection refused: connect; nested exception is:
    java.net.ConnectException: Connection refused: connect
    This is my application client:
    // HelloClient.java
    package hello;
    import javax.ejb.*;
    import javax.naming.*;
    import javax.rmi.PortableRemoteObject;
    import java.io.*;
    import java.util.*;
    import java.rmi.RemoteException;
    * A simple client for accessing an EJB.
    public class HelloClient
    public static void main(String[] args)
    System.out.println("client started...");
    try {
    // Initial context properties are set in the jndi.properties file
         Hashtable env = new Hashtable();
         env.put(Context.INITIAL_CONTEXT_FACTORY,"com.evermind.server.ApplicationClientInitialContextFactory");
         env.put(Context.PROVIDER_URL, "ormi://ecd11107.eadscasa.casa.corp:23791/helloworld");
         env.put(Context.SECURITY_PRINCIPAL, "admin");
         env.put(Context.SECURITY_CREDENTIALS, "123");
         Context context = new InitialContext(env);
    // This for use with com.evermind.server.rmi.RMIInitialContextFactory
    //Object homeObject = context.lookup("HelloBean");
    // This is for use with com.evermind.server.ApplicationClientInitialContextFactory
    Object homeObject = context.lookup("java:comp/env/Helloworld");
    // Narrow the reference to HelloHome.
    HelloHome home =
         (HelloHome) PortableRemoteObject.narrow(homeObject, HelloHome.class);
         System.out.println("hello home");
    // Create remote object and narrow the reference to Hello.
    Hello remote =
         (Hello) PortableRemoteObject.narrow(home.create(), Hello.class);
    System.out.println(remote.sayHello("James Earl"));
    } catch(NamingException e) {
    System.err.println("NamingException: " + e.getMessage());
    } catch(RemoteException e) {
    System.err.println("RemoteException: " + e.getMessage());
    } catch(CreateException e) {
    System.err.println("FinderException: " + e.getMessage());
    Can somebody helps me ???

    Thank you, but don�t work well yet. I checked the files orion-application.xml & principals.xml in the directory C:\servOracle\oracle\j2ee\home\application-deployments\helloworld but the result is the same, when I run the client the next error appears:
    NamingException: Lookup error: javax.naming.NoPermissionException: Not allowed to look up HelloBean, check the namespace-access tag setting in orion-application.xml for details; nested exception is:
    javax.naming.NoPermissionException: Not allowed to look up HelloBean, check the namespace-access tag setting in orion-application.xml for details
    This is my orion-application.xml
    <?xml version="1.0"?>
    <!DOCTYPE orion-application PUBLIC "-//ORACLE//DTD OC4J Application runtime 9.04//EN" "http://xmlns.oracle.com/ias/dtds/orion-application-9_04.dtd">
    <orion-application deployment-version="9.0.4.0.0" default-data-source="jdbc/OracleDS" treat-zero-as-null="true">
         <ejb-module remote="false" path="helloworld-ejb.jar" />
         <web-module id="helloworld-web" path="helloworld-web.war" />
         <client-module path="helloworld-client" deployment-time="fce4439997" auto-start="false" />
         <persistence path="persistence" />
         <principals path="principals.xml" />
         <jazn provider="XML" location="jazn-data.xml" />
         <log>
              <file path="application.log" />
         </log>
         <namespace-access>
              <read-access>
                   <namespace-resource root="">
                        <security-role-mapping name="<jndi-user-role>">
                             <group name="users" />
                        </security-role-mapping>
                   </namespace-resource>
              </read-access>
              <write-access>
                   <namespace-resource root="">
                        <security-role-mapping name="<jndi-user-role>">
                             <group name="users" />
                        </security-role-mapping>
                   </namespace-resource>
              </write-access>
         </namespace-access>
    </orion-application>
    And this is my principals.xml
    <?xml version="1.0"?>
    <!DOCTYPE principals PUBLIC "//ORACLE//DTD OC4J Principals 9.04//EN" "http://xmlns.oracle.com/ias/dtds/principals-9_04.dtd">
    <principals>
         <groups>
              <group name="users">
                   <description>users</description>
                   <permission name="rmi:login" />
              </group>
              <group name="guests">
                   <description>guests</description>
              </group>
              <group name="administrators">
                   <description>administrators</description>
                   <permission name="administration" />
              </group>
         </groups>
         <user username="admin" password="ADMIN">
              <description>The default administrator</description>
              <group-membership group="administrators" />
              <group-membership group="guests" />
              <group-membership group="users" />
         </user>
         <user username="SCOTT" password="TIGER">
              <description>no description</description>
              <group-membership group="users" />
              <group-membership group="administrators" />
         </user>
    </principals>
    Thanks in advance, please help me....

  • TREX error 5500: NameServer error: communication with server failed

    Hello TREX Gurus,
    After applying the latest NW 7.0 SPS18, TREX is no longer working.  We are getting this error message in the TREX Administration.
    "5500: NameServer error: communication with server failed;connection refused,location=sap01:37001"
    Any helps is greatly appreciated,
    Dave

    we have same problem... did you find a solution?
    best regards

  • SCOM agent communicating with server?

     
    Dear all,
    After SCOM agent installation how that agent will start communicating with server? Is there any flowchart (like first how the communication will start , then when the MP will get download ..etc..)
    Thnaks,
    Sengottuvel M

    Hi,
    The System Center Management Health service on each monitored agent collects performance data, executes tasks, and so on. Even when the service is unable to communicate with the management server it reports to, the service continues to run and queues the
    collected data and events on the disk of the monitored computer. When the connection is restored, the System Center Management Health service sends collected data and events to the management server.
    Regards, Yan Li

  • Error Communicating with server

    I've completed 4 projects and all went perfect without a hitch.  On starting a new project, I created 3 new bins, audio, stills, video.  When I clicked on capture, I get "error communicating with server. If this continues, contact adobe tech support."  I can't figure out why I'm getting this message now.  I haven't changed settings, using the same HD camcorder, etc.
    Any suggestions?

    Fast response ~ thanks.  I'm using the same camcorder I used on all previous projects: SonyHandycam, so I know it's not the camcorder  I've had no problem capturing in the past.
    The project settings: General>Action Safe & Title Areas are default settings; 20 and 10:  Video display format: Timecode:  Audio display format: audio samples:  Capture Format: DV. In the Sequence settings, they have to be factory default cause I've never changed any setting there.
    Actually I'm really stumped cause I just finished my Grandson's graduation video on July 10 and Premier and Encore worked beautifully.  Now, trying to do a family reunion video, I started new project, didn't change any settings, and when I clicked on Capture, it said "Capture Device Offline".  I went back and replugged in the camcorder, and still nothing.  Closed program, thought about it for awhile, then when I reopen, I get the "error communicating" in the resource panel.
    I doubt this will help you but I'm hoping......

  • Saving to the Server from an Applet

    Hi all, I've posted a message similar to this before, but didn't get too far. I need to get an applet to be able to open a new browser window and display a web page containing two images from the applet, and several strings from the applet. I need the user to be able to save the images to their hard drive, and I need to be able to use them in email forms from the web page. I assume I would have to somehow save the images and a text file from the applet to the server. I have sucessfully converted my objects of type Image to .gif files (with help from these forums) now all I need to do is find some way to save them or somehow get them onto the web page. I have looked into using a servlet, and using sockets, with little sucess either way. With sockets I keep getting IOExceptions and it says Connection refused. Here's the code I'm using for sockets.
    Socket socket;
    try {
         socket = new Socket(getCodeBase().getHost(), 8080);
    }catch(UnknownHostException u)
      {socket = null; System.out.println("Socket failed"); }
    catch(IOException i)
      {socket = null; System.out.println("IO Failed"); i.printStackTrace(); }I didn't get very far with Servlets, as for some reason I can't find very much help on them on the web. Any help is greatly appreciated.

    smg123: Well, I've tried modding my policy file on my local machine, I simply gave All Permissions to the directy that contains the applet on my local machine, with no luck. Not sure about signing the applet, if I understand it correctly it seems like that's a bit overkill making the user accept it and such, when all it really needs to do is server side.
    FelipeGaucho: I've looked at the servlet tutorial before, but I'll give it another shot. I can't ditch the applet approach entirely though, there's a ton of work put into the applet already.
    JohanUP: I've tried a bunch of different port numbers, all with the same results.
    Thanks for the tips guys, keep em coming :)

  • Looking up JMS Server from an applet

    Hi!!
    I am trying to lookup a JMS server via an applet using Oracle9i
    Application Server. It's giving Security Access Exception. Can
    anybody help.

    hi,
    if the security exception is coming from the applet side, then you should consider the following:
    Normally for an applet to run in any web server, the database and theweb server should reside in the same machine to avoid a security exception being thrown. If you have the web server residing in different machine than the database then you can either use signed applet or you can use oracle connection manager to make it as a medium between the web server and the database. The connection manager will have to be installed in the same machine where the database resides. For more information on applet security with oracle products, please refer to oracle connection manager reference guide.
    If the security issue is thrown from the JMS side, then you might conside granting your user Advance queing and some java security permissions.
    hope this helps.

  • Error when communicating with server, and locked fields

    Hi there,
    I am having a really weird, and annoyingly intermittent, problem.
    I'm trying to write a single value to my application via an Input EVDRE, for testing purposes. I've been doing this all morning (admittedly to a different application set but still...) but this time when I "send and refresh", it takes ages before coming back with this error:
    "An error has occurred while communicating with the server"
    Further more, if I look at the table "dbo.lckFinance" there is now a locked field in the database for this specific category and time. So a user without access to a DBA (or the database, in my case!) would be stuck now - even if the communication problem was solved, they couldn't post anyway.
    The application is not part of appshell, we are running BPC version 7.0.112 on SQL Server 2005.
    I've looked in the Event Viewer on the server and found nothing untoward there.
    Any idea what is happening and how I can avoid this in future? The communication thing is obviously a problem, but I'm just as concerned by the locking.
    Please help!
    Many thanks,
    Jason

    Hi Jason,
    If you have problems with the network this has to be solved.
    I don't think we can have a software working if a cable was unplug ).
    We advice our customer to use citrix servers in case if the latency into network is high (more than 200 ms) and of course in case of loosing packages.
    But I don't think the problem in your case is related to the network.
    It seems in your case it was a problem of send governor.
    This can have problem when the cube and dimension are not syncronize or you have an error in one of dimensions.
    Also can you check the table sgqueue if you have any record there when nobody is sending data?
    If you have records there then you have to delete these records.
    Check also tbl"your application"lock if you have records.
    Regards
    Sorin Radulescu

  • Error communicating with server when trying to download a score in soundbooth cs5

    I recently am getting back to some projects of mine.  I went into Soundbooth CS5, and the Resource Central lists all of the scores and sound effects available to me.  It says that i'm online, but then when I try to preview or download anything it gives me the following error:
    "We're sorry, but there was an error communicating with the server.  Please try again and if the problem persists, contact Adobe Technical Support (0) ioError: -1"    
    How do I get at the scores and sound effects?  Is there a way I can download them so that I don't have to consult with the server anymore? 

    Soundbooth is dead and those servers are offline most likely. I haven't seen any official note on this, but that doesn't mean it couldn't be the case...
    Mylenium

  • Can't activate on mac 10.7 Lion-Error communicating with server

    I followed help to remove former install and manually install; tried to sign in and activate get same error as when I also tried "don't authorize andactivate"  which was: Error communicating with  AdobeID server. Try again later. E_AUTH_BAD_DEVICE_KEY"
    I'm getting VERY frustrated with this new LION OS on this mac. I can't use OVERDRIVE media-it won't work, I can't use ADOBE, it won't work. I'm about to take it back to where I bo't couple days ago and go back to iPhone which overdrive ALWAYS works and forget all else!
    If ANYONE knows ANY solution, since it seems one can never talk to a LIVE person at ADOBE to get help, I'd sure appreicate it.

    The way that it is supposed to go, is that when you Launch ADE for the first time, there is a system dialog that supposed to come up and ask you for your login password, so that ADE can get access to the keychain to add the "Digital Editions" password entry. 
    If you cancel out of that dialog, or don't enter in the password, then you will get the "E_AUTH_BAD_DEVICE_KEY" error.
    Make sure that when you launch ADE that this dialog doesn't come up behind ADE  (minimize ADE).

  • Problem with communicating with server https.

    I am in Los Cabos and experiencing problem to add account on my iPad. I use my existing apple ID and password but I receive this message: Verification Error. There is a problem in communicating with the server HTTPS. Can some help me please?

    Did you find anything on this? I'm facing the same issue... Thank you

Maybe you are looking for

  • How do I change iTunes U account on iphone 4?

    I recently just purchased an iPhone 4 second hand and I'm unable to change the iTunes U account information on the phone. I'm constantly being sent the course lessons for iTunes U for the previous owner. When I try to change the settings in itunes U

  • Error occured in SAP NW(BPC)

    Hi, I am doing Migration project from SAP BPC MS to NW. In this I added more than 20 properties in the NW Entity dimension and it is not acceptind 21st property. the length o fthe property is 3 and the peoperty is having max 10 characterstics only..

  • Best BW datasource for consolidation in BPC 7.0NW

    BPC Gurus, I am working on Legal Consolidation. Which is the best datasource to be extracted from ECC New GL? 0FI_GL_20 is better or any other data source is better. The data required is in YTD format. The data is required only from leading ledger. P

  • Dual displays cursor problem

    I have a new Mac Pro and I had a 27" & 24" monitor connected to the card (Display Port, not Thunderbolt). Everything worked fine. I replaced the 24" with a new 27" (Display Port, not Thunderbolt) so now I have two 27" monitors. The problem is that th

  • Someone Deleted my Recently Added Playlist, How do I get it back?

    Someone else who was using my computer accidently deleted my recently added playlist. How do I get it back? I've already updated to the newest version of ITunes, but I still don't have it.