Client/server, applet/server

Hi
I have a question about server/client programming in java.
I have been programming a shortest path algorithm, but it takes to long time to rune this peace of code on the client. So I want to move it to the server.
The client is an applet but also a java program that runs on another computer.
How can I (the simples way) place the algorithm on the server and then call on it from the applet but also from the java program. I also want to send some data from the applet/client to the server, and then the server returns the processed information.
This don�t have to be 100% secure, easy and fast is better : )
(I only write it for my own learning)
I found something that use COBRA but is this necessary?
If you have I would like some sample code, but a url that handles the problem would be excellent.
Best regards,
Anders Sandholm

to applet client and server comunication you can use this:
from Applet To Server write this
private static String servletUri = new String("/myApp/Servlet");
private static String host = new String("localhost");
private static int port = 8080;      
//Sen data to server
URL dataURL = new URL("http",host, port, servletUri);
URLConnection con = dataURL.openConnection();
con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false);                    
//Send data
Serializable obj = "send this";
ObjectOutputStream out = new ObjectOutputStream(new GZIPOutputStream(con.getOutputStream()));
out.writeObject(obj);
out.flush();
out.close();                              
//get a Server aswer
ObjectInputStream din = new ObjectInputStream(new GZIPInputStream(con.getInputStream()));
String data;
data=(String)din.readObject();                    
din.close();     
===================================================================
from Servlet (on server) to applet
     ObjectInputStream din = new ObjectInputStream(new GZIPInputStream(req.getInputStream()));
     String data;
     data=(String) din.readObject();
     din.close();                              
//... do anything
//send client answer
Serializable obj = "result";
ObjectOutputStream out = new ObjectOutputStream(new GZIPOutputStream(res.getOutputStream()));
out.writeObject(obj);
     out.close();     

