How to get Time from Different Work Station on the Network

Hi,
How do I get time from different work station on the network using its ip:port etc.
Lets say, my main server-side Java application is running on a work station 123.12.123.1:1527,
the client-side applications are accessing it using above IP.
what I wanna do is, use the time of 123.12.123.1 machine throughout the application, not client local time.
Appreciated..

Ok, this network service on IP:Port is working for me, I hope this is the best way of doing it.
In server application, I have this
package RenameItToYourOwnPackage;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.text.SimpleDateFormat;
public class ServerSocketExample implements Runnable {
    private ServerSocket server;
    private int port = 7777;
    Socket socket;
    public void run() {
        try {
            System.out.println("Waiting for client message");
            server = new ServerSocket(port);
            while (true) {
                socket = server.accept();
                // Read a message sent by client application
                ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
                String clientMessage = (String) ois.readObject();
                System.out.println("Message sent by client: " + clientMessage);
                // send current datetime to client
                ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
                oos.writeObject(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new java.util.Date()));
                ois.close();
                oos.close();
                socket.close();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
}In the client application I have
package RenameItToYourOwnPackage;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
public class ClientSocketExample {
    static String dateTimeString;
    public ClientSocketExample() {
    public static String getServerDateString() {
        try {
            // Create a connection to the server socket on the server application
            InetAddress host = InetAddress.getByName("127.0.0.1");
            Socket socket = new Socket(host.getHostName(), 7777);
            // Send a message to the server application
             ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
             oos.writeObject("Send me today's timestamp as string");
            // Read the response by server application
            ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
            dateTimeString = (String) ois.readObject();
            //System.out.println("Message sent by server: " + message);
            ois.close();
            oos.close();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        return dateTimeString;
}And I run the service on the server-side with
        new Thread(new ServerSocketExample()).start();On the client-side I receive the date with
        System.out.println("DateTime on Server : " + ClientSocketExample.getServerDateString());Edited by: nkamir on Sep 13, 2010 2:53 PM

Similar Messages

  • How to get time from Date

    I have a Column that is defined as "DATE".it also Contains Time.........
    I want to Get the Time only....so when i am using this
    to_date(var_date,'hh12:mi:ss PM'),it is giving me date also and when i am using this
    to_char(var_date,'hh12:mi:ss PM') then it is giving me all values similar to one of the top values in Column....
    Then i Used EXTRACT function as
    Select EXTRACT(HOUR FROM VAR_DATE).......
    THEN IT THRWOING ERROR.......INVALID EXTRACT FIELD FOR EXTRACT SOURCE........
    pLZ HELP HOW TO GET TIME...................................ONLY WITH AM AND PM......
    Thanks in Advance

    Hi,
    to_char function should give the result as expected.
    SQL> select to_char(sysdate, 'hh12:mi:ss PM') from dual ;
    TO_CHAR(SYS
    11:39:16 AM
    SQL> select to_char(sysdate, 'hh12:mi:ss AM') from dual ;
    TO_CHAR(SYS
    11:39:32 AM
    SQL> select to_char(sysdate,'hh:mi:ss') from dual ;
    TO_CHAR(
    11:40:04
    SQL> select to_char(sysdate,'hh:mi:ss am') from dual ;
    TO_CHAR(SYS
    11:40:18 am
    SQL> select to_char(sysdate,'hh:mi:ss pm') from dual ;
    TO_CHAR(SYS
    11:40:31 am
    Thanks,
    Siva

  • How to get data from  different SEGMENTs

    Hi;
    My requirement is to first of all retrieve the data from different segments in run time.
    I mean, i have to execute t/code WE19 and the idoc will be given after that an user exit would called where i have to retrieve the data from different segments and then it would store in an internal table for further calculation.
    Can you all please guide me how to retrieve the data via ABAP code in runtime so that it can store in an internal table.
    Regards
    Shashi

    write code lke this ..
    form post_idoc tables idoc_data structure edidd
                                    idoc_status structure bdidocstat .
    loop at idoc_data .
      case idoc_data-segnam .
        when 'zsegment1'.
           move idoc_data-sdata to wa_zsegment1 .
        when 'zsegment2'.
          move idoc_data-sdata to wa_zsegment2 .
       when 'zsegmentn'.
          move idoc_data-sdata to wa_zsegmentn.
      endcase .
    endloop.
    After this write code to move data to int table from work area .
    endform .
    Hope this helps u....

  • How to get listitems from different lists using Js

    Hi,
    I want to search my web for all the lists that contains a certain checkbox column (get it by name).
    Once I have this list, I want to iterate through all of them and get the list items with this column checked.
    I got the lists, but when I tried to get the fields - I got an error - the system doesn't recognizes the fields.
    To be more specific - in the code I've posted below in method onGetFieldsSuccess I'm getting an error in the first line, as I can't retrieve the enumerator.
    In the MSDN I saw how to retrieve list's fields, but there it was a specific list. Is there a way to get the lists who have a specific field?
    Any help will be appreciated
    <script> 
    ExecuteOrDelayUntilScriptLoaded(showFavorites, "sp.js"); 
    var ctx;
    var lists;
    function showFavorites()
         ctx = new SP.ClientContext.get_current();
         var web = ctx.get_site().openWeb("/legal");
         ctx.load(web);
         lists = ctx.get_site().openWeb("/legal").get_lists();
         ctx.load(lists);
         ctx.executeQueryAsync(Function.createDelegate(this, this.onGetListSuccess), Function.createDelegate(this, this.onFail));
    var list;
    var fields;
    function onGetListSuccess(sender, args) {
              var listEnumerator = lists.getEnumerator();
              while (listEnumerator.moveNext()) {
                   list = listEnumerator.get_current();
                   ctx.load(list);
                   fields = list.get_fields();
                    ctx.load(fields , 'Include(Title)');
                   ctx.executeQueryAsync(Function.createDelegate(this, this.onGetFieldsSuccess), Function.createDelegate(this, this.onFail));
    function onGetFieldsSuccess(sender, args)
          var fieldEnumerator = fields.getEnumerator();
        while (fieldEnumerator.moveNext()) {
            var field = fieldEnumerator.get_current();
            var name = field.get_staticName();
            if (name == "MyFavorite") {
                alert(list.get_title()); 
                break;
    function onFail(sender, args) {
        console.log(args.get_message());
    </script>​​​​​​​​​​​​​​​​​​​​​​​​​

    Thanks a lot Thriggle,
    I've used your advise, and other then some syntax problems (as you predicted :) everything worked just fine!
    (I had to add another executeQueryAsync to get the listItems files - but that wasn't a problem).
    The only issue that I have is that it takes FOREVER to load, and once it does load - it returns duplicates of the same results (sometimes 3, sometime up to 10).
    I only have 13 tables with about 50 list items in each table, and from that only 6 tables have the specified field - so it shouldn't have taken THAT long (sometimes I see the results after 45 seconds after the page finished loading).
    should I have used a new client context for each query? or is there a place where I'm getting unnecessary loops (I've made sure that I have only 1 list item that matches the 
    I'm resending the complete code. maybe there's something I've missed here.
    <cfheader name="X-XSS-Protection" value="0"></cfheader>​​​​​ ​​​<script>
    ExecuteOrDelayUntilScriptLoaded(showFavorites, "sp.js"); 
    function showFavorites()
         var displayTable = document.getElementById("myFavoritesTable");
         for(var i = displayTable.rows.length - 1; i > 0; i--)
                displayTable.deleteRow(i);
       var fieldToLookFor = "MyFavorite";
         var ctx = new SP.ClientContext.get_current();
         var web = ctx.get_site().openWeb("/legal");
         var lists = web.get_lists();
         ctx.load(web);
         ctx.load(lists, 'Include(Title,Fields)');
         ctx.executeQueryAsync(Function.createDelegate(this, function(){
         var matchingLists = [];
         var listEnum = lists.getEnumerator();
         while(listEnum.moveNext()){
              var currList = listEnum.get_current();
              var containsField = false;
              var fields = currList.get_fields();
              var fieldEnum = fields.getEnumerator();
              while(fieldEnum.moveNext()){
                   if(fieldEnum.get_current().get_staticName() == fieldToLookFor){ containsField = true; break;}
              if(containsField){
                  matchingLists.push(currList.get_title());            
         //alert(matchingLists);
         var i = 0;
         while(i < matchingLists.length){
              var list = lists.getByTitle(matchingLists[i]);
              i++;
              var camlQuery = new SP.CamlQuery();
              var camlString = '<View><Query><FieldRef Name=\'' + fieldToLookFor + '\' /><Value Type=\'Integer\'>1</Value></Query></View>';
              camlQuery.set_viewXml(camlString);
              var items = list.getItems(camlQuery);
              ctx.load(items);
              ctx.executeQueryAsync(Function.createDelegate(this,function(){
                   var itemEnum = items.getEnumerator();
                   while(itemEnum.moveNext()){
                        var item = itemEnum.get_current();
                        var file = item.get_file();
                        ctx.load(file);
                        ctx.executeQueryAsync(Function.createDelegate(this,function(){
                        var table = document.getElementById("myFavoritesTable");
    // Create an empty <tr> element and add it to the 1st position of the table:
    var row = table.insertRow(-1);
    // Insert new cells (<td> elements) at the 1st and 2nd position of the "new" <tr> element:
    var cell1 = row.insertCell(0);
    var cell2 = row.insertCell(1);
    var cell3 = row.insertCell(2);
    var cell4 = row.insertCell(3);
    cell1.innerHTML = "XX";
    cell2.innerHTML = item.get_id();
    cell3.innerHTML = "<a href='" + item.get_file().get_serverRelativeUrl() + "' alt=''>" + item.get_file().get_name() + "</a>" ;
    cell4.innerHTML = "";
                     }),Function.createDelegate(this,function(sender, args){
                  alert(args.get_message());
              }),Function.createDelegate(this,function(sender, args){
                  alert(args.get_message());
    }), Function.createDelegate(this, function(sender, args){ 
         alert(args.get_message()); 
    </script>​​​​​ 
    <table id="myFavoritesTable">
       <tbody> 
          <tr valign="top" class="ms-viewheadertr"> 
             <th nowrap="nowrap" class="ms-vh"> 
                <table> 
                   <tbody> 
                      <tr> 
                         <td width="100%" nowrap="nowrap" class="ms-vb">שם טבלה 
                            <img src="/_layouts/15/images/blank.gif" height="1" width="13" alt="" style="visibility: hidden;"/> </td> 
                      </tr> 
                   </tbody> 
                </table> 
             </th> 
             <th nowrap="nowrap" class="ms-vh"> 
                <table> 
                   <tbody> 
                      <tr> 
                         <td width="100%" nowrap="nowrap" class="ms-vb">ID 
                            <img src="/_layouts/15/images/blank.gif" height="1" width="13" alt="" style="visibility: hidden;"/> </td> 
                      </tr> 
                   </tbody> 
                </table> 
             </th> 
             <th nowrap="nowrap" class="ms-vh"> 
                <table> 
                   <tbody> 
                      <tr> 
                         <td width="100%" nowrap="nowrap" class="ms-vb">כותרת 
                            <img src="/_layouts/15/images/blank.gif" height="1" width="13" alt="" style="visibility: hidden;"/> </td> 
                      </tr> 
                   </tbody> 
                </table> 
             </th> 
             <th nowrap="nowrap" class="ms-vh"> 
                <table> 
                   <tbody> 
                      <tr> 
                         <td width="100%" nowrap="nowrap" class="ms-vb">מסמך ​ 
                            <img src="/_layouts/15/images/blank.gif" height="1" width="13" alt="" style="visibility: hidden;"/> ​​​​​​​</td> 
                      </tr> 
                   </tbody> 
                </table> 
             </th> 
          </tr>
       </tbody> 
    </table>​ 
    <p>​​​​​​​​​</p>

  • How to get Session from different namespace?

    Hi,
    I´m trying to get a session from a different namespace, how can I do this?
    For example: I´m setting some session parameters with session.setAttribute in
    a namespace called "customer", and trying to get this parameters in a namespace
    called "main".
    In my webflow, I am using a proxy node to call the page in the other namespace.
    I will always recieve a session from the other namespace. But, when I try to get
    the parameters, I think the session have been lost.
    Can anyone help me?
    Thanx. CSN
    Thank

    Why? Because that's what the J2EE specification says should happen.

  • How to get posixGroups from LDAP working again?

    I can't tell if this is just broken in ML, or if I'm just missing it.
    I have an LDAP server running OpenLDAP and RFC2307. I have a couple groups defined with standard syntax, that is:
    dn: cn=netadmin,ou=Group,dc=example,dc=net
    cn: netadmin
    description: Network Administrators
    gidnumber: 20002
    memberuid: pjfasano
    memberuid: fasano
    objectclass: posixGroup
    objectclass: top
    I used to be able to use the dseditgroup command to add this group to the local "admin group, thereby giving all of the users in "netadmin" the right to sudo, install updates, etc. I seem to be able to use the same command, and add it to the local group, but users can't do anything administrative.
    Here's where it gets funky -- here's the output from dseditgroup netadmin:
    pjfasano@iMac:~$ dseditgroup -o read netadmin
    dsAttrTypeStandard:RecordName -
              netadmin
    dsAttrTypeStandard:AppleMetaNodeLocation -
              /LDAPv3/server.example.net
    dsAttrTypeStandard:AppleMetaRecordName -
              cn=netadmin,ou=Group,dc=example,dc=net
    dsAttrTypeStandard:PrimaryGroupID -
              20002
    dsAttrTypeStandard:RecordType -
              dsRecTypeStandard:Groups
    dsAttrTypeStandard:Member -
              pjfasano
              fasano
    dsAttrTypeStandard:GroupMembership -
              pjfasano
              fasano
    It all looks okay. But when I run dseditgroup -o checkmember:
    pjfasano@iMac:~$ dseditgroup -v -o checkmember netadmin
    dseditgroup verbose mode
    Options selected by user:
    Checking membership selected
    Username determined to be Groupname provided as
    no pjfasano is NOT a member of netadmin
    it says I'm not a member! Even though it just listed me as a member. Any ideas?
    NOTE: This is a duplicate of https://discussions.apple.com/message/19200709 -- just trying to get stuff answered.

    Bumping this to the top -- I'm still having this problem with 10.8.2 on the client.

  • How to get records from different tables

    Here is my Database diagram and my scenario is that When a user enter number of person and amount, amount/person
    let suppose 4/1000=250 and now 250 is , match in Product_Price Field in RstProductDetails, and select only Restaurant where 250 is matched. Next when a
    user select Restaurant e.g KFC and then KFC Products details is show.
    Here is my [WebMethod]
    [WebMethod]
        public DataSet Restaurant(decimal amount, decimal persons)
            //       DataSet result = Amount / personHash;
             //amount.ToString("amount");
            decimal price = amount / persons ;
            DataSet result = null;
            const string SQL_COMMAND_TEXT = "SELECT Product_Name,Product_Price FROM ABCD WHERE Product_Price<= @price";
            using (SqlConnection connection = Class1.GetConnection())
                connection.Open();
                using (SqlCommand command = new SqlCommand(SQL_COMMAND_TEXT, connection))
                    command.Parameters.Add("@Rst_Name", SqlDbType.NVarChar);
                    command.Parameters.Add("@Persons", SqlDbType.NVarChar);
                    command.Parameters.Add("@price", SqlDbType.Int);
                    command.Parameters["@Rst_Name"].Value = amount;
                    command.Parameters["@persons"].Value = persons;
                    command.Parameters["@price"].Value = price;
                    using (SqlDataAdapter dataAdapter = new SqlDataAdapter(command))
                        result = new DataSet();
                        dataAdapter.Fill(result);
            return result;

    <Table diffgr:id="Table8" msdata:rowOrder="7">
    <Product_Name>Orange/Tropical Juice Small</Product_Name>
    <Product_Price>120</Product_Price>
    </Table>
    <Table diffgr:id="Table9" msdata:rowOrder="8">
    <Product_Name>Orange/Tropical Juice Tall</Product_Name>
    <Product_Price>160</Product_Price>
    </Table>
    <Table diffgr:id="Table10" msdata:rowOrder="9">
    <Product_Name/>
    <Product_Price xml:space="preserve"></Product_Price>
    </Table>
    <Table diffgr:id="Table11" msdata:rowOrder="10">
    <Product_Name>Breakfast - Meals</Product_Name>
    <Product_Price>1,300</Product_Price>
    <Table diffgr:id="Table16" msdata:rowOrder="15">
    <Product_Name>3 pcs Hot Cakes + Small Cappuccino</Product_Name>
    <Product_Price>1,370</Product_Price>
    Sir when i debug mt web services it will show random items which is less than or greater than 325

  • How to get servername from a request but not the cluster name?

    hi all,
    how do i get server name from the request? This is the scenario, When ever a request is made, its handed to a cluster and then directed to one of the server in the cluster.
    When i say request.getServerName();---- This is giving me the cluster name and not the server name.
    any suggestions/idea ? Thanks alot in advance.
    Edited by: new_member on Apr 18, 2008 9:11 PM

    ADJavaUser wrote:
    You could try this:
    Create a batch or shell script that executes ifconfig or ipconfig and writes the IP address out to a file.
    Place each shell script file at different locations on each server within the cluster.
    Then within the code, try to execute each script from an external process (Runtime.exec). Since the files are at different locations within each server only the correct shell script for each server should execute and write the IP Address to a file. You'll have to detect which one ran. Then open the file that was written, possible parse it for the IP Address and use the code that I already provided.
    This is a time consuming process that will slow your application. Additionally depending on how your cluster is set up it might not work and still return the cluster's IP address.I got the solution....java.net.InetAddress.getLocalHost().getHostName(); works fine...But thanks guyz for ur responses

  • How to get data from excel sheet present in the client(local) system?

    hi,
    I have to upload the data from an excel sheet present in the local system(not on the server) to the table using webdynpro.
    i donot want to upload the excel file
    if it is necessary to upload the file then it should be on temporary basis and it should be deleted automatically.
    i can get the data from excel sheet which is present in the km using HSSF api but how to do the same if it is in local system?
    if anyone has the sample application of this type please give me the link.
    thanks

    You can use the FM ALSM_EXCEL_TO_INTERNAL_TABLE with Web Dynpro ABAP.

  • How to get information from a text editor in the SAP standard transactions

    Hi SAP gurus I have a requirement in which it is required to gte the information from a text editor(which is not a field) in mm02 (click on) goto Purchase Order Text  in this view there is a text editor there is some text  in te the text editor i have to get that information in a table can it be done if so please give example and steps
    Points will be given to useful information

    Ah yes, excellent question, and not really a clear cut answer. In my experience, the easiest way to find this information is to simply create the text using the standard transaction, in this case MM02.  Then go to transaction SE16, using table STXH, do a query on this table, entering your user name, and today's date as the creation date.  The results should show the text that you just created, now you can see the object, id, and the way the name is being used here. 
    I also understand that in some cases, there is a button next to the editor in the screen which gives you some idea of these values, but this is not implemented everywhere, and I believe that I've only seen this in one place, can't remember where, but the first solution above will always work for you.
    Regards,
    Rich Heilman

  • Re: how to get servername from a request but not the cluster name?

    hi all,
    how do i get server name from the request? This is the scenario, When ever a request is made, its handed to a cluster and then directed to one of the server in the cluster.
    When i say request.getServerName();---- This is giving me the cluster name and not the server name. Say cluster1 has server1 and server2 and request is dispatched to any of one these servers. request.getServerName() - gives me cluster1 but I need to get server1/server2.
    any suggestions/idea ? Thanks alot in advance.

    http://forum.java.sun.com/thread.jspa?threadID=5287623

  • How can I load a flat file using a different Work Station

    Hi Gurus,
    I'm having problems with loading Flat file in our Production Server when it comes to loading a file from another work station. The scenario is all the Info Packages needed are created in oour Dev Server. So the location of the flatfile is already define which is the developer's workstation. Now when the package is transported to the production server any changes to the package is not allowed inlcuding the location of the flatfile needed to be uploaded. Now my question is. is there a way that the location be changed in the production server without adding the package Z_BI because that will mean we can do changes in the production server. Thanks in Advance
    - Kit

    Directly you can not change the info package settings. You need do   change the status of Info package to changeable mode and then do necessary changes.
    RSA1 => Click on truck symbol (Object changeability) => select info package => right click => click on Switch changeability.
    Now do the changes to your Info Package.
    With Regards,
    Kishore.

  • HT4623 how to get app from itunes

    HOW TO GET GAMES FROM ITUNES,

    Find app in the app store.
    Buy app from the app store.
    Are you having an issue with the process?  What is that issue?
    Please turn off your caps lock and explain your issue

  • How to get users from Organizational Unit and with worker's subgroup

    Hi
    I am looking for a f. module to get the list of users from specific Organizational Unit and with specific worker's subgroup.
    I found f. module SWI_GET_USERS_OF_ORG_UNIT but it seems not working and only returns the users, how can I narrow the selection to get only from specific worker's subgroup?
    Thank you

    Hi,
    Try with FM RH_STRUC_GET with following parameters:
    ACT_OTYPE = O
    ACT_OBJID = worker's subgroup
    ACT_WEGID = SBESX
    Most important is to specify OBJID as the workers's subgroup, values for the others parameters may vary.
    Cheers.

  • How to get support for research work from oracle?

    sir
    i want to undergo a research from a univ at my city on db security and cryptography.i may require some document and psudo code of certain algorithim.how to get those from oracle?
    regards

    Find a contact within Oracle to help get you introduced to the Product Manager(s) for the area of interest. Ways to find that contact:
    - Oracle Sales (ask your/university sales rep for an intro)
    - relevant Oracle Forums (watch for responses from Oracle employees)
    - Oracle Wiki
    - Oracle Open World where you can meet lots of employees
    - User group meetings

Maybe you are looking for

  • HP 3520 All-in-One Printer Falls Out of Wireless Network Periodicia​lly

    We have an ongoing problem with our HP 3520 All-in-One Printer. We set it up for wireless printing and it works....for a while. Periodically, we find that it falls off the wireless network and will not print except when plugged into the USB cable. Th

  • I can send but not receive email using Outlook

    Hi all, I have had an iPhone 5C for about a year. I recently deleted my email account after being hacked, after which I received around 45 thousand bounceback emails in the space of 12 hours. It was too hard to receive them, 500 at a time on my iPhon

  • [Solved] Steam Can't Download Games

    Numerous people have been having this problem, where Steam will not download games correctly. It will start the download, then it slows to a crawl until it completely stops. I have found two reasons so far as to why this could be happening. One is th

  • Default display option in MB51

    Hi Folks, Can anyone help me in setting up a user specific default DISPLAY OPTION in transaction MB51. Expecting an early reply. T H A N K S, Sugopa

  • Dead link in iTunes Store

    I was trying to buy iPod games, but then realize it's all dead link and I coudn't click the buy button... Any suggestion for this?