Client/server socket based application

hi does anyone have example of client/server socket based application using Spring and Maven
where application do the following
Client sends a request with a path to any file on the server
„h Server reads the file and responds back with the content
„h Client outputs the content to the console
am trying to follow this
http://www2.sys-con.com/itsg/virtualcd/java/archives/0205/dibella/index.html
http://syntx.io/a-client-server-application-using-socket-programming-in-java/
am using java 6

i have attempt code but i wht to do the following
client/server socket based application that will read the content of a file and stream the content of the file to the client. The client must simply output the content of the file to the console using System.out. The client must be able to run in a standalone mode (non-network mode) or in a remote mode.
Additionally the client must be designed in a way that i can print the output to a console but must be interchangeable where if requirements change i can persist the response to file or persist the response to a database.
/* Server.java*/
///ifgetBoolen= true then...
import java.io.*;
import java.net.*;
import java.util.*;
import java.sql.*;
public class Server
    static String array[][];
    // STEP 1 a1  
    // Server socket
    ServerSocket listener;
    // STEP 1 a2 Client connection
    Socket client;
    ObjectInputStream in;
    ObjectOutputStream out;
    public void createConnection() throws IOException
            System.out.println("\nSERVER >>> Waiting for connection.....");
            client = listener.accept();
            String IPAddress = "" + client.getInetAddress();
            DisplayMessage("SERVER >>> Connected to " + IPAddress.substring(1,IPAddress.length()));
      public void runServer()
        // Start listening for client connections
        // STEP 2
        try
            listener = new ServerSocket(12345, 10);
            createConnection();
              // STEP 3
//              processConnection();
        catch(IOException ioe)
            DisplayMessage("SERVER >>> Error trying to listen: " + ioe.getMessage());
    private void closeConnection()
        DisplayMessage("SERVER >>> Terminating connections");
        try
            if(out != null && in != null)
                  out.close();
                in.close();
                client.close();                
        catch(IOException ioe)
            DisplayMessage("SERVER >>> Closing connections");
    public static void define2DArray(ResultSet RS, int Size)
        try
            ResultSetMetaData RMSD = RS.getMetaData();
            DisplayMessage("SERVER >>> Requested arraySize: " + Size);
            if (RS.next())
                array = new String[Size][RMSD.getColumnCount()];
                for (int Row = 0; Row < Size; Row++)
                    for (int Col = 0; Col < RMSD.getColumnCount(); Col++)
                        array[Row][Col] = new String();
                        array[Row][Col] = RS.getString(Col+1);
                        DisplayMessage(array[Row][Col] + " ");
                    RS.next();
            else
                array = new String[1][1];
                array[0][0] = "#No Records";
        catch (Exception e)
            DisplayMessage("SERVER >>> Error in defining a 2DArray: " + e.getMessage());  
    public static void DisplayMessage(final String IncomingSMS)
        System.out.println(IncomingSMS);
//client
* @author
import java.io.*;
import java.net.*;
import javax.swing.*;
public class ClientSystem
    static Socket server;
    static ObjectOutputStream out;
    static ObjectInputStream in;
    static String Response[][];
    static boolean IsConnected = false;
    static int Num = 0;
    public static void connectToServer() throws IOException
        server = new Socket("127.0.0.1", 12345);