Similar Messages

  • Introduce My Client-Server Applet RPG Called EsperHunter

    Hi, my name is Yudhi Kurniawan.
    I have developed a client-server applet game which I called it EsperHunter project.
    It's a client-server Java applet Role Playing Game application.
    It's not like common applet games which are stand-alone games. It use server application for
    login player, getting its world and story, saving and loading playing status.
    It's not a multiplayer RPG, but as player you will find the interesting thing that the world
    of game and story will grow up continously or changed because its administrator can update
    or change the world and story of the game. You will find out how it's working at my documentation page.
    But I have a problem to launch that application in actual web because it's difficult to find
    web hosting which I can launch my server game application there. For now, my application is
    reliable for LAN development.
    You can download and try my application at my site at :
    http://members.fortunecity.com/yudhi97
    I really need a solution to solve this problem. As fellow of Java programmer, I hope that we
    can join a bussiness together to develop Java game application.
    Thank you for your attention.

    i'm not downloading all of that. that server sucks ass. i hate all those pop ups. i don't want to install and run any of that shite. maybe you should store all your files in a jar file

  • Kicking out a client from rmi server

    I have a few clients on a rmi server .
    how can I disconnect a client from the server?
    the client is an applet.
    I treid calling a method containning System.exit(0)
    from the server on to the client but it throws a
    java.securtiy .. exception?
    so how can I close down the client applet from the server?
    thanks

    please help
    shall I throw a remote exception on the server

  • TCP server applet, can't instance ServerSocket

    Hy guys ! i'm havin trouble getting my server applet on it's feet, this is mainly because it won't get past instancing the server socket.
    this is the code i'm using, i've put it in a button's event handler
            String clientSentence;
            try{
            System.out.println("starting Server");
            ServerSocket welcomeSocket = new ServerSocket(6789);
            while (true) {
                Socket connectionSocket = welcomeSocket.accept();
                System.out.println("Server has started");
                BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
                DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
                clientSentence = inFromClient.readLine();
            }catch(Exception e){
            System.out.println("there's a problem :"+e.getMessage());}i run the applet, click the button, i see "starting Server", and it locks up. I've tried other ports, no difference it locks up on any port

    OK, let's forget the applet now. Your application should work. "Does not get that far". How far does it get?
    A debugger should tell you. Or some System.out.println() placed all over the place. It's hard to see what happens with so little info. I strongly believe that it gets farther than this. It gets to the accept() call and it blocks there, as it should. Let it run to wherever it goes, open a Command Prompt and type "netstat -an". I believe your server should be listed something like this:
    TCP    0.0.0.0:6789            0.0.0.0:0              LISTENINGIf it is, the application works fine.
    Check the code with correct System.out.println():
    package testcuc;
    import java.io.*;
    import java.net.*;
    public class Main {
        public static void main(String[] args) {
            String clientSentence;
            String capitalizedSentence;
            try{
            System.out.println("starting Server");
            ServerSocket welcomeSocket = new ServerSocket(6789);
            System.out.println("Server has started");
            while (true) {
                System.out.println("Waiting for client to connect");
                Socket connectionSocket = welcomeSocket.accept();
                System.out.println("Client connected");
                BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
                DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
                clientSentence = inFromClient.readLine();
                capitalizedSentence =clientSentence.toUpperCase() + '\n';
                outToClient.writeBytes(capitalizedSentence);
            }catch(Exception e){
            e.printStackTrace();}
        }//main
    }//MainEdited by: baftos on May 18, 2009 2:47 PM

  • Async tcp client and server. How can I determine that the client or the server is no longer available?

    Hello. I would like to write async tcp client and server. I wrote this code but a have a problem, when I call the disconnect method on client or stop method on server. I can't identify that the client or the server is no longer connected.
    I thought I will get an exception if the client or the server is not available but this is not happening.
    private async void Process()
    try
    while (true)
    var data = await this.Receive();
    this.NewMessage.SafeInvoke(Encoding.ASCII.GetString(data));
    catch (Exception exception)
    How can I determine that the client or the server is no longer available?
    Server
    public class Server
    private readonly Dictionary<IPEndPoint, TcpClient> clients = new Dictionary<IPEndPoint, TcpClient>();
    private readonly List<CancellationTokenSource> cancellationTokens = new List<CancellationTokenSource>();
    private TcpListener tcpListener;
    private bool isStarted;
    public event Action<string> NewMessage;
    public async Task Start(int port)
    this.tcpListener = TcpListener.Create(port);
    this.tcpListener.Start();
    this.isStarted = true;
    while (this.isStarted)
    var tcpClient = await this.tcpListener.AcceptTcpClientAsync();
    var cts = new CancellationTokenSource();
    this.cancellationTokens.Add(cts);
    await Task.Factory.StartNew(() => this.Process(cts.Token, tcpClient), cts.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default);
    public void Stop()
    this.isStarted = false;
    foreach (var cancellationTokenSource in this.cancellationTokens)
    cancellationTokenSource.Cancel();
    foreach (var tcpClient in this.clients.Values)
    tcpClient.GetStream().Close();
    tcpClient.Close();
    this.clients.Clear();
    public async Task SendMessage(string message, IPEndPoint endPoint)
    try
    var tcpClient = this.clients[endPoint];
    await this.Send(tcpClient.GetStream(), Encoding.ASCII.GetBytes(message));
    catch (Exception exception)
    private async Task Process(CancellationToken cancellationToken, TcpClient tcpClient)
    try
    var stream = tcpClient.GetStream();
    this.clients.Add((IPEndPoint)tcpClient.Client.RemoteEndPoint, tcpClient);
    while (!cancellationToken.IsCancellationRequested)
    var data = await this.Receive(stream);
    this.NewMessage.SafeInvoke(Encoding.ASCII.GetString(data));
    catch (Exception exception)
    private async Task Send(NetworkStream stream, byte[] buf)
    await stream.WriteAsync(BitConverter.GetBytes(buf.Length), 0, 4);
    await stream.WriteAsync(buf, 0, buf.Length);
    private async Task<byte[]> Receive(NetworkStream stream)
    var lengthBytes = new byte[4];
    await stream.ReadAsync(lengthBytes, 0, 4);
    var length = BitConverter.ToInt32(lengthBytes, 0);
    var buf = new byte[length];
    await stream.ReadAsync(buf, 0, buf.Length);
    return buf;
    Client
    public class Client
    private TcpClient tcpClient;
    private NetworkStream stream;
    public event Action<string> NewMessage;
    public async void Connect(string host, int port)
    try
    this.tcpClient = new TcpClient();
    await this.tcpClient.ConnectAsync(host, port);
    this.stream = this.tcpClient.GetStream();
    this.Process();
    catch (Exception exception)
    public void Disconnect()
    try
    this.stream.Close();
    this.tcpClient.Close();
    catch (Exception exception)
    public async void SendMessage(string message)
    try
    await this.Send(Encoding.ASCII.GetBytes(message));
    catch (Exception exception)
    private async void Process()
    try
    while (true)
    var data = await this.Receive();
    this.NewMessage.SafeInvoke(Encoding.ASCII.GetString(data));
    catch (Exception exception)
    private async Task Send(byte[] buf)
    await this.stream.WriteAsync(BitConverter.GetBytes(buf.Length), 0, 4);
    await this.stream.WriteAsync(buf, 0, buf.Length);
    private async Task<byte[]> Receive()
    var lengthBytes = new byte[4];
    await this.stream.ReadAsync(lengthBytes, 0, 4);
    var length = BitConverter.ToInt32(lengthBytes, 0);
    var buf = new byte[length];
    await this.stream.ReadAsync(buf, 0, buf.Length);
    return buf;

    Hi,
    Have you debug these two applications? Does it go into the catch exception block when you close the client or the server?
    According to my test, it will throw an exception when the client or the server is closed, just log the exception message in the catch block and then you'll get it:
    private async void Process()
    try
    while (true)
    var data = await this.Receive();
    this.NewMessage.Invoke(Encoding.ASCII.GetString(data));
    catch (Exception exception)
    Console.WriteLine(exception.Message);
    Unable to read data from the transport connection: An existing   connection was forcibly closed by the remote host.
    By the way, I don't know what the SafeInvoke method is, it may be an extension method, right? I used Invoke instead to test it.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Copy file from client PC to server in a web deployed application

    I have developed one application using Oracle forms 6i, which is deployed on the web server.
    I run this application from a client PC in Internet Explorer using internet.
    I want to copy one file from the client PC to the web server.
    I have done following things
    - Created a shared folder on the server and given full rights to every one on this folder
    - I use 'net use' command in my program to connect to this shared folder
    - I use copy command to copy file from local client pc to server. This copy command I am executing using host command of my programming (PL/SQL: eg. host('copy abc.txt \\server\share\') )
    But this does not work.
    When I do the same thing in command window, it works.
    (ie. Start-Run cmd to open command window and then type the above copy command)
    Can you please tell me, how to copy a file from client PC to the sever in Web deployed application?
    Thanks

    I downloaded D2KWUtil from the link suggested by you. It has very nice example demo form. But the documentation provided says following
    Using D2KWUTIL in Web Deployed Applications
    The use of this library is not supported with Web deployed applications.
    In a web deployment scenario not all functions within D2KWUTIL will work. Any function that interacts with the User Interface (such as those in the WIN_API_DIALOG package) will fail.
    Any interaction with the O/S by other functions will all be executed on the NT server and will act within, or return information pertinant to, the environment on that machine. For instance GET_COMPUTER_NAME will return the Server’s name, not the name of the computer that the Client browser is running on. Likewise COPY_FILE will copy files in the Forms Server not on the Client.
    Functions such as those in WIN_API_BITOP will continue to work without change.
    so this will not work in web deployed application.
    Any other suggestion?
    Thanks

  • How can i load file into database from client-side to server-side

    i want to upload file from client-side to server-side, i use the following code to load blob into database.
    if the file is in the server-side, it can work, but if it in the client-side, it said that the system cannot find the file. i think it only will search the file is in the server-side or not, it will not search the client-side.
    how can i solve it without upload the file to the server first, then load it into database??
    try
    ResultSet rset = null;
    PreparedStatement pstmt =
    conn.prepareStatement ("insert into docs values (? , EMPTY_BLOB())");
    pstmt.setInt (1, docId);
    pstmt.execute ();
    // Open the destination blob:
    pstmt.setInt (1, docId);
    rset = pstmt.executeQuery (
    "SELECT content FROM docs WHERE id = ? FOR UPDATE");
    BLOB dest_lob = null;
    if (rset.next()) {
    dest_lob = ((OracleResultSet)rset).getBLOB (1);
    // Declare a file handler for the input file
    File binaryFile = new File (fileName);
    FileInputStream istream = new FileInputStream (binaryFile);
    // Create an OutputStram object to write the BLOB as a stream
    OutputStream ostream = dest_lob.getBinaryOutputStream();
    // Create a tempory buffer
    byte[] buffer = new byte[1024];
    int length = 0;
    // Use the read() method to read the file to the byte
    // array buffer, then use the write() method to write it to
    // the BLOB.
    while ((length = istream.read(buffer)) != -1)
    ostream.write(buffer, 0, length);
    pstmt.close();
    // Close all streams and file handles:
    istream.close();
    ostream.flush();
    ostream.close();
    //dest_lob.close();
    // Commit the transaction:
    conn.commit();
    conn.close();
    } catch (SQLException e) {

    Hi,
    Without some more details of the configuration, its difficult to know
    what's happening here. For example, what do you mean by client side
    and server side, and where are you running the upload Java application?
    If you always run the application on the database server system, but can't
    open the file on a different machine, then it sounds like a file protection
    problem that isn't really connected with the database at all. That is to
    say, if the new FileInputStream (binaryFile) statement fails, then its not
    really a database problem, but a file protection issue. On the other hand,
    I can't explain what's happening if you run the program on the same machine
    as the document file (client machine), but you can't write the data to the
    server, assuming the JDBC connection string is set correctly to connect to
    the appropriate database server.
    If you can provide some more information, we'll try to help.
    Simon
    null

  • Can i use same Server for server side and client??

    Hi,
    i m developing webservices in java and using two different server for server side and client.
    e.g. i m using one tomcat server on a machine to run webservice and again using one more tomcat server on client side at different machine.
    and hence it need two tomcat server.
    But i want only one server to run webservice and client.
    So please help me out...
    Thanks

    Hi,
    It is always recommended to maintain different servers
    REgards,
    Ravi.

  • How to enable traffic between VPN clients in Windows Server 2012 R2?

    Hello, 
    I installed Remote Access role with VPN.
    IPv4 Router is enabled: http://snag.gy/UAMY2.jpg
    VPN clients should use static ip pool: http://snag.gy/REjkB.jpg
    One VPN user is configured to have static ip: http://snag.gy/TWwq0.jpg
    VPN server uses Windows Authentication and Windows Accounting.
    With this setup, VPN clients can connect to server, get ip addresses and can see server via server's vpn ip. Server can connect to VPN clients too (Using client's vpn ips). But VPN clients can't communicate with each other.
    For example, VPN server has ip 192.168.99.5
    VPN Client 1 - 192.168.99.6
    VPN Client 2 - 192.168.99.7
    I am able to ping 192.168.99.5 from both clients, and able to ping 192.168.99.6 and 192.168.99.7 from server via remote desktop. But I am not able to ping 192.168.99.7 from client 1 and 192.168.99.6 from client 2.
    If I trace route from 192.168.99.6 to 192.168.99.7 - I can see that packets goes to server (192.168.99.5) and next hop - request timeout.
    What else should I configure to allow network traffic between VPN clients?

    Hi,
    To better analyze this issue, would you please post the routing tables on the two VPN clients? You can run "route print" at the command prompt to get the routing table.
    Best regards,
    Susie
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact [email protected]

  • Is it possible to lock the keyboard of a client from a server using java

    please explain wheterit is possible to lock the keyboard of a client from a server using java

    You want to process code on one machine, and thereby lock the keyboard on another machine? No, that's not possible. It is extremely far from possible.
    Of course, if the client is running software with security holes in it you might hack into it and crash the thing. This will lock up the keyboard pretty good. I hope that's not what you want ...
    Or are you talking about a setup where you already have code running on the client, and some sort of communication between client and server? In that case what you need to know is whether it is possible to lock the keyboard at all. Once you have figured that out, it is trivial to add the communication code to have the server software tell the client software to lock the keyboard.
    So what do you mean with "lock the keyboard"? It's pretty easy to remove/disable all keyboard related listeners in your own application. It's a lot harder (and AFAIK impossible with pure java) to disable alt-tabbing out of the application. And impossible, except from exploiting security holes, to lock the ctrl-alt-delete-combination on windows machine.

  • ORA-03113 while connect from 8i client to 7 Server

    Hi,
    I have a Oracle 7.3.3 Server running on a SCO OpenSever 5.0.5 and a Oracle 8i Client 8.1.6.0.0 on a RedHat Linux 6.2.
    When I try to connect from the client to the server by issue command "sqlplus user@test", it responses me "Error while trying to retrieve text for error ORA-03113". But when I run "netasst" to test the connection, it says the connection was sucessful.
    Can anyone help? Here are my configuration files:
    Listener.ora on Server side:
    LISTENER=
    (ADDRESS LIST=
    (ADDRESS =
    (COMMUNITY=TCP.world)
    (PROTOCOL=TCP)
    (Host=10.128.64.52)
    (Port=1526)
    STARTUP_WAIT_TIME_LISTENER = 0
    CONNECT_TIMEOUT_LISTENER = 10
    TRACE_LEVEL_LISTENER = OFF
    SID_LIST_LISTENER =
    (SID_LIST=
    (SID_DESC =
    (SID_NAME = test)
    (ORACLE_HOME = /usr/app/oracle/product/7.3.3
    (PRESPAWN_MAX=10)
    tnsnames.ora on client side:
    TEST.888.COM
    (DESCRIPTION =
    (ADDRESS_LISTS =
    (ADDRESS =
    (PROTOCOL = TCP)
    (HOST = 10.128.64.52)
    (PORT = 1526)
    (CONNECT_DATA =
    (SID = test)
    )

    Hi,
    I don't have a 64 bit instance, but maybe another test will be usefull, try to get a connection with sqlplus on the server but via sqlnet like "user/passwd@tnsentry" I think if that also is not possible it is not the 64 bit issue but more that the listener itself coundn't etsablish a db connection, be aware tnsping is only testing if the listener is running and do not check if the listener is able to connect to the db.
    Hope this helps a little to find your real proble ;-), Olaf

  • Problem with program hanging randomly on certain commands from win 7 pro client to SB Server

    Having a problem with program hanging randomly on certain commands from Win-7 Pro Client to SB Server Both 64-Bit
    Five other slower XP-Pro 32 Bit systems though they are older and slower systems do not seem to hang as readily if at all.
    It has been very frustrating as the Client-System, SB-Server and Program should work w/o any hitches, but this seems to work fine @ times and then hang randomly.
    Would appreciate any and all suggestions in assisting.... JimBAgde-MSS  

    You can try this, as I have had similar problems with another MS Access .MDB file and slow access before. This fixed my problem for me. On the slow computer, make sure the program is set to see the .mdb file via UNC path, not a mapped drive letter. ex.
    USE:  \\yourserver\shared\dental\file.mdb
    DO NOT: S:\\shared\dental\file.mdb
    hope this helps

  • What's the difference between client combo and server combo? Also, what would happen if I install both?

    what's the difference between client combo and server combo? Also, what would happen if I install both?

    One is for the base version of the Mac OS, the other is for the Server version. You can only install the one that matches your system.

  • What is the recommended number of clients per Mac server? Also what are some recommended specs when purchasing an Apple machine that will have Mac OS X server installed?

    What is the recommended number of clients per Mac server? Also what are some recommended specs when purchasing an Apple machine that will have Mac OS X server installed? We have around 300 clients that need to be enroled on the Mac server. I want to know what is the recommended amount of clients a Mac server should contain. Also what are some recommended specs to make sure the server will flawlessly?

    Hello cpreasbeck,
    Thank you for contacting Apple Support Communities.
    I was able to find the following transition guide for Xserve that provides some workload guidance to determine performance when planning a server deployment.
    Transition Guide Xserve
    http://images.apple.com/xserve/pdf/L422277A_Xserve_Guide.pdf
    On page 9, Performance there is a chart that provides maximum numbers of connected users for various activities such as file sharing, mail, web, calendar, directory services and Time Machine and the CPU used as a server (Xserve, Mac Pro, Mac Mini). This information is a bit dated as the referenced software is Snow Leopard Server (OS X 10.6), and the hardware is older also, but it should give you a general idea of what you might need to look for.
    Regards,
    Jeff D.

  • How to know oracle client or oracle server installed in m/c ?

    Hi all,
    Could any one tell me how to know whether oracle 10.1 s/w installed in my machine is client version or server . Is there any easy method..??
    Thanks in advance.

    Hi,
    Check the database / dbs folder exist in the $ORACLE_HOME if yes then SERVER else CLIENT.
    PS: Above is not a standard method, i am telling based on DIRECTORY.
    Regards,
    Taj

Maybe you are looking for