Saving string  from multiple clients on a server data structue

I have a server which receives updates from multiple clients ( in this example, football scores which are updated periodically by the clients.)
When the server receives the scores it needs to store them and at certain time intervals send the complete list of scores to multiple terminals at various locations.
I am approaching this task in stages...
stage 1.
..create the clients and server ...test the clients can send the data and the server can receive the data and output to screen..
this is completed
stage 2...
a/ on the server side store the received scores in a data structure (ArrayList<String> is what I'm thinking.)
b/ periodically output all scores to the screen (maybe every 30 seconds) and empty the ArrayList..am looking at the Timer class for this part..
stage 3
create the monitors and output scores to monitors periodically..
======================================================
right now I'm at stage 2a ie trying to store the received scores in a data structure.
i've created a method saveScore in the StoreScore class which is called by the StoreScore run method...
The saveScore method creates an ArrayList and adds the score to it...
Question
does every thread create a new instance of storedScores and therefore the scores are stored in a multitude of data structures?
I think the answer is yes and if so then this is not the solution...
What I'm thinking is , as all scores can be outputted to the server screen via System.out.println, is there not a way of saving all these scores in a single data structure?
The code below is the server code..
any advice much appreciated....thank you
/*=============================================================== */
import java.io.*;
import java.net.*;
import java.util.*;
import java.util.concurrent.*;
class ScoresServer1{
final static int portNum = 1234; // any number > 1024
final static int numThreads = 10;
static ExecutorService pool;
public static void main(String[] args){
pool = Executors.newFixedThreadPool(numThreads);
System.out.println("Server running ...");
try{  
ServerSocket servesock = new ServerSocket(portNum);
// for service requests on port
while (true){ 
// wait for a service request on port portNum
Socket socket = servesock.accept();
// submit request to pool
pool.submit(new StoreScore(socket));
}catch(IOException e){}
class StoreScore implements Runnable {
BufferedReader reader;
Socket sock;
public StoreScore(Socket clientSOcket) {
try {
sock = clientSOcket;
InputStreamReader isReader = new InputStreamReader(sock.getInputStream());
reader = new BufferedReader(isReader);
} catch (Exception ex) { ex.printStackTrace(); }
public void run() {
String message;
try {
while ((message = reader.readLine()) != null) {
// System.out.println("latest score: " + message);
saveScore(message);
} catch (Exception ex) { ex.printStackTrace(); }
public void saveScore(String message){
     ArrayList<String> storedScores = new ArrayList<String>();
     storedScores.add(message);
     Iterator<String> t = storedScores.iterator();
          while(t.hasNext()){
               String s = t.next();
               System.out.println(s);
}

does every thread create a new instance of storedScores and therefore the scores are stored in a multitude of data structures?
I think the answer is yes and if so then this is not the solution...The answer is yes. However, threads can share data, if they were properly synchronized. You should read the threading tutorial before creating a lot of hard to debug mistakes.
[http://java.sun.com/docs/books/tutorial/essential/concurrency/]

Similar Messages

  • Accessing the same stateful session bean from multiple clients in a clustered environment

    I am trying to access the same stateful session bean from multiple
              clients. I also want this bean to have failover support so we want to
              deploy it in a cluster. The following description is how we have tried
              to solve this problem, but it does not seem to be working. Any
              insight would be greatly appreciated!
              I have set up a cluster of three servers. I deployed a stateful
              session bean with in memory replication across the cluster. A client
              obtains a reference to an instance of one of these beans to handle a
              request. Subsequent requests will have to use the same bean and could
              come from various clients. So after using the bean the first client
              stores the handle to the bean (actually the replica aware stub) to be
              used by other clients to be able to obtain the bean. When another
              client retrieves the handle gets the replica aware stub and makes a
              call to the bean the request seems to unpredictably go to any of the
              three servers rather than the primary server hosting that bean. If the
              call goes to the primary server everything seems to work fine the
              session data is available and it gets backed up on the secondary
              server. If it happens to go to the secondary server a bean that has
              the correct session data services the request but gives the error
              <Failed to update the secondary copy of a stateful session bean from
              home:ejb20-statefulSession-TraderHome>. Then any subsequent requests
              to the primary server will not reflect changes made on the secondary
              and vice versa. If the request happens to go to the third server that
              is not hosting an instance of that bean then the client receives an
              error that the bean was not available. From my understanding I thought
              the replica aware stub would know which server is the primary host for
              that bean and send the request there.
              Thanks in advance,
              Justin
              

              If 'allow-concurrent-call' does exactly what you need, then you don't have a problem,
              do you?
              Except of course if you switch ejb containers. Oh well.
              Mike
              "FBenvadi" <[email protected]> wrote:
              >I've got the same problem.
              >I understand from you that concurrent access to a stateful session bean
              >is
              >not allowed but there is a
              >token is weblogic-ejb-jar.xml that is called 'allow-concurrent-call'
              >that
              >does exactly what I need.
              >What you mean 'you'll get a surprise when you go to production' ?
              >I need to understand becouse I can still change the design.
              >Thanks Francesco
              >[email protected]
              >
              >"Mike Reiche" <[email protected]> wrote in message
              >news:[email protected]...
              >>
              >> Get the fix immediately from BEA and test it. It would be a shame to
              >wait
              >until
              >> December only to get a fix - that doesn't work.
              >>
              >> As for stateful session bean use - just remember that concurrent access
              >to
              >a stateful
              >> session bean is not allowed. Things will work fine until you go to
              >production
              >> and encounter some real load - then you will get a surprise.
              >>
              >> Mike
              >>
              >> [email protected] (Justin Meyer) wrote:
              >> >I just heard back from WebLogic Tech Support and they have confirmed
              >> >that this is a bug. Here is their reply:
              >> >
              >> >There is some problem in failover of stateful session beans when its
              >> >run from a java client.However, it is fixed now.
              >> >
              >> >The fix will be in SP2 which will be out by december.
              >> >
              >> >
              >> >Mike,
              >> >Thanks for your reply. I do infact believe we are correctly using
              >a
              >> >stateful session bean however it may have been misleading from my
              >> >description of the problem. We are not accessing the bean
              >> >concurrently from 2 different clients. The second client will only
              >> >come into play if the first client fails. In this case we want to
              >be
              >> >able to reacquire the handle to our stateful session bean and call
              >it
              >> >from the secondary client.
              >> >
              >> >
              >> >Justin
              >> >
              >> >"Mike Reiche" <[email protected]> wrote in message
              >news:<[email protected]>...
              >> >> You should be using an entity bean, not a stateful session bean
              >for
              >> >this application.
              >> >>
              >> >> A stateful session bean is intended to be keep state (stateful)
              >for
              >> >the duration
              >> >> of a client's session (session).
              >> >>
              >> >> It is not meant to be shared by different clients - in fact, if
              >you
              >> >attempt to
              >> >> access the same stateful session bean concurrently - it will throw
              >> >an exception.
              >> >>
              >> >> We did your little trick (storing/retrieving handle) with a stateful
              >> >session bean
              >> >> on WLS 5.1 - and it did work properly - not as you describe. Our
              >sfsb's
              >> >were not
              >> >> replicated as yours are.
              >> >>
              >> >> Mike
              >> >>
              >> >> [email protected] (Justin Meyer) wrote:
              >> >> >I am trying to access the same stateful session bean from multiple
              >> >> >clients. I also want this bean to have failover support so we want
              >> >to
              >> >> >deploy it in a cluster. The following description is how we have
              >tried
              >> >> >to solve this problem, but it does not seem to be working. Any
              >> >> >insight would be greatly appreciated!
              >> >> >
              >> >> >I have set up a cluster of three servers. I deployed a stateful
              >> >> >session bean with in memory replication across the cluster. A client
              >> >> >obtains a reference to an instance of one of these beans to handle
              >> >a
              >> >> >request. Subsequent requests will have to use the same bean and
              >could
              >> >> >come from various clients. So after using the bean the first client
              >> >> >stores the handle to the bean (actually the replica aware stub)
              >to
              >> >be
              >> >> >used by other clients to be able to obtain the bean. When another
              >> >> >client retrieves the handle gets the replica aware stub and makes
              >> >a
              >> >> >call to the bean the request seems to unpredictably go to any of
              >the
              >> >> >three servers rather than the primary server hosting that bean.
              >If
              >> >the
              >> >> >call goes to the primary server everything seems to work fine the
              >> >> >session data is available and it gets backed up on the secondary
              >> >> >server. If it happens to go to the secondary server a bean that
              >has
              >> >> >the correct session data services the request but gives the error
              >> >> ><Failed to update the secondary copy of a stateful session bean
              >from
              >> >> >home:ejb20-statefulSession-TraderHome>. Then any subsequent requests
              >> >> >to the primary server will not reflect changes made on the secondary
              >> >> >and vice versa. If the request happens to go to the third server
              >that
              >> >> >is not hosting an instance of that bean then the client receives
              >an
              >> >> >error that the bean was not available. From my understanding I
              >thought
              >> >> >the replica aware stub would know which server is the primary host
              >> >for
              >> >> >that bean and send the request there.
              >> >> >
              >> >> >Thanks in advance,
              >> >> >Justin
              >>
              >
              >
              

  • 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

  • Uploading Multiple Files from web client to web server

    Am using a Digitally signed applet to pickup files from a specific directory and only to pickup those of a specific type. Applet is called by a HTML converted page and uses the JAVA 1.3.1 plug-in. Client side is ok, but the server side does not work - cannot see how to drop the files down onto the web server.
    code
    URL url = null ;
    FileInputStream filReader = null ;
    DataOutputStream dosOutfile = null ;
    HttpURLConnection httpUrlConn = null ;
    int bytes = 0 ;
    //read local file on client's hd with signed applet
    try
    filReader = new FileInputStream( new File( fromFile ) );
    catch ( java.io.FileNotFoundException eNotFound )
    DisplayStatus ( fromFile + " Not found");
    eNotFound.printStackTrace();
    // start setup to server-side copy of in file
    try
    url = new URL ( toFile ) ;
    catch ( java.net.MalformedURLException eMalFormedUrl )
    DisplayStatus ( url + " url mal formed");
    eMalFormedUrl.printStackTrace();
    // create a HttpUrl connection for POSTING
    try
    httpUrlConn = (HttpURLConnection) url.openConnection(); // do not remove this casting, as needed
    catch ( java.io.IOException eIoException )
    DisplayStatus ( url + " IO not possible");
    eIoException.printStackTrace();
    // set preferences
    httpUrlConn.setDoInput(true); // default value, but best make sure
    httpUrlConn.setDoOutput(true); // default value, but best make sure
    httpUrlConn.setUseCaches(false); // enable write straight through
    try
    httpUrlConn.setRequestMethod("POST") ;
    // httpUrlConn.setRequestMethod("PUT") ;
    } catch ( java.net.ProtocolException eProtEx )
    DisplayStatus ( "Protocol Exception on setting up POST") ;
    eProtEx.printStackTrace();
    httpUrlConn.setRequestProperty("Content-Type", "multipart/form-data");
    // permissions?
    try
    java.security.Permission permission = httpUrlConn.getPermission() ;
    if ( iDebug == true )
    DisplayStatus ("Permission = " + permission.toString() ) ;
    DisplayStatus ( "Actions = " + permission.getActions() ) ;
    DisplayStatus ( "Name = " + permission.getName() ) ;
    catch ( java.io.IOException eUrlIOConnException )
    DisplayStatus ( "httpUrl " + httpUrlConn + " IO not possible");
    DisplayStatus ( eUrlIOConnException.toString() ) ;
    eUrlIOConnException.printStackTrace();
    // connect
    try
    this.VerifyHttpResponseCode ( httpUrlConn.getResponseCode() ) ;
    DisplayStatus ("About to connect") ;
    httpUrlConn.connect() ;
    DisplayStatus ("Connected") ;
    if ( iDebug == true )
    DisplayStatus ("Connected Content Encoding = " + httpUrlConn.getContentEncoding() ) ;
    DisplayStatus ("Connected Content Length = " + httpUrlConn.getContentLength() ) ;
    DisplayStatus ("Connected Content Type = " + httpUrlConn.getContentType() ) ;
    DisplayStatus ("Connected default allow user interaction = " + httpUrlConn.getDefaultAllowUserInteraction() ) ;
    DisplayStatus ("Connected File Map = " + httpUrlConn.getFileNameMap() ) ;
    DisplayStatus ("Connected request method = " + httpUrlConn.getRequestMethod() ) ;
    DisplayStatus ("Connected response code = " + httpUrlConn.getResponseCode() ) ;
    DisplayStatus ("Connected response message = " + httpUrlConn.getResponseMessage() ) ;
    DisplayStatus ("Connected = " + httpUrlConn.getURL() ) ;
    } // end of debug print out status
    catch ( java.net.ConnectException eConnEx )
    this.DisplayStatus ( "Connection error - no server listening or incorrect port " ) ;
    this.DisplayStatus ( "Connection error - http = " + httpUrlConn) ;
    eConnEx.printStackTrace();
    catch ( java.io.IOException eUrlConnException )
    DisplayStatus ( "url " + url + " connection not possible");
    DisplayStatus ( eUrlConnException.toString() ) ;
    eUrlConnException.printStackTrace();
    // create file on server
    try
    dosOutfile = new DataOutputStream ( new BufferedOutputStream( httpUrlConn.getOutputStream () ) ) ;
    catch ( java.io.IOException eNewFileIO )
    DisplayStatus ("Unable to create file on server / buffer output stream " + toFile ) ;
    // copy files char by char for the moment, till testing complete
    try
    bytes = filReader.read();
    while(bytes != -1)
    dosOutfile.writeByte(bytes);
    bytes = filReader.read();
    // close both files
    dosOutfile.flush ();
    dosOutfile.close ();
    filReader.close();
    catch (java.io.IOException eCpyIo )
    DisplayStatus ("Error copying files") ;
    connection of the HttpURLConnection
    gives 'Fobbiden' response for 'PUT'
    and
    'method not allowed' for 'POST'
    trying to create the file on the server than causes IOException at the create DataStream line
    What am I doing wrong?
    Is this philosphy correct?
    Should the HttpURLConnection be to the target folder
    and then create the file in it?

    hello,
    first here is my interpretation of your prob.
    You have a client.From this client you are trying to upload files onto a server.
    Finding the files and reading them on the client side is not a prob. The prob is storing them on the server side.
    right?
    If the above stated prob is right, here is a solution.
    1. You have to first inform the server that you are sending the file. Unless you do so the server will not understand when you have started sending the file.
    So, initially, the applet which you have written need to communicate with a servlet on the server side.
    This can be done using reqs.. .get or post.In the req itself you can even send the name of the folder wherein you want to store the file you are going to transfer later on.
    Next, after receiving the folder name, the servlet can now understand that next file data is going to be received.
    The applet now sends the file which is received by the servlet and stored appropriately.
    You need to explicitly write a servlet to receive a data into the file and then store the file into appropriate folder.
    for any further probs email me at [email protected]

  • String Tokenizer/ Multiple Client app.

    Hi all,
    I am developing a multi user pure Java App.
    My situation:
    1. client request server for connection. > server accepted
    2. client send his details (name*|*group*|*ID)
    3. server receive the string, update itself and other client accordingly
    My problem:
    1. to send client detail (name*|*group*|*ID), String tokenizer is being used? and *|" serve as delimeter ?
    2. how do create an statement that count the total user connected to server or leave the server
    3. and how to assign an identifier to each connected client, thus server can perform differ operation based on the identifier.
    Thanks Ya, if someone can provide me some suggestions
    Happy Life

    To answer your problems directly
    1. Client Info: Yes, read all information from the client using an inputstream. convert that into a String, and use StringTokenizer (str, "|") to parse the information
    2. # of clients: After a client has connected to your server, they will be automatically shunted to another port that that user alone communicates on. You should set up a new thread to listen to data being sent on that port. Keep these listeners in an array/vector/arraylist and use getSize()
    3. The identifier could just be their port #

  • How to upload file from a client machine to server machine

    hei evryone!
    can anyone pls help me on how i can upload file from a client machine to another machine (or server). using jsp.Then later on, i can also retrieve the names of these files to place it as values for option tag in an html form.I have a seperate screen for uploading the file and the screen for displaying all the files that were uploaded on the server...
    any sample code/ ideas would be much appreciated.Thx!!!!

    hei evryone!
    can anyone pls help me on how i can upload file from a client machine to another machine (or server). using jsp.Then later on, i can also retrieve the names of these files to place it as values for option tag in an html form.I have a seperate screen for uploading the file and the screen for displaying all the files that were uploaded on the server...
    any sample code/ ideas would be much appreciated.Thx!!!!

  • Upgrade from Tiger (client) to Leopard Server

    Hi all,
    I have a client with an existing dual G5 box they have running Tiger. They use it as a file share primarily but want the extra functionality of the server OS (viz Leopard server). Is there an upgrade path from OS 10.4 client to 10.5 server or is it a backup/format/restore process for the data? Thanks in advance for any replies.
    Cheers
    Si

    Well, I can offer my opinion on best practice, other opinions may vary.
    In the past, you have been able to upgrade client versions to server. I believe this creates a new System folder. In any event, the client OS and the server OS are not the same thing with different features, There are some functional differences. So if you plan to use the Mac as a client and a server, I'd really recommend against that. I'd also recommend erasing the HD and installing the Server OS on a clean HD.
    Jeff

  • Purpose of Multiple Clients in Development Server

    can anybody tell me the advantages and
    disadvantages of having multiple clients in a
    development server?

    I don't think there is disadvantage when we have multiple clients for development system
    DEV  SAP system may have multiple clients..
    Main pupose : Changes can be client dependent or client independent
                          Client-independent effects some clients.
                          Client-dependent effects all clients.
    Let me say one example : Dev system has two clients
    100 - Here we can write the code
    200 - Testing will be here ( customizing will done here)
    http://help.sap.com/saphelp_nw04/helpdata/en/8d/933d3c3a926614e10000000a11402f/frameset.htm
    http://www.sap-img.com/general/what-is-sap--landscape.htm
    http://help.sap.com/saphelp_nw2004s/helpdata/en/96/8a99386185c064e10000009b38f8cf/content.htm
    Thanks
    Seshu

  • Business content load data from multiple clients

    Hi Experts,
    we are implementing Business Content for FI-GL. On the system there is already the content enabled and the extraction from one client (let's say Client200). We now have to extract data from Client300. How can we do that?
    Thanks in advance,
    Costi

    You should create another Source system on the other client and copy the transfer rules from the extractor mapping them on the other source system . After this you can create the infopackage and load data
    hope it helps

  • Using word/excel from java (client or weblogic server)

    Hi everybody,
    i want to use excel / word functionality from java in two different variants:
    -> serverside
    -> clientside
    I tried the weblogic.comc and i got serveral classes but in the remote-package i got only a utitlity-class.
    My knowlege about COM is rather bad.
    Does anybody did this bevor and
    -> can say me, if it is correct, that i only got a utility-class (so how will i use it from the client ?!)
    -> has a example for using Excel / Word from Java in bea weblogic
    -> has a example for using Excel / Word directly in a client (not via rmi)
    Thanks
    Ciao
    Sven

    Sven, This is a really bad idea. Why don't you tell me
    what your trying to do and I wil surely give you a better alternative
    JRadecki
    "Sven Roesner" <[email protected]> wrote:
    >
    Hi everybody,
    i want to use excel / word functionality from java in two different variants:
    -> serverside
    -> clientside
    I tried the weblogic.comc and i got serveral classes but in the remote-package i got only a utitlity-class.
    My knowlege about COM is rather bad.
    Does anybody did this bevor and
    -> can say me, if it is correct, that i only got a utility-class (so how will i use it from the client ?!)
    -> has a example for using Excel / Word from Java in bea weblogic
    -> has a example for using Excel / Word directly in a client (not via rmi)
    Thanks
    Ciao
    Sven

  • LOGIN FAILED for POP3 from multiple clients

    Hi - I recently moved (changed service address). Since then, I have not been able to POP or IMAP my mail. It was working perfectly for many years before then. Many calls and chats with tech support have resulted in promises for Comcast to have someone call me - but they never call. Basicaly I'm very stuck.  I can log into my comcast webmail perfectly and everything is great there. I've tried every combination listed on this page: http://customer.xfinity.com/help-and-support/internet/email-client-programs-with-xfinity-email/ And this one: http://customer.xfinity.com/help-and-support/internet/configuring-comcast-email-mac I've tried it on multiple Macs, iPhones, you name it. Very carefully make sure username, password, SSL enabled, ports, etc. etc. are correct. No combination ever works.  Related - perhaps? When I moved my email was completely disabled. Tech support said that happens when you change addresses. Pretty darn strange as email is virtual and shouldn't be related, but okay. Tech support re-enabled it and then webmail worked, but still no POP or IMAP.  Comcast Tech Support really doesn't have a clue here how to even understand the issue, let alone fix it. I'm kind of thinking somewhere in there they need to enable the account to allow POP3 access or something, but I can never get to anyone that knows what they are doing.  Ideas?? Thanks for any help or ideas anyone has. 

    Has someone left the company or has an account of some nature been dropped/replaced?
    Please click "Mark As Answer" if my post helped. Tony C.
    Hi Tony,
    Srry but No.  We just installed the monthly updates.
    I went back and found I had missed removing a patch.  I missed the rollup for Windows Server 2003:
    Event Type: Information
    Event Source: NtServicePack
    Event Category: None
    Event ID: 4382
    Date:  3/12/2015
    Time:  12:26:04 PM
    User:  NETTEST\admin
    Computer: DATA1
    Description:
    Windows Server 2003 KB954920 was removed from your computer, and the previous Windows Server 2003 configuration was restored.
    After I removed that is still didn't work but after about five minutes it started working.
    I guess I ned to report that to MS after I research what might be changed to make the patch work.
    Every time I get stuck and ask for help it seems to be just before I stumble on the solution.
    Thanks for replying.
    Well - maybe this will help someone else.
    Thanks again for replying Tony
    ¯\_(ツ)_/¯

  • Accepting connection from multiple client

    Hi, i try to open a port on the server and allows others client to connect to this port and sent in data. It works well when it's 1 server to 1 client relationship. But when i turn on 1 server to many client connection where all the client will connect at the same time... none of the client data were capture in the server. Here is my code :
    Server code:
    static class Listener extends Thread
              public void run()
                   ServerSocket svrSocket;
                   Socket soc;
                   try
                        svrSocket = new ServerSocket(20);
                        System.out.println("---------------------------------------");
                        soc = svrSocket.accept();
                        System.out.println("---------------------------------------");
                        BufferedReader in = new BufferedReader(new InputStreamReader(soc.getInputStream()));
                        String strTest;
                        while((strTest = in.readLine()) != null)
                             System.out.println("SEE THIS !!!!!!!!!!!!! " + strTest);
                   catch(Exception e)
                        e.printStackTrace();
    Client code:
    socClient = new Socket("10.1.8.101", 4444);
    outPrintWriter = new PrintWriter(socClient.getOutputStream(), true);
    outPrintWriter.println(strWrite);
    Can anyone help me??? IT"S URGENT....
    THANKS

    Your code will only handle one connection at a time currently. To handle more connections it needs to be reorganized, see below. Also, you may be having a problem with binding port 20 in your server and trying to connect to port 4444 in your client. These ports obviously have to be the same or its never going to work at all! :-)
    Without getting into thread pools and stuff, this is a sample of how you might want to organize your server.
    import java.net.*;
    import java.io.*;
    import java.util.*;
    public class SocServ implements Runnable {
        // running flag set to false to stop server.
        public static boolean isRunning=true;
        // set of servicing threads, if needed.
        private static Set servicers = new HashSet();
        public void run() {
            ServerSocket svrSocket;
            Socket soc;
            Thread t;
            // open the server socket, error if port is in use, etc.
         try {
                svrSocket = new ServerSocket(4096);
                // accept connections, and start new SocServicer threads.
                while (SocServ.isRunning) {
                    soc = svrSocket.accept();
                    t = new Thread(new SocServicer(soc));
              SocServ.servicers.add(t);
                    t.start();
                // server finished, close socket
                svrSocket.close();
            } catch (IOException e) { e.printStackTrace(); }
    import java.net.*;
    public class SocServicer implements Runnable {
         // socket connection being serviced...
         Socket s;
         public SocServicer(Socket soc) { s=soc; }
         public void run() {
              if (s==null) { return; } // for sanity
              * Do all the interaction with each socket here.
    }The idea is to run one thread that listens for connections and then spawn new threads to process each connection. This way one connection does not have to wait for the previous one to finish. For a serious application you will probably want to do some more careful management of the SocServicer threads [because each thread eats up memory & resources].

  • Help: question on send XML file from java client to java server

    Hi, I am now to Java, and now I am going to set up a simple network in the lab.
    I have created a random array of data and transferred to XML file on my client. Now, I would like to send it to the server. I am wondering how I can put the XML file into my client, and do I need any parser to let the server show what random date it has received?
    Anybody can give me any idea or some basic code? Thank you.
    Now, I am referring the KnockKnock example in Java online tutorial. But, not clear how to deal with the XML File.
    Fengyuan

    There are several ways you can achieve this: one could be that you transfer data over HTTP, using Servlets for instance. Have a Servlet listening on the Server with content type 'text/xml', POST the XML data to the server and have the Servlet to receive the data and re-compose the XML file. This can be achieved with different libraries:
    1) JAXB --> this is good because is the JDK standard, also for web services
    2) Castor (http://www.castor.org/)

  • JAX-WS: How to choose from multiple client certificates on the fly?

    I have a webapp that is calling a web service supplied by a vendor. The vendor requires the use of client certificates for authentication, and I have successfully called their service using the PKCS#12 keystore they gave us with JAX-WS 2.2 using code like this:
        System.setProperty("javax.net.ssl.keyStore", "myKeyStore.p12");<br />
        System.setProperty("javax.net.ssl.keyStoreType", "pkcs12");<br />
        System.setProperty("javax.net.ssl.keyStorePassword", "password");The problem is, my webapp will be supporting multiple business units, and the vendor differentiates between our business units by issuing separate certificates for each. So I'm in a quandary: I have four PKCS#12 files, one per business unit, and my webapp will need to decide which one to use at runtime. Moreover, this webapp could be heavily used by many simultaneous users, and thus more than one of the certs may need to be used at the same time. Hence whatever the solution is, it will need to be thread safe.
    I was able to combine all four certificates into a single JKS keystore using the JDK 1.6 "keytool -importkeystore" operation with each of my four PKCS#12 certs, so I now have all four in a single JKS keystore. The above code then becomes this:
        System.setProperty("javax.net.ssl.keyStore", "myKeyStore.jks");<br />
        System.setProperty("javax.net.ssl.keyStoreType", "jks");<br />
        System.setProperty("javax.net.ssl.keyStorePassword", "password");So my challenge now is to programatically select between the four possible certs when calling the vendor's web service. How do I do that with JAX-WS RI 2.2?
    Thanks,
    Bill

    Just to close the loop on this (and for the next person trying to figure out how to do it), I was able to [extend X509KeyManager as described in Alexandre Saudate's blog|http://alesaudate.com/2010/08/09/how-to-dynamically-select-a-certificate-alias-when-invoking-web-services/] . I was then able to set the com.sun.xml.ws.developer.JAXWSProperties.SSL_SOCKET_FACTORY on my JAX-WS request context to use my custom SSLSocketFactory, and it works like a charm!
    Thanks,
    Bill

  • How to handle the master data when we are loading the from multiple clients

    Hi,
    We are loading HR data from two different clients 101 and 102 of same source system.
    Here we are facing the problem with msater data maintenance for employee in BW, whose employee numbers are same.
    For example client 101 employee range is 10001 to 10100.
                      In client 102 also same employee range.Then how to handle the above scenario
    Is there any solutions apart from compounding of infoobjets with logical system.
    Thanks in advance for your sugessions.
    Thanks.
    Maria.

    Hi ,
    you  can create copy of 0EMPLOYEE Object.
    Load one client master data to the copied object.
    Example:
    1. Create ZEMPLOYEE copy of 0EMPLOYEE.
    2. create the transformation or rules
    3.  You have to follow same for remaining objects
    regards,
    HREDDY

Maybe you are looking for

  • Error while migrating BLOB data

    Hi , I am migrating the data from oracle to oracle and both soruce and target tables have BLOB type field. I am getting error when I am executing the interface with these blob fields. But My interface is successfull if I am not maaping this blob file

  • Two nvidia cards for triplehead setup

    hello everyone^^ i posted in the german arch-forum but nobody was able to help. I already have an agp nvidia 7600gs installed. additionally i want to install a pci nvidia fx5200. both cards use different driver packages. are there any known problems

  • UTL_FILE  File Naming Problem

    Hi, I am using the UTL_FILE package to write into a file. I want to name the output file as "file1yyyymmddhh.psc". In the syntax of UTL_FILE.FOPEN if I try to append the file name with sysdate then error comes. Also if i use the following: select 're

  • 980 songs missing out of 5567 aft upgrade to 8.2.1.6

    This is frustrating. songs are in the iTunes Music folder. Only way i see is to add all files all over again manually. Somgs missing are random over all albums. I noticed this when syncing my nano and it came up with a warning that many songs could n

  • Changed from Version 4.0 to 7.0

    Hello all I hope you can help me to fix a problem. I was running PSE Version 4.0 on XP, then bought a new computer which runs Vista. Version 4.0 isn't running well. I can import photos und create photoshows. But I can't import any audio in my photosh