//        server = new Socket("000.00.98.00", 12345);
        String IPAddress = "" + server.getInetAddress();
        DisplayMessage("\nCLIENT >>> Connected to " + IPAddress.substring(1,IPAddress.length()));
    public static void getStreams() throws IOException
        out = new ObjectOutputStream(server.getOutputStream());
        out.flush();
          in = new ObjectInputStream(server.getInputStream());
          IsConnected = true;
          DisplayMessage("CLIENT >>> Got I/O streams");  
    public static void runClient()
        try
            connectToServer();
            getStreams();
              DisplayMessage("CLIENT >>> Connection successfull....\n");
              DisplayMessage("CLIENT >>> Want to talk to server");
        catch (IOException ioe)
            System.out.print("."+Num);
            Num++;
    public static void closeConnection()
        try
            out.close();
            in.close();
            server.close();  
        catch(IOException error)
            DisplayMessage("CLIENT >>> Could not close connections");
    public static void Start()
        System.out.print("\nCLIENT >>> Attempting connection.....");
        try
            IsConnected = false;
            while (IsConnected == false)
                runClient();
                if (IsConnected == false)
                    Thread.sleep(100);
        catch (Exception e)
            DisplayMessage("CLIENT >>> Attempting connection.....");
    public static String sendSMS(String sms)
        Response = new String[0][0];
        try
            DisplayMessage("CLIENT >>> " + sms);
            out.writeObject(sms);
            out.flush();
            Response = (String[][])in.readObject();
            DisplayMessage("CLIENT >>> Waiting for server to respond...");
            for (int Row = 0; Row < Response.length; Row++)
                System.out.printf( "_SERVER >>> \t");
                for (int Col = 0; Col < Response[Row].length; Col++)
                    //DisplayMessage( "_SERVER >>> " + Response[Row][Col] + " ");
                    System.out.printf( "%s\t", Response[Row][Col]);
                System.out.println();
            DisplayMessage("CLIENT >>> Query processed successfully....\n");
        catch(ClassNotFoundException cnfe)
            DisplayMessage("CLIENT >>> Class not found for casting received object");
        catch(IOException ioe)
            reConnect();          
        catch (Exception sqle)
            DisplayMessage("CLIENT >>> Error sending query ??? " + sqle.getMessage());
        return "transmission successfull";
    public static void reConnect()
        try
            DisplayMessage("CLIENT >>> Connection was lost. Trying to reconnect...");
            closeConnection();
            Thread.sleep(100);
            IsConnected = false;
            while (IsConnected == false)
                runClient();
                Thread.sleep(200);
        catch (Exception e)
            DisplayMessage("CLIENT >>> Error trying to Re-Connect...");
    public static void DisplayMessage(final String IncomingSms)
        System.out.println(IncomingSms);
    System.out.printf("Isms: %s", IncomingSms);  ///naah.
    public static String[][] getResponse()
        return Response;
    public static String getResponse(int row, int col)
        return Response[row][col];
how can i do below using above code
The program must be able to work in a non-networked mode. In this mode, the server and client must run in the same VM and must perform no networking, must not use loopback networking i.e: no “localhost” or “127.0.0.1”, and must not involve the serialization of any objects when communicating between the client and server components.
The operating mode is selected using the single command line argument that is permitted.
imust use a socket connection and define a protocol. networking must be entirely bypassed in the non-network mode.

