How do I find the name of the server?

Hi all,
I've finished a server program that returns a hard-coded html page via a socket but was hoping to make it as authentic as possible. Therefore is there a way of retrieving the server's name that I'm conecting to without using servlets?
My code is:-
/*This program is designed to take a GET request from HTTPClient.java and return
*a hard-coded html document to the client. This program is run on the student
*server and listens to requests from the client program which should be run
*on the local machine.*/
import java.io.*;
import java.net.*;
import java.util.*;
public class HTTPServer{
    String version = null;
    public static void main(String argv[]){
    //I've added this statement for those that may be unfamiliar of how to run
    //the program.     
    if (argv.length != 1) {
         System.out.println("usage: java HTTPServer port");
         System.exit(1);
    //creates a new HTTPSever, argv[0] is the port.
     new HTTPServer(Integer.parseInt(argv[0]));
    public HTTPServer(int port){
     boolean listening = true;
    //Socket's must be created in a try and catch block as they may generate
    //exceptions, which the program must deal with.
     try{
          ServerSocket ss = new ServerSocket(port);
          System.out.println("HTTP Server running and listening for requests...");
          while (listening){
           Socket mySocket = ss.accept();
           //create an InputStream called 'in'
           InputStream in   = mySocket.getInputStream();
           //pass 'in' to the readHeaders method
           readHeaders(in);
           //call getResponse method to obtain the desired string and assign to
           //'response'
           String response = getResponse();
           //creates an OutputStream called 'out'
           OutputStream out = mySocket.getOutputStream();
           //transform 'response' into a byte array ready for output
           out.write(response.getBytes("US-ASCII"));
           //sends output to client
           out.flush();
           //close socket
           mySocket.close();
      catch(Exception e){System.out.println(e.getMessage());}
     /*This method creates a string buffer and appends the html to it. It then
      *gets transformed to a string and all leading and trailing white space
      *is trimmed. Finally the string is returned.*/
    private String getResponse(){
         //creates StringBuffer called 'responseBuf'.
         StringBuffer responseBuf = new StringBuffer();
         //get today's date and convert to a string
         Date date = new Date();
         String todayDate = date.toString();
         //appends values in brackets to responseBuf
         responseBuf.append (version + " 200 OK\r\n");
         responseBuf.append ("Date: " + todayDate + "\r\n");
         responseBuf.append ("Content-type: text/html\r\n");
         responseBuf.append ("Content-length: 119\r\n");
         responseBuf.append ("Last-modified: Thu, 21 July 2005 15:00:00 GMT \r\n");
         responseBuf.append ("<HTML>\r\n");
         responseBuf.append ("<TITLE> My served web document </TITLE>\r\n");
         responseBuf.append ("</HEAD>\r\n");
         responseBuf.append ("<BODY>\r\n");
         responseBuf.append ("<H1> Hello from the server! </H1>\r\n");
         responseBuf.append ("</BODY>\r\n");
         responseBuf.append ("</HTML>\r\n\r\n");
         //converts responseBuf to String called 'response'
         String response = responseBuf.toString();
         //trims any leading or trailing white space from string.
         response = response.trim();
         //returns the string
          return response;
     /*This method reads in the string from the client until either a header
      *block termination (\r\n\r\n) is read, or when the client disconnects
      *(ch == -1). When a character is received it gets stored in an array and
      *also in a string buffer. I decided to use a character array as it enabled
      *me to check for the header block termination commands with relative ease.
      *When the if loop condition is met the program breaks out of the while
      *loop. The StringBuffer sbuf now contains the full request from the client.
      *The program now converts the buffer to a string and trims any leading and
      *trailing white space. From here the string is then split into substrings
      *and stored in a string array. The program finally checks for the HTTP
      *version.*/
    private void readHeaders(InputStream in) throws IOException {
          //Creates a character array to store each character one-by-one.
          char [] inputArr = new char [200];
          //Creates StringBuffer called 'sbuf'
          StringBuffer sbuf = new StringBuffer();
          //Integer 'count' set to zero. Will be used to position each character
          //in the character array.
          int count = 0;
          //Initialise new integer called 'ch'
          int ch;
          //Initialise a new String called 'clientStr'
          String clientStr;
          //While there is something to read and socket is connected, add each
          //character to the character array and the buffer as long as the program
          //doesn't receive the header block termination.
          while ((ch = in.read()) != -1) {
               inputArr[count] = (char) ch;
               if ((inputArr[count] == '\n') && (inputArr[count - 1] == '\r')
               && (inputArr[count - 2] == '\n') && (inputArr[count - 3] == '\r'))
                break;
                count++;
                sbuf.append((char) ch);
     //clientStr will hold string in string buffer without any leading or
     //trailing white space.
         clientStr = sbuf.toString();
         clientStr = clientStr.trim();
     //Split clientStr into substrings and store them in an array.
     String [] tokens = clientStr.split(" ");
     //Obtains HTTP version
     version = tokens [2];
}Thanks in advance,
Chris

When an HTTP message is sent to my client it should send something like:-
HTTP/1.0 200 OK
Date: Thurs, 21 Jul 2005 21:30:00 GMT
Server: Apache/1.3.26
etc....
The bit I'm trying to obtain is the Server line. Is it the server type perhaps as opposed to the name? I would imagine it's something like String serverName = Server.getName().toString(); but that doesn't work.

Similar Messages

  • I've installed LR on my new Mac - How do I find/what is the name of the file that opens to bring up my existing photos (on my external hd)?

    I've installed LR on my new Mac - How do I find/what is the name of the file that opens to bring up my existing photos (on my external hd)?

    Bookmarks and history are stored together in your profile folder in a database file named places.sqlite. These articles should help with restoring as much or as little of your other profile as you like:
    Locating the folder: [https://support.mozilla.com/en-US/kb/Profiles Profiles | How to | Firefox Help]
    The following article has suggestions for recovering bookmarks: [http://support.mozilla.com/en-US/kb/Lost%20Bookmarks Lost Bookmarks | Troubleshooting | Firefox Help].
    To move more settings, see: [https://support.mozilla.com/en-US/kb/Recovering+important+data+from+an+old+profile Recovering important data from an old profile].
    Hope this helps.

  • How to find table name for the fields from Standard Extractor in CRM system

    How to find table name of fields from the standard extractor in CRM system ?
    e.g. We use LBWE TCode in R/3 system to find table name for the field from Extractor VCSCL(e.g.).
    Likewise is there any way to find table name for the fields from Standard extractor like 0CRM_LEAD_I.

    Hi ,
    Please find the link below for understanding BW CRM analysis.
    http://help.sap.com/bp_biv135/html/bw.htm
    activate the CRM DSs by scenario:
    1) Activate the application component hierarchy (tcode RSA9). Changes made to the application component hierarchy in the CRM system can be transferred to the BW using the "Edit Application Component Hierarchy" (SBIW - Postprocessing of DataSources).
    SAP Note 434886 must be implemented in CRM 3.0 before the application component hierarchy is activated.
    2) Activate the Business Content DataSources (tcode RSA5).
    Select/enter the application component and choose Execute (F8).
    To compare the shipped and active versions, choose the 'Select Delta' pushbutton. If there is no active version of the DataSource, it is selected automatically.
    To activate the shipped version, choose the 'Transfer DataSources' pushbutton.
    3) Management of the versions of the BW-Adapter metadata (tcode BWA5). All DataSources are displayed that are managed by the BW Adapter.
    As in transaction RSA5 (Service API Metadata Activation), the 'Select Delta' function can be used to select the inactive DataSources or compare shipped and active versions.
    You can also go directly to the screen for maintaining DataSources that are managed by the BW Adapter.
    The 'Compare Version' function makes a detailed comparison of the shipped and active versions.
    All BW-Adapter metadata is considered when versions are compared:
    Header information (Table SMOXHEAD)
    Mapping information (Table SMOXRELP)
    Global selection conditions (Table SMOXGSEL)
    Attribute key fields (Table SMOXAFLD)
    Hope this helps.
    Regards,
    csm reddy

  • How can I find out the name of the folder my java program is in?

    Hi, I'm trying to make a little utitlity that makes a bunch of url shortcuts based on the name of the folder I run the java from.
    i.e.
    I have my executable jar in C:/Someplace/My Folder Name/
    I'd like to be able to double click on the jar and it creates the url shortcuts for me using "My Folder Name" as a parameter.
    I've done the shortcuts bit but can't figure out (=find a tut) how to read the folder name.
    Thanks to anyone who can help!

    import java.io.*;
    import java.net.*;
    import java.security.*;
    public class Attempt {
        public static void main(String[] args) throws IOException {
            System.out.println(new Attempt().getFolder());
        public File getFolder() throws IOException {
            ProtectionDomain domain = getClass().getProtectionDomain();
            CodeSource source = domain.getCodeSource();
            URL url = source.getLocation();
            if (!"file".equals(url.getProtocol())){
                throw new IOException("Code source location not a file:" + url);
            String path = url.getPath();
            //remove xxx.jar from path:
            return new File(path.substring(0, path.lastIndexOf('/')));
    }

  • HT4519 when i try send a email off my iphone its says my house name is ,how do i find out which is the correct name?

    when i try send a email off my iphone its says my house name is wrong,how do i find out which is the correct name?

    Try deleting the account and then add it back.

  • How to find the name of the main program in the SM35

    Hi all,
    I have problems to find which program a batch input belongs to: may I explain myself...I can see in transaction SM35 several session names but no trace of the name of the program which is being used...I tried to find it with table APQI but no results so far. Does anyone know how can I get this information?
    Thanks a lot!

    Check table TBTCP
    Regards,
    Rich Heilman

  • How to find the name of the program of session in sm35 ?

    I have some session in sm35.
    How to find the name of the program of session in sm35 ?
    Could you please help me ?

    In the list of sessions displayed -> double click the session that an error (i.e. Transaction Ended with errors).
    Then it will take you to another screen, here you choose the Screens tab.
    Check
    Re: BDC session's program name
    Re: BDC session's program name
    Regards,
    Santosh
    Message was edited by:
            Santosh Kumar Patha

  • How can i get my name on the finder bar?

    How do i get my name on the top right corner next to the search bar? I have OS X Mountain Lion 10.8.5

    System Preferences > Users & Groups
    Click the lock to unlock it, if you have to.
    Click "Login Options".
    Enable " Show fast user switching menu as" and select "Full Name".
    Best.

  • How to find out the name of the executable

    hi,
    say, i have an executable jar called Hello.jar. how do i know the name "Hello.jar" in main() when the executable jar is launched.
    that is, if i rename Hello.jar to HelloWorld.jar, how can main() know about this? this matters because i want to run the app
    in a separate process, which requires the name of the application.
    thanks

    yes to question 1: because i'm calling into a dll through jni to display a screensaver in the preview window. not spawning a separate process causes windows to hang for a while before
    the screensaver is displayed. the new process is passed arguments that are checked by main() so that another process won't be created (no infinite recursions).
    thanks.

  • How to find the Name of the BSP Application Being Invoked?

    Hi ,
    Is there any FM or method that would return the name of the BSP Application being invoked?
    Say i have a method A which is being invoked by 2 BSP Application B and C. How do we determine which BSP is invoking the method A?
    Any input on this regard will be of great help.
    Thanks and Regards,
    Pavithra

    Hi,
    this methods are not 100% efective but you may try it:
    On runtime:
    set an external breakpoint in your method A and run your application. When it stops, the debugger has many folders, so press the one marked with "Standard" and in section ABAP stack you see the different call steps that have been executed, including the application that is calling the method.
    For this you must activate the new debugger (Utilities --> settings --> ABAP editor --> Debugging)
    On development time:
    Click on method A and press button Where-used list. In the incomming window press BSP applications.
    Hope it helps.

  • How to find the name of the calling procedure

    Hi,
    Can anybody please help me out urgently. Inside one procedure or function,i want to get the name of the procedure calling this procedure. In other words, i want to get the name of the calling procedure inside the called procedure.
    Please reply soon.Have a nice time.
    Thanks & Regards
    Jogesh

    Hi Rod West,
    Thanks for your reply. Can you please give an example how to use this.just simple example where it will display the name of the calling proc in the called proc.Please help.
    Thanks & Regards
    Jogesh

  • Existing cross Reference: how to change the name of the file it refers to?

    Hi everybody,
    I am a professional translator.
    One client of mine sent me a complete FrameMaker 9 book file for translation.
    I translated the content via a CAT-Tool and now am in the process of checking if cross references and markers are ok directly into the file.
    I noticed that many cross references are linked to another file of the book. But in the process of translating each file separately, I gave them a slightly different name (I added the language at the end) so as to be able to recognise them eventually.
    Now I have this problem: I cannot find in the cross reference interface where to change the name of the file into the new one the cross reference is supposed to refer to.
    Am I right in wanting to change the file reference? If so, how do I do that?
    Or is it better to avoid this task and rename the translated file into their original names ? Would it work then?
    Thanks for your help.

    ... book file ...
    ...  each file separately, I gave  them a slightly different name (I added the language at the end) ...
    I'm guessing that you renamed the component files by means other than using the Edit > Rename File from the Book menu.
    If so, do over. Rename from the Book menu. It automatically revises all the cross-references in all the component files.
    In a Book, the only thing that's safe to rename with the file manager is the .book file itself.

  • How do I change the name of the Home folder OSX 10.9

    Hi there,
    I am trying to change the name of the Home folder on my Macbook Pro running OSX 10.9  I had a clean install of 10.9, and used migration assistant to restore my settings from a Time Machine Backup. 
    The problem is that the Home folder for my user is now named "Cody 1" when it used to be "Cody".  This seems like a minor issue, but all the programs that reference data in the old location, are forcing me to go and find the data manually.  Everything from iPhoto to VirtualBox, all files have to be found manually. 
    I have tried the instructions set forth in this article, http://support.apple.com/kb/ht1428, but the dialog that should, according to the article, allow me to redirect the account to the existing folder, returns an error saying that the user name is already in use.  There is no option to use the existing folder.  I have tried re-naming the folder to something different, to no avail. 
    Ideas?
    Thanks in advance. 
    -Cody

    The Apple Support document you referenced is cumbersome, outdated, buggy, and too likely to result in the sort of problems you described.
    It may be too late now but see the following:
    Niel's post here: How to change name of home folder
    and:
    Apple Support Communities contributor Pondini found an astonishingly simple way to accomplish what you seek. etresoft distilled that information into the following User Tip:
    Changing user account short name
    Note that he writes it has been tested on Mountain Lion but the procedure appears sound and should work equally well with Mavericks.
    Back up your system before doing either one.
    To fix what happened might be possible in Single user mode. I don't have specific instructions but you should be able to find and delete user accounts in the /Users directory.
    Type carefully and don't proceed without knowing the risks.

  • How to get the name of the subform

    Hi All,
    My form is designed in the below structure.
    masgterpage-->form1-->table
                                  -->subform
    How can i get the name of the subform dynamically(as it varies from page to page, but the rest of the structure is same).
    Please help me.
    Thank you,
    Saravanakumar.

    Hi there,
    the name property would be the correct attribute to get the subform name, just by looking at the code it doesn't seem like it's doing the right thing
    I am assuming that you send Main in the function countChk() which would look something like this
    countChk(Main);
    And you probably want to make sure you are entering the right subform so you need to keep that loop at the end of the function
    but if you want to get through all the checkboxes inside that subform you must do a loop through that node to find each checkbox
    I am assuming that the function would probably look something like this
    function countChk(vNode) {//Starts vNode with Main
         for (var i = 0; i < vNode.nodes.length; i++) {
              if (vNode.nodes.item(i).className === "field") {
                   if (vNode.ui.oneOfChild.className === "checkButton") {
                        if (vNode.items.nodes.length > 1) {
                             if (vNode.value.oneOfChild.value == 1) {
                                  nChk++ ;
              }else if (vNode.nodes.item(i).className === "subform"){
                   if (vNode.nodes.item(i).name === "Door_Subform"){
                        countChk(vNode.nodes.item(i));
         }//endloop
    Hope this help!

  • For those who have problems RE: My iPhone 4 on connecting to my pc shows my friends name in the DIGITAL camera Drive..It dsiplays my correct name when I`m on iTunes..PLEASE HELP ME HOW DO I CHANGE THE NAME IN THE DIGITAL CAMERA DRIVE??

    For those who have problems RE: My iPhone 4 connecting to my pc shows my friends name in the DIGITAL camera Drive..It dsiplays my correct name when I`m on iTunes..PLEASE HELP ME HOW DO I CHANGE THE NAME IN THE DIGITAL CAMERA DRIVE??
    SOLUTION:
    Iam pointing t0 windows7 os.
    1) go to control panel
    2) open hardware and sound
    3) In that open Devices and printers
    4)In that u can find Apple Iphone.
    5) now right click on this --> Hardware --> Properties --> General --> Uninstall --> ok.
    6) now unplug and plug in ur iphone again.There u go u iphone name changes to its original name.

    I am having this problem.  At first with the new iPhone 5, and then with the iPad 2.  I am not sure why this is happening. 
    My gut feeling is this is an iO6 issue and here's why -
    The problem mainly occurs with apps.  I have about 150 apps, and when I plugged in the phone, iTunes went to sync all of them.  The process would hang up after about 20 - 30 apps were loaded onto the phone. I could tell where about the process hung up because the apps on the phone showed up as "waiting".
    Then on the iPad 2 I plugged in to sync and saw there was a huge "Other" component in my storage.  It required me to restore the iPad 2 from backup.  With this restore the same issues occurred - putting the apps back on the iPad would hang up.  The videos on the iPad also got stuck - maybe after about 10 hours of videos transfered iTunes crashed.
    My solution has been to soft reset the device, restart Windows, and continue the process until it's complete.  This is remarkably inefficient and time-intensive but everything works with patience.
    I have been wondering if others have had these same problems. 

  • "Who ran me" - how to determine the name of the dbms_scheduler job that ran me

    Hi Community
    I can see plenty of examples out on the interweb which shows how you can use dbms_utility.format_call_stack to find the hierarchy of procs, functions and packages that got me to a particular point in my code.
    For example, if proc (procedure) A calls proc B, which in turn calls proc C, in the code for proc C, I can query the call stack to find out that proc C was called by proc B which in turn was called by proc A
    However, I want to extend this further.
    For example, using the example above, if proc A in turn was started by a dbms_scheduler job, I want to determine (within proc C) the name of the dbms_scheduler job which started the whole process off.
    The reason I want to do this is that I have inherited a (massive) system which is undocumented. In many places within the code, email alerts are sent out using a custom "MAIL" package to designated users (now including me) when certain long-running processes reach certain milestones and/or complete.
    I have added to the custom "MAIL" package a trailer on the mails to show the call stack. I also want to show the name of the dbms_scheduler job which started it all.
    Over time, this info may help me in building the "map" of how the whole undocumented system hangs together and in the meantime, to assist in troubleshooting problems
    Looking forward to hearing from you
    Alan

    Use USER_SCHEDULER_RUNNING_JOBS or DBA_SCHEDULER_RUNNING_JOBS there is column SESSION_ID and when you know your session ID build query is very simple.
    select owner, job_name
    into ...
    from dba_scheduler_runnig_jobs
    where session_id=sys_context('USERENV','SESSIONID');
    You must declare local variables in PL/SQL procedure to read owner and job_name into them. Second thing, you must handle possible exception no_data_found than can be raised when procedure is not run from job.

Maybe you are looking for

  • System monitor counter

    I'm trying to use system monitor activeX in order to control memory usage and CPU usage of my PC. All activeX properties work fine except the most useful: counter. I've attached the screen shot of my VI. P.S. I think counter property is used to read

  • Using imessenger is it free to chat with iphone users who are in another country?

    Using imessenger is it free to chat with iphone users who are in another country?

  • System Copy in Unix

    Hi, We are Restoring Backup of Production system to Quality Server. SAP version is ECC 5.0. Database - Oracle 9.2.0.7.0. OS- HP Unix 5.1A For that first of all we have installed UNIX Tru-64 on Quality Server. Then after we have restored backup of pro

  • Doc for 10g Web Services for EJBs

    I'm trying to determine if any documentation exists for 10gAS that discusses how to publish a statless session bean as a web service. The only thing I'm found so far is a tutorial called "Expose a Stateless Session EJB as a Web Service Endpoint throu

  • Management of LR3.2 Versions on Computer?

    Greetings-   I posted this on another thread, but never received a response.  Now it seems to have been "lost" in the traffic for that previous thread!   Can someone clear this up for me so that I don't erase/remove the wrong program?   Thanks. Steph