Similar Messages

  • FU Ant task failure: java.util.concurrent.ExecutionException: could not close client/server socket

    We sometimes see this failure intermitently when using the FlexUnit Ant task to run tests in a CI environment. The Ant task throws this exception:
    java.util.concurrent.ExecutionException: could not close client/server socket
    I have seen this for a while now, and still see it with the latest 4.1 RC versions.
    Here is the console output seen along with the above exception:
    FlexUnit player target: flash
    Validating task attributes ...
    Generating default values ...
    Using default working dir [C:\DJTE\commons.formatter_swc\d3flxcmn32\extracted\Source\Flex]
    Using the following settings for the test run:
    FLEX_HOME: [C:\dev\vert-d3flxcmn32\302100.41.0.20110323122739_d3flxcmn32]
    haltonfailure: [false]
    headless: [false]
    display: [99]
    localTrusted: [true]
    player: [flash]
    port: [1024]
    swf: [C:\DJTE\commons.formatter_swc\d3flxcmn32\extracted\build\commons.formatter.tests.unit.sw f]
    timeout: [1800000ms]
    toDir: [C:\DJTE\commons.formatter_swc\d3flxcmn32\reports\xml]
    Setting up server process ...
    Entry  [C:\DJTE\commons.formatter_swc\d3flxcmn32\extracted\build] already  available in local trust file at  [C:\Users\user\AppData\Roaming\Macromedia\Flash  Player\#Security\FlashPlayerTrust\flexUnit.cfg].
    Executing 'rundll32' with arguments:
    'url.dll,FileProtocolHandler'
    'C:\DJTE\commons.formatter_swc\d3flxcmn32\extracted\build\commons.formatter.tests.unit.swf '
    The ' characters around the executable and arguments are
    not part of the command.
    Starting server ...
    Opening server socket on port [1024].
    Waiting for client connection ...
    Client connected.
    Setting inbound buffer size to [262144] bytes.
    Receiving data ...
    Sending acknowledgement to player to start sending test data ...
    Stopping server ...
    End of test data reached, sending acknowledgement to player ...
    When the problem occurs, it is not always during the running of any particular test (that I am aware of). Recent runs where this failure was seen had the following number of tests executed (note: the total number that should be run is 45677): 18021, 18, 229.
    Here is a "good" run when the problem does not occur:
    Setting inbound buffer size to [262144] bytes.
    Receiving data ...
    Sending acknowledgement to player to start sending test data ...
    Stopping server ...
    End of test data reached, sending acknowledgement to player ...
    Closing client connection ...
    Closing server on port [1024] ...
    Analyzing reports ...
    Suite: com.formatters.help.TestGeographicSiteUrls
    Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.008 sec
    Suite: com.formatters.functionalUnitTest.testCases.TestNumericUDF
    Tests run: 13, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.071 sec
    Results :
    Tests run: 45,677, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 201.186 sec
    Has anyone else ran across this problem?
    Thanks,
    Trevor

    I am not sure if this information will help everyone, but here goes...
    For us, these problems with FlexUnit tests crashing the Flash Player appear to be related to couple of factors. Recently, we moved up from Flex 3.2 to Flex 4.1 as our development baseline.  Many people complained that their development environment (Flash Builder, etc.) was much more unstable.  Apparently, 4.1 produces SWFs that require more memory to run than 3.2 does?  Anyway, we still had Flash Player 10.1 as our runtime baseline.  Apparently, that version of the player was not as capable of running larger FlexUnit test SWFs, and would crash (as I posted months earlier).  I upgraded to the latest 10.3 standalone player versions, and the crashes have now ceased.  It would be nice to know exactly what was causing the crashes, but memory management (or lack of) is my best guess.
    So, if you are seeing these issues, try upgrading to the latest Flash Player version.
    Regards,
    Trevor

  • Client Server Socket With GUI

    Hi,
    As the name of the forum suggests I am very new to this whole thing.
    I am trying to write a client/server socket program that can encrypt and decrypt and has a GUI, can't use JCE or SSL or any built in encryption tools.
    I have the code for everything cept the encryption part.
    Any help, greatly appreciated,

    tnks a million but how do i incorporate that into the following client and server code:
    here's the client code:
    import java.awt.Color;
    import java.awt.BorderLayout;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.*;
    import java.net.*;
    class SocketClient extends JFrame
              implements ActionListener {
    JLabel text, clicked;
    JButton button;
    JPanel panel;
    JTextField textField;
    Socket socket = null;
    PrintWriter out = null;
    BufferedReader in = null;
    SocketClient(){ //Begin Constructor
    text = new JLabel("Text to send over socket:");
    textField = new JTextField(20);
    button = new JButton("Click Me");
    button.addActionListener(this);
    panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.setBackground(Color.white);
    getContentPane().add(panel);
    panel.add("North", text);
    panel.add("Center", textField);
    panel.add("South", button);
    } //End Constructor
    public void actionPerformed(ActionEvent event){
    Object source = event.getSource();
    if(source == button){
    //Send data over socket
    String text = textField.getText();
    out.println(text);
         textField.setText(new String(""));
    //Receive text from server
    try{
         String line = in.readLine();
    System.out.println("Text received :" + line);
    } catch (IOException e){
         System.out.println("Read failed");
         System.exit(1);
    public void listenSocket(){
    //Create socket connection
    try{
    socket = new Socket("HUGHESAN", 4444);
    out = new PrintWriter(socket.getOutputStream(), true);
    in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
    } catch (UnknownHostException e) {
    System.out.println("Unknown host: HUGHESAN.eng");
    System.exit(1);
    } catch (IOException e) {
    System.out.println("No I/O");
    System.exit(1);
    public static void main(String[] args){
    SocketClient frame = new SocketClient();
         frame.setTitle("Client Program");
    WindowListener l = new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    frame.addWindowListener(l);
    frame.pack();
    frame.setVisible(true);
         frame.listenSocket();
    SERVER Code
    import java.awt.Color;
    import java.awt.BorderLayout;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.*;
    import java.net.*;
    class SocketServer extends JFrame
              implements ActionListener {
    JButton button;
    JLabel label = new JLabel("Text received over socket:");
    JPanel panel;
    JTextArea textArea = new JTextArea();
    ServerSocket server = null;
    Socket client = null;
    BufferedReader in = null;
    PrintWriter out = null;
    String line;
    SocketServer(){ //Begin Constructor
    button = new JButton("Click Me");
    button.addActionListener(this);
    panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.setBackground(Color.white);
    getContentPane().add(panel);
    panel.add("North", label);
    panel.add("Center", textArea);
    panel.add("South", button);
    } //End Constructor
    public void actionPerformed(ActionEvent event) {
    Object source = event.getSource();
    if(source == button){
    textArea.setText(line);
    public void listenSocket(){
    try{
    server = new ServerSocket(4444);
    } catch (IOException e) {
    System.out.println("Could not listen on port 4444");
    System.exit(-1);
    try{
    client = server.accept();
    } catch (IOException e) {
    System.out.println("Accept failed: 4444");
    System.exit(-1);
    try{
    in = new BufferedReader(new InputStreamReader(client.getInputStream()));
    out = new PrintWriter(client.getOutputStream(), true);
    } catch (IOException e) {
    System.out.println("Accept failed: 4444");
    System.exit(-1);
    while(true){
    try{
    line = in.readLine();
    //Send data back to client
    out.println(line);
    } catch (IOException e) {
    System.out.println("Read failed");
    System.exit(-1);
    protected void finalize(){
    //Clean up
    try{
    in.close();
    out.close();
    server.close();
    } catch (IOException e) {
    System.out.println("Could not close.");
    System.exit(-1);
    public static void main(String[] args){
    SocketServer frame = new SocketServer();
         frame.setTitle("Server Program");
    WindowListener l = new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    frame.addWindowListener(l);
    frame.pack();
    frame.setVisible(true);
         frame.listenSocket();
    Again help on this is very welcomed

  • Client Server Desktop Sharing Application

    I have made a client server Desktop Sharing application containing a java class for server and one for client, how can I deploy my java client bytecode at client's machine without installing JVM on that machine and not even going to the clients machine if we are connected in LAN.
    I want to start my client program on that machine as & when the OS starts, so, is there any way to start a bytecode (or exe ) as a windows service( I dont want an installer)? Please provide information if I can get this done by some other service/software and tell me its name too.
    Thanks for your reply (awaited)

    I have made a client server Desktop Sharing
    application containing a java class for server and
    one for client, how can I deploy my java client
    bytecode at client's machine without installing JVM
    on that machine and not even going to the clients
    machine if we are connected in LAN.Well this can be done if the server has access to the clients hard disk you can simply copy the files from the server. But not recamended
    I want to start my client program on that machine as
    & when the OS starts, so, is there any way to start a
    bytecode (or exe ) as a windows service( I dont want
    an installer)? Please provide information if I can
    get this done by some other service/software and tell
    me its name too.Search in google for JavaService it is a simple third party exe that can register java programs as background services
    Thanks for your reply (awaited)

  • Best practice for client-server(Socket) application

    I want to build a client-server application
    1) On startup.. client creates connection to Server and keeps reading data from server
    2) Server keeps on sending different messages
    3) Based on messages(Async) from server client view has to be changed
    I tried different cases ended up facing IllegalStateChangeException while updating GUI
    So what is the best way to do this?
    Please give a working example .
    Thanks,
    Vijay
    Edited by: 844427 on Jan 12, 2012 12:15 AM
    Edited by: 844427 on Jan 12, 2012 12:16 AM

    Hi EJP,
    Thanks for the suggestion ,
    Here is sample code :
    public class Lobby implements LobbyModelsChangeListener{
        Stage stage;
        ListView<String> listView;
        ObservableList ol;
         public Lobby(Stage primaryStage) {
            stage = primaryStage;
               ProxyServer.startReadFromServer();//Connects to Socket Server
             ProxyServer.addLobbyModelChangeListener(this);//So that any data from server is fetched to Lobby
            init();
        private void init() {
              ProxyServer.getLobbyList();//Send
            ol = FXCollections.observableArrayList(
              "Loading Data..."
            ol.addListener(new ListChangeListener(){
                @Override
                public void onChanged(Change change) {
                    listView.setItems(ol);
         Group root = new Group();
        stage.setScene(new Scene(root));
         listView = new ListView<String>();
        listView.maxWidth(stage.getWidth());
         listView.setItems(ol);
         listView.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
        istView.setOnMouseClicked(new EventHandler<MouseEvent>(){
                @Override
                public void handle(MouseEvent t) {
    //                ListView lv = (ListView) t.getSource();
                    new NewPage(stage);
         root.getChildren().add(listView);
         @Override
        public void updateLobby(LobbyListModel[] changes) {
    //        listView.getItems().clear();
            String[] ar = new String[changes.length];
            for(int i=0;i<changes.length;i++)
                if(changes!=null)
    System.out.println(changes[i].getName());
    ar[i] = changes[i].getName();
    ol.addAll(ar);
    ProxyServer.javaProxyServer
    //Implements runnable
    public void run()
         ......//code to read data from server
    //make array of LobbyListModel[] ltm based on data from server
         fireLobbyModelChangeEvent(ltm);
    void addLobbyModelChangeListener(LobbyModelsChangeListener aThis) {
    this.lobbyModelsChangeListener = aThis;
         private void fireLobbyModelChangeEvent(LobbyListModel[] changes) {
    LobbyModelsChangeListener listner
    = (LobbyModelsChangeListener) lobbyModelsChangeListener;
    listner.updateLobby(changes);
    Exception :
    java.lang.IllegalStateException: Not on FX application thread; currentThread = Thread-5
             at line         ol.addAll(ar);
    But ListView is getting updated with new data...so not sure if its right way to proceed...
    Thanks,
    Vijay                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Client / Server Socket Communication - Should use 2 ports?

    If we have a client server architecture using a socket based connection, should there be 2 serperate sockets? One dedicated to sending and one dedictated to receiving? What happens if both the client and server both send at the same time? How does that get handled? Does one of the messages get dropped? Thanks...

    There are of course reasons you might want to use two sockets.
    For instance security. One socket is encrypted and the other isn't. Or because the server initiates a confirmed port connection back it verifies the IP.
    Or because the main socket is used for control and the second one is used for data. That way the client can tell the server to pause or make other adjustments in the data while the data is still flowing.

  • Client/server vs. Application Server

    Our company has around 30 sites with each one having its own Oracle database server and file server (repository for executables of Forms6i/Reports6i). All the sites have the same applications running, i.e., the same set of programs are replicated to each site. At present we are running the applications in client/server mode (Forms6i/Reports6i runtime is installed on each client machine).
    We are also using some third party modules developed in VB/VC++.
    Now we are looking for the Centralized Solution, i.e., We want to have a Single Database Server available to all the sites all the sites are already linked with Network Leased lines).
    Now we want to know the impact of running centralized file server (located at Corporate Office site) accessible from all the sites (through same client/server mode).
    Will this solution work for us or we should move to 3-tier mode? Please suggest us the best feasible solution which can be implemented as early as possible.
    What I mean to ask in the question above is: if a good intranet connectivity is available among sites, what would be the better approach, client/server or n-tier?
    What actually would we gain by using application server in this context? Does the Data travelling is reduced from Database Server through to the Client Node in 3-tier AS approach? Does this 3-tier approach will reduce the Burden on Leased Lines? Does we gain more network resources available in 3-tier?
    What I think is that in client/server mode, the data is travelled from Database Server to Client Machine, but using Application Server, the Data from Database Server will travel upto Application Server and NOT to the Cleint machine (on browser etc.), hence reducing Network Load.
    Please clarify as your input makes a valuable role in our decision-making.

    Hello,
    I'll take a stab at this one...
    If you have enough network bandwidth, you should be fine funning in client/server mode. I have worked with clients with this same configuration. In addition to having a centralized DB, we have also centralized the forms on a network drive allowing users to access the same files and removing the need for users having to update their files locally. The biggest problem I see with this configuration, as long as you have enough band width, is that your configuration is not supported as 6i has been desupported.
    From my perspective you really don't have any choice but to upgrade your application so that you can be supported. The good news is that for the clients we have worked with upgrades have gone very smoothly. In fact recently we have started to partner with another vendor that has a tool specifically designed to upgrade Oracle Forms and it includes additional features above and beyond what you get from Oracle. This tool has drastically reduced the amount of time to complete upgrades (like going from a 2 year project to just a few weeks).
    I hate to answer this question because it is hard to answer without really getting into the details with you. The good news is once you do have a centralized DB and centralized application maintenance will be significantly easier.
    One last option you might consider that our company has done is to use Citrix. I've never used it for Oracle Forms, but for other client/server applications it has allowed out clients to web enabled their existing applications without changing them at all and also get a boost in performance. I wouldn't recommend this approach to you because what you have should be short term until you get your forms/reports upgraded.
    If you have any specific questions I can try and answer them for you. Good luck and let me know if I can be of any assistance.

  • Publishing .fla project including client - server socket connection

    Hi,
    I have designed with Adobe Flash Professional CS5 a .fla project that integrates a client - server connection.
    After publishing it, I have the following issue:
    - when running the generated .exe file for Windows, then the connection to the server works perfectly
    - but when I am running the published .html file, then nothing is sent to the server.
    I have tried to change the Publish Settings.
    When setting the Local Playback Security in Flash menu to "Access network only" instead of "Access local files only" then the last packet that was send using the .exe file is resent once and that's all (the html client does not receive the response from the server and the next connection attemps generate data transfer).
    I guess I have to change some security settings somewhere but I didn't find which.
    Does anybody have a hint ?
    Thanks.

    Hi again,
    I was finally able to solve the issue.
    I did not get any error message when using firefox, but using iExplorer provided me this error:
    "Local-with-filesystem SWF files are not permitted to use sockets"
    Googling did then allow me to find the solution here:
    http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.htm l
    The local locations on which I store my html page during the development has to be added to the trusted locations in the global security settings.
    Hope it will help some other people.
    Best regards

  • Client-server remote desktop application

    I am developing application of client - server . In this i am getting error
    *java.net.BindException: Address already in use: JVM_Bind
    at client side.*
    can u tell me which type of error is this?

    To Connect to a server port , i have to pass port and ip on which server is running .
    Description of error::
    Client Side : : when client 's lan disables connection breaks and when lan ebanles my client connected with error message
    java.net.BindException: Address already in use: JVM_Bind . so which type of error is this? i searched on net. Is there an error of Port number ? please help me ....
    Jsfgeeks

  • Socket based application - Performance Issues - Suggestions Needed

    Hi All,
    We have an application which basically has been developed using core java. Here is a high level information about the application:
    a) It opens a serversocket which allows clients to connect to it.
    b) For every new client connection, a separate thread is created and this thread deals with requests from clients, processing the data and replying back to clients.
    c) Each socket is polled continuously and sockettimeout is 2 seconds. If there is a timeout, we handle the situation and socket is again read. So basically sockets is read every 2 seconds. If number of timeouts reaches a configurable value, we close the connection and thread is dropped as well.
    d) In production, three instances of this application are running with the help of a cisco load balancer. It is there for last 5 years.
    However there has always been some minor performance isssues and we have sorted them out using different types of garbage collectors, by introducing hardware load balancers, upgrading the code for new Java versions. It is currently running on 1.4.2.
    However there has always been some performance issues and today while googling over internet I came across following on the bea website which says that core java sockets are not as efficients as native API. BEA has implemented its own APIs for weblogic. My queries are:
    a) Are there any better Java Socket/network API (for solairs, I know Java is plateform independenet but there could be lib which also using native libs) which are much more efficient than Core Java.
    b) We are getting the InputStream/OutputStream and creating objects of DataInputStream/DataOutputStream to read the data 'Byte-By-Byte'. Each byte can have different information thats why it is required. Are there any better way of getting info than what we are currently doing.
    c) As I mentioned, we are continously polling the socket for read operation with a timeout value of 2 seconds. What is the better among the following from performance point of view: (1) Frequent read operation with a lesser timeout value or (2) Less Frequent read operations with larger timeout value. (3) Any better idea??
    Please suggest few things or pointers which I could do to improve the performance of the applcations. Many thanks.
    Thanks,Akhil
    From BEA website:-
    "Although the pure-Java implementation of socket reader threads is a reliable and portable method of peer-to-peer communication, it does not provide the best performance for heavy-duty socket usage in a WebLogic Server cluster. With pure-Java socket readers, threads must actively poll all opened sockets to determine if they contain data to read. In other words, socket reader threads are always "busy" polling sockets, even if the sockets have no data to read. This unnecessary overhead can reduce performance."

    My recommendations:
    - Always use a BufferedInputStream and BufferedOutputStream around the socket streams
    - Increase the socket send and receive buffers to at least 32k if you are on a Windows platform where the default is a ridiculous 8k, which hasn't been enough for about 15 years.
    - Your 2-second timeout is far too short. Increase it to at least 10 seconds.
    - Your strategy of counting up to N short timeouts of S seconds each is completely pointless. Change it to one single timeout of N*S seconds. There is nothing to be gained by the complication you have introduced to this.

  • How to set proxy for client-server socket connection?

    Hi,
    I'm using the code found on the following page to create a client (mobile) to server (pc) connection and send a text message.
    http://javafaq.nu/java-example-code-503.html
    This works with mobile operators without proxy, but does nothing when the operator uses a proxy. The question is, exactly how to set the proxy and port values for using that code.
    Any help is greatly appreciated, thanks,

    It's part of the cellular settings, and is usually set up by your 3G provider. You can't choose your own proxy server

  • Large file transfer problems over client/server socket

    Hi,
    I wrote a simple chat problem in which I can send files from client to client. The problem is when I send large files over 101 MB the transfer freezes. I do not even get any error mesages in the console. The files I am sending are of any type (Ex mp3, movies, etc...). I am serializing the data into a "byteArray[packetSize]" and sending the file packet by packet until the whole file has been sent, and reconstructed on the other side. The process works perfectly for files smaller than 101MB, but for some reason freezes after that if the file is larger. I have read many forums and there aren't too many solutions out there. I made sure to use the .reset() method to reset my ObjectOutputStream each time I write to it.
    Here's my file sending code:
    byte[] byteArray = new byte[defaultPacketSize];
    numPacketsRequired = Math.ceil(fileSize / defaultPacketSize);
    try {
    int i = 0;
    reader = new FileInputStream(filePath);
    while (reader.available() > 0) {
    if (reader.available() < defaultPacketSize) {
    byte[] lastPacket = new byte[reader.available()];
    reader.read(lastPacket);
    try {
    if (socket == null || output == null) {
    throw new SocketException("socket does not exist");
    output.writeObject(lastPacket);
    output.reset();
    output.writeObject("DONE");
    output.reset();
    output.close();
    socket.close();
    catch (Exception e) {
    System.out.println("Exception ***: " + e);
    output.close();
    socket.close();
    else {
    reader.read(byteArray);
    try {
    if (socket == null || output == null) {
    throw new SocketException("socket does not exist");
    output.writeObject(byteArray);
    output.reset();
    catch (Exception e) {
    System.out.println("Exception ***: " + e);
    output.close();
    socket.close();
    reader.close();
    catch (Exception e) {
    System.out.println("COULD NOT READ PACKET");
    Here's my file receiving code:
    try {
    // The message from the client
    Object streamInput;
    FileOutputStream writer;
    byte[] packet;
    while (true) {
    streamInput = input.readObject();
    if (streamInput instanceof byte[]) {
    packet = (byte[]) streamInput;
    try {
    writer = new FileOutputStream(outputPath, true);
    writer.write(packet); //Storing the bytes on file
    writer.close();
    catch (Exception e) {
    System.out.println("Exception: " + e);
    else if (streamInput.equals("DONE")) {
    socket.close();
    input.close();
    break;
    catch (Exception e) {
    I'm looking for any way I can possibly send large files from client to client without having it freeze. Are there any better file transfer ways other than socket? I don't really want FTP. I think I want to keep it HTTP.
    Any suggestions would be helpful.Thanks!
    Evan

    I've taken a better look a the code you posted, and
    there is one problem with the receiving code. You
    keep repeatedly opening and closing the
    FileOutputStream. This is not going to be efficient
    as the file will keep needing to be positioned to its
    end.Yes sorry I did change that code so that it leaves the file open until completely done writing. Basically I have a progress bar that records how far along in the writing process the client is, and when the progress bar reaches 100%, meaning the file is complete, the file.close() method is invoked. Sorry about that.
    I also ran some memory tests using the "Runtime.getRuntime().totalMemory()", and "Runtime.getRuntime().freeMemory()" methods. I put these methods inside the loop where I read in the file and send it to the client. here's the output:
    Sender's free memory: 704672
    File reader read 51200 bytes of data.
    767548 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 702968
    File reader read 51200 bytes of data.
    716348 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 701264
    File reader read 51200 bytes of data.
    665148 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 699560
    File reader read 51200 bytes of data.
    613948 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 697856
    File reader read 51200 bytes of data.
    562748 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 696152
    File reader read 51200 bytes of data.
    511548 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 694448
    File reader read 51200 bytes of data.
    460348 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 692744
    File reader read 51200 bytes of data.
    409148 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 691040
    File reader read 51200 bytes of data.
    357948 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 689336
    File reader read 51200 bytes of data.
    306748 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 687632
    File reader read 51200 bytes of data.
    255548 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 685928
    File reader read 51200 bytes of data.
    204348 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 684224
    File reader read 51200 bytes of data.
    153148 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 682520
    File reader read 51200 bytes of data.
    101948 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 680816
    File reader read 51200 bytes of data.
    50748 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 679112
    File reader read 50748 bytes of data.
    0 left to read.
    Creating last packet of size: 50748
    Last packet size after setting it equal to byteArray: 50748
    Here's the memory stats from the receiver:
    Receiver's free memory: 639856
    Receiver's total memory: 2842624
    Receiver's free memory: 638920
    Receiver's total memory: 2842624
    Receiver's free memory: 637984
    Receiver's total memory: 2842624
    Receiver's free memory: 637048
    Receiver's total memory: 2842624
    Receiver's free memory: 636112
    Receiver's total memory: 2842624
    Receiver's free memory: 635176
    Receiver's total memory: 2842624
    Receiver's free memory: 634240
    Receiver's total memory: 2842624
    Receiver's free memory: 633304
    Receiver's total memory: 2842624
    Receiver's free memory: 632368
    Receiver's total memory: 2842624
    Receiver's free memory: 631432
    Receiver's total memory: 2842624
    Receiver's free memory: 630496
    Receiver's total memory: 2842624
    Receiver's free memory: 629560
    Receiver's total memory: 2842624
    Receiver's free memory: 628624
    Receiver's total memory: 2842624
    Receiver's free memory: 627688
    Receiver's total memory: 2842624
    Receiver's free memory: 626752
    Receiver's total memory: 2842624
    Receiver's free memory: 625816
    Receiver's total memory: 2842624
    Receiver's free memory: 624880
    Receiver's total memory: 2842624
    Receiver's free memory: 623944
    Receiver's total memory: 2842624
    Receiver's free memory: 623008
    Receiver's total memory: 2842624
    Receiver's free memory: 622072
    Receiver's total memory: 2842624
    Receiver's free memory: 621136
    Receiver's total memory: 2842624
    Receiver's free memory: 620200
    Receiver's total memory: 2842624
    Receiver's free memory: 619264
    Receiver's total memory: 2842624
    Receiver's free memory: 618328
    Receiver's total memory: 2842624
    Receiver's free memory: 617392
    Receiver's total memory: 2842624
    Receiver's free memory: 616456
    Receiver's total memory: 2842624
    Receiver's free memory: 615520
    Receiver's total memory: 2842624
    Receiver's free memory: 614584
    this is just a sample of both receiver and sender's stats. Everything appears to be fine! Hope this message post isn't too long.
    Thanks!

  • Client Server Socket question!

    Hello all,
    how are ye.
    I would like to ask a question.
    I would be graterful for any suggestions relating to my query.
    i am creating a program that needs to communicate over a network
    it has two parts
    P1) sends request to the other program mainly about account information and
    also updates.
    P2) the second part among other things listens for messages on a port from Program One.
    but also must be able to interface with the user who is using Program Two, the user should be able
    to view account info update delete search etc.
    my problem is how will i get the second program todo both operations do i need
    to create another thread that listens and if i do this. will i be able to
    like add info to a database from this thread.
    Mainly i need suggestion as to how i should implement a scenario like the above.
    I am sorry if i havent spelled out my problem in a clear manner.
    Very grateful for any assistance.
    Thank you all :-)

    http://java.sun.com/developer/onlineTraining/Programming/BasicJava2/socket.html
    That should help you out.

  • Socket Client/Server

    I have an app using the Client/Server socket connections. Only problem is if the server should drop out and then get restarted, how can I detect the event from the client socket connection. At the moment on fail to send data I attempt to re-connect to the server; but it may actually be a diff error.
    Thanks in advance

    while (i > 0) {This loop terminates when the server closes the socket. If the server doesn't close the socket it will block in the read() method. So you'll never get to the next part. So either have the server close the socket or arrange your application protocol so you can tell when you've received a complete reply.

  • ActiveX Bridge Usage in Client-Server architecture

    Hi,
    We developed an application (client-server architecture) based on RMI layer. Now we want to expose client as an ActiveX Control. Assume, server is running on one m/c, client is running on different m/c. Now in other m/c, on VB container my client activex is running. This activex should fetch data from server(through java based client) and should display it.
    We implemented an activex control for client, it is interacting with server. To show server data it should use one user-defined object class. We made this object as public static. But we are not able to use this object on activex side. Even serializing this object and reading it again is also not working.
    If anyone has idea on debugging this issue, please help us.
    Sagar.

    Use the 'NI AlarmEvent Browser' ActiveX control.   Set the machine as the remote station.  Lots of parameters.
    Mike
    Mike Crabtree - Lead Developer
    Destek of Nevada, Inc. / Digital Telemetry Systems, Inc.
    (866) 964-6948 / (760) 247-9512

Maybe you are looking for

  • IPad2 wifi no longer detecting some networks

    Hello, my old iPad 2 is detecting some networks in the house but not others.  I have Uverse Motorola ngv510 and using wireless, it has even an additional Cisco WAP for the wireless uverse receivers.  My old iPad sees the Cisco WAP but not the standar

  • USB720 VZAccess not working with Mac OS 10.6.4

    Hello: I have a USB 720 modem that I have been using on my Intel Macbook Pro with OS 10.5.8. I just bought a Mac Pro tower with OS 10.6.4, downloaded the VZAccess update 7.0.5, installed it and can not connect. When I do it says, "Error Connection fa

  • My itunes told me there was a update to do so i did it now it wont work or sync with my phone!

    i logged into my itunes a few days ago and it told me there was a update so i did it and now it wont open up itunes or sync with my phone!  I've uninstalled itunes and reinstalled it but it's still not working and asks me to reinstall it everytime!

  • Old iPod - converter for Firefire to USB?

    Hey guys, I have an older iPod, one with 5GB of memory and the 6-pin firefire connector on the top. I got a new computer and it doesn't have 6-pin firewire access but has tons of USB ports. Does anybody know of a converter or adaptor that I can put o

  • Best way to set up a private cloud for family

    I wish to set up my private cloud. Is there any Apple device that will help me do so? If not, which are the devices that will be most compatible with Mac, iPhone and an iPad? I don't have a server as yet. I am looking for an Apple device that can act