Applet - Server socket problem

Hello i'm trying to develop a simple chat application
The applet connects to the server via a socket and it can successfully send a line of text to the server and receive one back.
But if I try to put a loop in to receive more lines the applet doesn't start
here is some source, i'd appreciate any help
* ChatClient.java
* Java Applet for communicating with server
import java.io.*;
import java.net.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class ChatClient extends Applet
     public Panel input;
     public OutputPanel output;
     public PrintWriter out = null;
public BufferedReader in = null;
     public Socket client = null;
     public Label label;
     public TextField itext;     
     public boolean connected = false;
     public String fromServer = "";
     public void init()
          setLayout( new BorderLayout() );
          input = new Panel();
          input.setLayout( new FlowLayout() );
          label = new Label( "Enter Message" );
          itext = new TextField( 15 );
          TextHandler handler = new TextHandler();
          itext.addActionListener( handler );
          input.add( label );
          input.add( itext );          
          output = new OutputPanel();     
          add( "South", input );
          add( "Center", output );
     public void start()
          String host = getDocumentBase().getHost();          
          try
               // create socket connection
               client = new Socket( host, 4444 );
               out = new PrintWriter( client.getOutputStream(), true );
in = new BufferedReader( new InputStreamReader( client.getInputStream() ) );
          catch (UnknownHostException e)
               System.err.println("Don't know about host: 10.1.7.2.");
System.exit(1);
          catch (IOException e)
System.err.println("Couldn't get I/O for the connection to: 10.1.7.2.");
System.exit(1);
          output.otext.append( "Chat client started, listening\n\n" );
          listen();               
     public void listen()
          out.println( "Client 1" );
          try
               fromServer = in.readLine();
               output.otext.append( "Server: " + fromServer + "\n\n" );
               connected = true;
               //do
               //     fromServer = in.readLine();
                    System.err.println( "Server: " + fromServer );
               //     if ( fromServer.equals( "Bye" ) )
               //          connected = false;
               //     output.otext.append( "Server: " + fromServer + "\n\n" );
               //}while ( connected );
          catch( IOException io )
               System.err.println( "Cannot read from server" );
               io.printStackTrace();
     public void sendData ( String s )
          out.println( s );
          //output.otext.append( "Client: " + s + "\n\n" );
     public void destroy()
          try
               out.println( "Bye" );
               out.close();
               in.close();
               client.close();
          catch( IOException io )
               System.err.println( "Error closing Socket or IO streams");
               io.printStackTrace();
class TextHandler implements ActionListener
     public void actionPerformed( ActionEvent e )
          sendData( e.getActionCommand() );
public String getAppletInfo()
          return "A simple chat program.";
     public static void main(String [] args)
          Frame f = new Frame( "Chat Applet" );
          ChatClient chatclient = new ChatClient();
          chatclient.init();
          chatclient.start();          
          f.add( "Center", chatclient );
          f.setSize( 300, 300 );
          f.show();
class OutputPanel extends Panel
     public TextArea otext;
     public OutputPanel()
          setBackground( Color.white );
          setLayout( new BorderLayout() );
          otext = new TextArea( 6, 60 );
          otext.setEditable( false );
          add( "Center", otext );
          setVisible( true );
public void paint(Graphics g)
}

I think you have to modify the loop, which receive data from your socket.
here an example which I tryed
hope I can help you
while (z==1)
anzeige = in.readLine();
if (anzeige.charAt(0) == ende.charAt(0) && anzeige.charAt(1) == ende.charAt(1) && anzeige.charAt(2) == ende.charAt(2)) // searching for the end"-~-"
break;
textField.add(anzeige);

Similar Messages

  • Server socket problem

    I have written a java program, that is running on 2 PCs. I would like to display the outcomes of the program on one of those PCs. I believe I need a server socket to do this, but I am not really sure. Can someone help me? Thanks!

    Yes, java applications can communicate using sockets.
    Assuming your 2 PCs can "ping" each other.
    A ServerSocket listens for connections on a port and creates a new Socket when a client connects.
    What are you having problems with?

  • Problems Reading SSL  server socket  data stream using readByte()

    Hi I'm trying to read an SSL server socket stream using readByte(). I need to use readByte() because my program acts an LDAP proxy (receives LDAP messages from an LDAP client then passes them onto an actual LDAP server. It works fine with normal LDAP data streams but once an SSL data stream is introduced, readByte just hangs! Here is my code.....
    help!!! anyone?... anyone?
    1. SSL Socket is first read into  " InputStream input"
    public void     run()
              Authorization     auth = new Authorization();
              try     {
                   InputStream     input     =     client.getInputStream();
                   while     (true)
                   {     StandLdapCommand command;
                        try
                             command = new StandLdapCommand(input);
                             Authorization     t = command.get_auth();
                             if (t != null )
                                  auth = t;
                        catch( SocketException e )
                        {     // If socket error, drop the connection
                             Message.Info( "Client connection closed: " + e );
                             close( e );
                             break;
                        catch( EOFException e )
                        {     // If socket error, drop the connection
                             Message.Info( "Client connection close: " + e );
                             close( e );
                             break;
                        catch( Exception e )
                             //Way too many of these to trace them!
                             Message.Error( "Command not processed due to exception");
                             close( e );
                                            break;
                                            //continue;
                        processor.processBefore(auth,     command);
                                    try
                                      Thread.sleep(40); //yield to other threads
                                    catch(InterruptedException ie) {}
              catch     (Exception e)
                   close(e);
    2 Then data is sent to an intermediate function 
    from this statement in the function above:   command = new StandLdapCommand(input);
         public StandLdapCommand(InputStream     in)     throws IOException
              message     =     LDAPMessage.receive(in);
              analyze();
    Then finally, the read function where it hangs at  "int tag = (int)din.readByte(); "
    public static LDAPMessage receive(InputStream is) throws IOException
        *  LDAP Message Format =
        *      1.  LBER_SEQUENCE                           --  1 byte
        *      2.  Length                                  --  variable length     = 3 + 4 + 5 ....
        *      3.  ID                                      --  variable length
        *      4.  LDAP_REQ_msg                            --  1 byte
        *      5.  Message specific structure              --  variable length
        DataInputStream din = new DataInputStream(is);
        int tag = public static LDAPMessage receive(InputStream is) throws IOException
        *  LDAP Message Format =
        *      1.  LBER_SEQUENCE                           --  1 byte
        *      2.  Length                                  --  variable length     = 3 + 4 + 5 ....
        *      3.  ID                                      --  variable length
        *      4.  LDAP_REQ_msg                            --  1 byte
        *      5.  Message specific structure              --  variable length
        DataInputStream din = new DataInputStream(is);
           int tag = (int)din.readByte();      // sequence tag// sequence tag
        ...

    I suspect you are actually getting an Exception and not tracing the cause properly and then doing a sleep and then getting another Exception. Never ever catch an exception without tracing what it actually is somewhere.
    Also I don't know what the sleep is supposed to be for. You will block in readByte() until something comes in, and that should be enough yielding for anybody. The sleep is just literally a waste of time.

  • Problem trying to read an SSL server socket stream using readByte().

    Hi I'm trying to read an SSL server socket stream using readByte(). I need to use readByte() because my program acts an LDAP proxy (receives LDAP messages from an LDAP client then passes them onto an actual LDAP server. It works fine with normal LDAP data streams but once an SSL data stream is introduced, readByte just hangs! Here is my code.....
    help!!! anyone?... anyone?
    1. SSL Socket is first read into  " InputStream input"
    public void     run()
              Authorization     auth = new Authorization();
              try     {
                   InputStream     input     =     client.getInputStream();
                   while     (true)
                   {     StandLdapCommand command;
                        try
                             command = new StandLdapCommand(input);
                             Authorization     t = command.get_auth();
                             if (t != null )
                                  auth = t;
                        catch( SocketException e )
                        {     // If socket error, drop the connection
                             Message.Info( "Client connection closed: " + e );
                             close( e );
                             break;
                        catch( EOFException e )
                        {     // If socket error, drop the connection
                             Message.Info( "Client connection close: " + e );
                             close( e );
                             break;
                        catch( Exception e )
                             //Way too many of these to trace them!
                             Message.Error( "Command not processed due to exception");
                             close( e );
                                            break;
                                            //continue;
                        processor.processBefore(auth,     command);
                                    try
                                      Thread.sleep(40); //yield to other threads
                                    catch(InterruptedException ie) {}
              catch     (Exception e)
                   close(e);
    2 Then data is sent to an intermediate function 
    from this statement in the function above:   command = new StandLdapCommand(input);
         public StandLdapCommand(InputStream     in)     throws IOException
              message     =     LDAPMessage.receive(in);
              analyze();
    Then finally, the read function where it hangs at  "int tag = (int)din.readByte(); "
    public static LDAPMessage receive(InputStream is) throws IOException
        *  LDAP Message Format =
        *      1.  LBER_SEQUENCE                           --  1 byte
        *      2.  Length                                  --  variable length     = 3 + 4 + 5 ....
        *      3.  ID                                      --  variable length
        *      4.  LDAP_REQ_msg                            --  1 byte
        *      5.  Message specific structure              --  variable length
        DataInputStream din = new DataInputStream(is);
           int tag = (int)din.readByte();      // sequence tag// sequence tag

    I suspect you are actually getting an Exception and not tracing the cause properly and then doing a sleep and then getting another Exception. Never ever catch an exception without tracing what it actually is somewhere.
    Also I don't know what the sleep is supposed to be for. You will block in readByte() until something comes in, and that should be enough yielding for anybody. The sleep is just literally a waste of time.

  • Problems reading  an SSL server socket stream using readByte()

    Hi I'm trying to read an SSL server socket stream using readByte(). I need to use readByte() because my program acts an LDAP proxy (receives LDAP messages from an LDAP client then passes them onto an actual LDAP server. It works fine with normal LDAP data streams but once an SSL data stream is introduced, readByte just hangs! Here is my code.....
    help!!! anyone?... anyone?
    1. SSL Socket is first read into  " InputStream input"
    public void     run()
              Authorization     auth = new Authorization();
              try     {
                   InputStream     input     =     client.getInputStream();
                   while     (true)
                   {     StandLdapCommand command;
                        try
                             command = new StandLdapCommand(input);
                             Authorization     t = command.get_auth();
                             if (t != null )
                                  auth = t;
                        catch( SocketException e )
                        {     // If socket error, drop the connection
                             Message.Info( "Client connection closed: " + e );
                             close( e );
                             break;
                        catch( EOFException e )
                        {     // If socket error, drop the connection
                             Message.Info( "Client connection close: " + e );
                             close( e );
                             break;
                        catch( Exception e )
                             //Way too many of these to trace them!
                             Message.Error( "Command not processed due to exception");
                             close( e );
                                            break;
                                            //continue;
                        processor.processBefore(auth,     command);
                                    try
                                      Thread.sleep(40); //yield to other threads
                                    catch(InterruptedException ie) {}
              catch     (Exception e)
                   close(e);
    2 Then data is sent to an intermediate function 
    from this statement in the function above:   command = new StandLdapCommand(input);
         public StandLdapCommand(InputStream     in)     throws IOException
              message     =     LDAPMessage.receive(in);
              analyze();
    Then finally, the read function where it hangs at  "int tag = (int)din.readByte(); "
    public static LDAPMessage receive(InputStream is) throws IOException
        *  LDAP Message Format =
        *      1.  LBER_SEQUENCE                           --  1 byte
        *      2.  Length                                  --  variable length     = 3 + 4 + 5 ....
        *      3.  ID                                      --  variable length
        *      4.  LDAP_REQ_msg                            --  1 byte
        *      5.  Message specific structure              --  variable length
        DataInputStream din = new DataInputStream(is);
           int tag = (int)din.readByte();      // sequence tag// sequence tag

    I suspect you are actually getting an Exception and not tracing the cause properly and then doing a sleep and then getting another Exception. Never ever catch an exception without tracing what it actually is somewhere.
    Also I don't know what the sleep is supposed to be for. You will block in readByte() until something comes in, and that should be enough yielding for anybody. The sleep is just literally a waste of time.

  • Can't connect to my server socket using external IP

    Hi I'm very new to Java programming, and I'm learning all the core things I need to understand so that I can make a simple networked game using a command-line server and applet clients. I tried the networking tutorial and it worked perfectly on my machine.
    However, it only works if I supply the client with my INTERNAL IP. When I give it my EXTERNAL IP it cannot connect to the server socket. The error thrown is a IOException.
    The code:
    import java.io.*;
    import java.net.*;
    public class KnockKnockClient {
        public static void main(String[] args) throws IOException {
            Socket kkSocket = null;
            PrintWriter out = null;
            BufferedReader in = null;
            try {
                kkSocket = new Socket("192.168.2.3", 4444);
                out = new PrintWriter(kkSocket.getOutputStream(), true);
                in = new BufferedReader(new InputStreamReader(kkSocket.getInputStream()));
            } catch (UnknownHostException e) {
                System.err.println("Don't know about host.");
                System.exit(1);
            } catch (IOException e) {
                System.err.println("Couldn't get I/O for the connection.");
                System.exit(1);
            BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
            String fromServer;
            String fromUser;
            while ((fromServer = in.readLine()) != null) {
                System.out.println("Server: " + fromServer);
                if (fromServer.equals("Bye."))
                    break;
                fromUser = stdIn.readLine();
             if (fromUser != null) {
                    System.out.println("Client: " + fromUser);
                    out.println(fromUser);
            out.close();
            in.close();
            stdIn.close();
            kkSocket.close();
    }The code works fine with my internal IP (192.168.2.3) but not my external IP (86.3.51.171). Any ideas about how to fix it?

    Not quite sure I understand. Do you use the external IP with clients
    from the external network or with clients from the internal network?
    But regardless, I assume your Java code is correct since it works
    on the internal network. Try this command:
    telnet 192.168.2.3 4444
    from the internal network. I expect it to show "Server: ...", whatever the
    server sends. If this works, it means we can indeed use telnet to
    test connectivity. Now do:
    telnet 86.3.51.171 4444
    from the machine that gives you problems. If this does not work
    (connection lost or something like this), it means your Java code is OK
    and you need to do some configuration at your router.
    If this works, which I doubt, I am on the wrong track.

  • Server Socket does not read data input stream

    Hi all,
    I am very newbie to Java Network programming with sockets and multi-threading.
    But I am obliged to develop a chat system written in Applets which can be placed on the website and used by visitors who come to my website.
    In order to understand this, I have tested a basic web chat program I downloaded from the Internet which use sockets and multi-threadings. The program work fine, no bugs at all at both compilation and run time. I noticed that all three streams for Client side (i.e. first one is input stream used receiving data from User; the second one is socket input stream used for receiving data from Server socket, and the third is socket output stream used for writing data to server socket) were established. And the same, two socket streams (input & output) for Server side were also connected when running program giving right port number and IP address of the server.
    The problem is both server and client sockets do not read data using the following stream classes:
    1. DataStreamInput: I use input.readUTF() method
    2. or BufferedReader: I use input.readLine() method
    The example of the codes are below:
    private BufferedReader input = null;
    private PrintWriter output = null;
    private Socket socket = null;
    public void open() throws IOException
    {  input = new BufferedReader(new
    InputStreamReader(socket.getInputStream()));
    System.out.println("Server socket input stream was created, and");
    output = new PrintWriter(socket.getOutputStream());
    System.out.println("Server socket output stream was created");
    public void run()
    {  System.out.println("Server Thread " + clientPort + " running.");
    while (true)
    {  try
    System.out.println("Server is reading data from Client, wait...");
    String fromClient = input.readLine();
    System.out.println("Server received a message on " + clientPort + ".");
    catch(IOException ioe)
    {  System.out.println(clientPort + " ERROR reading: " + ioe.getMessage());
    server.remove(clientPort);
    stop();
    The problem is at the line: String fromClient = input.readLine(); in the run() method? What is wrong with the codes above?
    Note: I also try to use original codes which use readUTF() method in DataStreamInput class instead using readLine() in BufferedReader. Both methods dont read data from inputstream socket?
    I very appreciate any help/advice from experienced developers.
    Best regards

    Hi,
    Yes. The readLine() method hangs! After the test, the execuation of the program is stopped at the line of readLine() method; it does not pass it?
    There is no problem with writing to Server socket. After the test, the program pass through flush() method. Here is the code for writing to sever socket within ChatClient (client side socket) class:
    private BufferedReader input = null;
    private PrintWriter           output = null;
    public ChatClient(String serverName, int serverPort)
    {  System.out.println("Establishing connection. Please wait ...");
    try
    {  socket = new Socket(serverName, serverPort);
    System.out.println("Connected: " + socket);
    start();
    catch(UnknownHostException uhe)
    {  System.out.println("Host unknown: " + uhe.getMessage()); }
    catch(IOException ioe)
    {  System.out.println("Unexpected exception: " + ioe.getMessage()); }
    public void start() throws IOException
    {  input   = new BufferedReader (new
                             InputStreamReader(System.in));
    System.out.println("Client User input stream was created,");
    output = new PrintWriter(socket.getOutputStream());
    System.out.println("Client Socket output stream was established, and");
    if (thread == null)
    {  client = new ChatClientThread(this, socket);
    thread = new Thread(this);
    thread.start();
    public void run()
         while (thread != null) {
         String fromUser;
              try{
                   while((fromUser = input.readLine())!= null)
                   System.out.println("Client wasreading a data from User, and");
    output.println(fromUser);
         output.flush();
         System.out.println("Client has written a data to Server");
    catch(IOException ioe)
    {  System.out.println("Sending to server error: " + ioe.getMessage());
    stop();
    etc.
    Here is a piece of codes for reading data from the Client Socket in the ChatServer Class (Server Side socket):
    public void run()
    {  System.out.println("Server Thread " + clientPort + " running.");
    while (true)
    {  try
    {  //server.handle(clientPort, input.readLine());
    System.out.println("Server is reading data from Client, wait...");
    String fromUser = input.readLine();
    //while((fromUser = input.readLine()) != null)
         System.out.println("Server received a message on " + clientPort + ".");
    catch(IOException ioe)
    {  System.out.println(clientPort + " ERROR reading: " + ioe.getMessage());
    server.remove(clientPort);
    stop();
    etc. Please advice why the readLine() method hangs; does not read data from the input stream received from the CLIENT?

  • Reading text from server socket stream

    I have a basic cd input program i've been trying to figure out the following problem for a while now, the user enters the artist and title etc and then a DOM (XML) file is created in memory this is then sent to the server. The server then echos back the results which is later printed on a html page by reading the replys from the server line by line.
    The server must be run it listens for clients connecting the clients connect and send DOM documents through the following jsp code.
    <%@page import="java.io.*"%>
    <%@page import="java.net.*"%>
    <%@page import="javax.xml.parsers.*"%>
    <%@page import="org.w3c.dom.*"%>
    <%@page import="org.apache.xml.serialize.*"%>
    <%!
       public static final String serverHost = "cdserver";
       public static final int serverPort = 10151;
    %>
    <hr />
    <pre>
    <%
            Socket mySocket = null;          // socket object
            PrintWriter sockOut = null;      // to send data to the socket
            BufferedReader sockIn = null;    // to receive data from the socket
            try {
                //  #1 add line that creates a client socket
                mySocket = new Socket(serverHost, serverPort);
                // #2 add lines that create input and output streams
                //            attached to the socket you just created
                 sockOut = new PrintWriter(mySocket.getOutputStream(), true);
                 sockIn = new BufferedReader(new InputStreamReader(mySocket.getInputStream()));
            } catch (UnknownHostException e) {
                throw e; // This time the JSP can handle the exception, not us
            } catch (IOException e) {
                throw e; // This time the JSP can handle the exception, not us
    String cdTitle, cdArtist, track1Title, track1Time, track1Rating;
    // Retrieve the HTML form field values
    cdTitle = request.getParameter("cdtitle");
    cdArtist = request.getParameter("cdartist");
    track1Title = request.getParameter("track1title");
    track1Time = request.getParameter("track1time");
    track1Rating = request.getParameter("track1rating");
    // Create a new DOM factory, and from that a new DOM builder object
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    // Note that we are creating a new (empty) document
    Document document = builder.newDocument();
    // The root element of our document wil be <cd>
    // It gets stored as the child node of the whole document (it is the root)
    Element rootElement = document.createElement("cd");
    document.appendChild(rootElement);
    // Create an element for the CD title called <title>
    Element cdTitleElement = document.createElement("title");
    // Add a text code under the <title> element with the value that
    // the user entered into the title field of the web form (cdTitle)
    cdTitleElement.appendChild(document.createTextNode(cdTitle));
    // Place the <title> element underneath the <cd> element in the tree
    rootElement.appendChild(cdTitleElement);
    // Create an <artist> element with the form data, place underneath <cd>
    Element cdArtistElement = document.createElement("artist");
    cdArtistElement.appendChild(document.createTextNode(cdArtist));
    rootElement.appendChild(cdArtistElement);
    // Create a <tracklist> element and place it underneath <cd> in the tree
    // Note that it has no text node associated with it (it not a leaf node)
    Element trackListElement = document.createElement("tracklist");
    rootElement.appendChild(trackListElement);
    // In this example we only have one track, so it is not necessary to
    // use a loop (in fact it is quite silly)
    // But the code below is included to demonstrate how you could loop
    // through and add a set of different tracks one by one if you
    // needed to (although you would need to have the track data already
    // stored in an array or a java.util.Vector or similar
    int numTracks = 1;
    for (int i=0; i<numTracks; i++) {
      String trackNum = Integer.toString(i+1);
      Element trackElement = document.createElement("track");
      trackElement.setAttribute("id", trackNum);
      trackListElement.appendChild(trackElement);
      // Track title element called <title>, placed underneath <track>
      Element trackTitleElement = document.createElement("title");
      trackTitleElement.appendChild(document.createTextNode(track1Title));
      trackElement.appendChild(trackTitleElement);
      // Track time element called <time>, placed underneath <track>
      Element trackTimeElement = document.createElement("time");
      trackTimeElement.appendChild(document.createTextNode(track1Time));
      trackElement.appendChild(trackTimeElement);
      // Track rating element called <rating>, placed underneath <track>
      Element trackRatingElement = document.createElement("rating");
      trackRatingElement.appendChild(document.createTextNode(track1Rating));
      trackElement.appendChild(trackRatingElement);
    OutputFormat format = new OutputFormat();
    format.setIndenting(true);
    // Create a new XMLSerializer that will be used to write out the XML
    // This time we will serialize it to the socket
    // #3 change this line so that it serializes to the socket,
    // not to the "out" object
    XMLSerializer serializer = new XMLSerializer(writer, format);
    serializer.serialize(document);
            // Print out a message to indicate the end of the data, and
            // flush the stream so all the data gets sent now
            sockOut.println("<!--QUIT-->");
            sockOut.flush();
            BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
            String fromServer;
            String fromUser;
             #4 add a while loop that reads text from the
            server socket input stream, line by line, and prints
            it out to the web page, using out.println(...);
            Note that because the reply from the server will contain
            XML, you will need to call upon the toHTMLString() method
            defined below to escape the < and > symbols so that they
            will display correctly in the web browser.
            Also note that as you receive the reply back from the
            server, you should look out for the special <!--QUIT-->
            string that will indicate when there is no more data
            to receive.
            while ((fromServer = sockIn.readLine()) != null) {
            out.println(sockIn.readLine());
                // If the reply from the server said "QUIT", exit from the
                // while loop by using a break statement.
                if (fromServer.equals("QUIT")) {
                    out.println("Connection closed - good bye ...");
                // Print the text from the server out to the user's screen
                out.println("Reply from Server: " + fromServer);
                // Now read a line of text from the keyboard (typed by user)
                fromUser = stdIn.readLine();
                // If it wasn't null, print it out to the screen, and also
                // print a copy of it out to the socket
                if (fromUser != null) {
                    out.println("Client: " + fromUser);
                    sockOut.println(fromUser);
            // Close all the streams we have open, and then close the socket
            sockOut.close();
            sockIn.close();
            mySocket.close();
    %>
    I'm suppose to modify the commented sections labled with #.
    #1,2 are correct but i have doubts on the 3rd and 4th modification.
    for #3 i changed so i serializes to the socket not to the "out" object:
    from
    XMLSerializer serializer = new XMLSerializer(out, format);
    to
    XMLSerializer serializer = new XMLSerializer(writer, format);
    with "out" it prints out some of the results entered but it just hangs i'm thinking it might be the while loop that i added in #4. If i changed it to serialize the socket XMLSerializer serializer = new XMLSerializer(writer, format); it doesn't print out nothing at all; just a blank screen where it hangs.
    I can post the rest of the code (server thats in java and cdinput.html) but since i want to keep my post short and if required i'll post it later on i also omitted some of the code where it creates the DOM textnodes etc to keep my post short.

    On your previous thread, why did you say the server was using http POST and application/xml content type when it quite obviously isn't, but a direct socket communication that abuses XML comments for message end delimiters?
    The comments imply you need to wait for "<!--QUIT-->" on a line by itself, but your loop is waiting for "QUIT".
    Pete

  • Content Server connection problems

    SAP Content Server connection problems
    I have installed the SAP Content Server on a Windows 2003 server. I connected to the Max DB on the remote server from Database Manager on my PC. I created repositories in R/3 in OAC0 and CSADMIN and saved documents to the Content Server. This all took a few hours from O/S install to saving a document in the repository, so I do understand the basics of the Content Server and Max DB.
    Unfortunately we are not going to use Windows; we will be running this on UNIX. Therefore I'm trying it out on a Linux system while I wait for the AIX system to be available. It's been a long road but I have finally gotten the install to finish 'successfully' however I can't connect from R/3.
    When I run the check http://10.XXX.YYY.ZZZ:1090/ContentServer/ContentServer.dll?serverInfo from the browser on the Linux host I get back a good status as shown below:
    serverType="SAP HTTP Content Server";serverVendorId="SAP AG";serverVersion="640";serverPatch="0";serverBuild="16";pVersion="0046";serverStatus="running";serverDate="2008-03-25";serverTime="22:39:45";startUpDate="2008-03-25";startUpTime="22:32:21";lastAccessDate="2008-03-25";lastAccessTime="22:38:33";
    However when I do this from any my PC it won't connect. (Of course the real problem is I can't connect from R/3.)
    If I try the same URL from a different user session on the same Content Server Linux host I get the same good status.
    I thought maybe the httpd.conf file was wrong so I tried:
    Listen 0.0.0.0:1090
    In cs.conf I tried commenting out AdminSecurity & AdminSecurityGroup.
    I also changed StorageDriver from SAPDBStorage to FSStorage.
    I don't know if this is related or just another problem to tackle once I can get through this one. I was not able to add the new system to the Database Manager. I get the error "-4 could not connect to socket [10060]".
    Thanks to all for any help. Points will dutifully be rewarded.
    David

    Hi Henk,
    It looks like I am dumber than a rock. The firewall was indeed active on the Linux host. I turned it off and can now do the http connection test to the Content Server. (I awarded very helpful points.)
    I still can't connect to the database with the Database Manager however the message has changed; it now says "-4 XSERVER might be inactive". I just turned off the firewall so I have a few things to try, like figure out how to start MaxDB without the DB Manager. I'll post my progress. Thanks Henk.
    David
    Edited by: Dave Hill on Mar 28, 2008 12:00 AM
    Now I have installed the Database Studion on my PC. No I'm getting this message when I try to connect to the host/database on the Linux system: "Cannot connect to host 10.XXX.XXX.XXX:7210 [Connection refused: connect], -813."
    Does MaxDB need to be started to connect? Any idea how to start it manually? Thanks,
    David
    Edited by: Dave Hill on Mar 28, 2008 1:06 AM
    Ah, at long last. There's this tiny yet very important little program called x_server that SAP didn't include in the SAP Content Server install guide. This needs to be running in order for anything to connect. I'm sure most of you know about it but for the rest you can find it in:
    /sapdb/programs/bin
    Then type
    ./x_server start
    I'm not sure what user it should run under but I started it as the sdb user.
    You could automate the database startup with a script. See http://maxdb.sap.com/doc/7_7/e9/005dac1592496783e26133eb7fad0b/frameset.htm
    Thank you Henk, I'll call this problem solved and award points.
    Edited by: Dave Hill on Mar 28, 2008 2:10 AM

  • Can't open HTTP server socket on port 50000 in dispatcher

    We get the following message in the console_log for the dispatcher.
    ID000544: Error starting service http. Can't start the service due to java.io.IO
    Exception: Can't open HTTP server socket on port 50000
    [ServiceManager]: ID000544: Error starting service http. Can't start the service
    due to java.io.IOException: Can't open HTTP server socket on port 50000
    [Framework -> criticalShutdown] Service http startup error!
    Anyone have any ideas what might be the problem?
    Thanks,
    Keith

    Hello Keith,
    this errors occurs when the port http 50000 is already taken. Please could you check if this port on your machine is free or an other dispacther instance is already started on same machine. You can change the port in sap j2ee config tool (dispatcher-> services->http)
    Best Regards,
    Fabrice

  • Sockets problem

    Hi ,
    I written a server class that simply writes the numbers and the client simply reads those numbers and prints them. When I run the both client and server on tha same machine there is no data loss found. But when I run the server on different machine than client I found heavy dataloss.(while theserver written numbers from 1-9000 the client is able read only 6000 plus). The data loss is increased when the data read from the server socket created by the VB application. Here with i am pasting the code snippet for the Server and the Client java files . Please help me in solving this problem.
    Client.java
    import java.net.*;
    import java.io.*;
    public class Client
         static Socket client = null;
         ObjectInputStream is = null;
         public Client() throws Exception
              client = new Socket("rajsekhar",3333);
              is = new ObjectInputStream (client.getInputStream());
              while(true){
                   Integer in = (Integer)is.readObject();
                   System.out.println(in.toString());
         public static void main(String[] args) throws Exception
              new Client();
    Server.java
    import java.net.*;
    import java.io.*;
    public class Server
         public static void main(String[] args) throws Exception
              ServerSocket server = null;
              server = new ServerSocket(3333);
              Socket s = server.accept();
              ObjectOutputStream os = new ObjectOutputStream(s.getOutputStream());
              int i =1;
              while(true)
                   os.writeObject(new Integer(i));
                   System.out.println(i);
                   i++;
    please help me .
    thanks in advance,
    Sridhar Reddy .R

    This has nothing to do with JSSE; please post in a more appropriate forum.

  • Serversock/socket problem pls Help

    Hi all,
    I have a serversocket that accepts client's connections, reads from this stream, processes the data and sends back response to the client. This works fine for a standard scenario.
    The problem occurs if for some reason the client looses connection after writing to the serversocket. The server behaves as if nothing happens and sends back the response. I want the server to be able to detection any connection loss and report back. My code snippet is shown below
    ServerSocket server;
    Socket conn;
    BufferedReader input;
    PrintWriter out;
    try{
    server= new ServerSocket(4550,10);
    conn=server.accept();
    input = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    String data=input.readLine();
    process data .....
    out = new PrintWriter(conn.getOutputStream(), true);     
    out.println(processed_data);
    }catch(IOException e){
    e.printStackTrace();
    }finally{
    try{
    input.close();
    out.close();
         conn.close();
         }catch(Exception uncaught){}
    If during process data, the client looses connection, the program behaves as if the connection still exist. Any suggesion would be highly appreciated
    Regards
    Tim

    err, yeah, i got that bit....
    and there is nothing, nothing at all in java, C, C++, any and i mean ANY TCP/IP programming that can tell if the client has been unplugged without trying to send something to it
    you can use a keepAlive in Socket to automatically occasionally send a dummy packet (for which it expects a response)
    but apart from that the Socket cannot know it is not connected unless it recieves indication from the client (the end that is closed first sends a FIN packet and the other end replies with ACK FIN)
    a pair of Sockets connectd through a network does not get a permanent physical connection, they give the impression of such by exchanging packets with sequence numbers and ack numbers coresponding to the last packet recived.
    if neither Socket has nothing to send, nothing is sent and it is assumed that the connection is still valid, so isConnected() will return true unless it actually knows that the client has closed the connection or an Exception occured when it tried to send something
    isConnected() does not test the connection, just reports true if it has been connected and there has not been an IOException or either end has closed
    maybe you could explain why you need to avoid sending the response if the client has been unplugged?

  • 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

  • Should i create a client and a server socket in a same application

    Greetings,
    In which situation sould i have a server socket ? and in which situation should i have a client socket ?and in which situation should i have both?
    I 'm making a app. who receives info (like alarms ) from a automation machine and also that same app. as a scheduler who send commands according to dates to the automation machine.
    Now the automation machine is programmed like a socket tcp/ip server who is always on and the app. is a client.
    Every time there's an alarm the machine sends me the info and i put it in a mysql database.
    Every time there's an event programmed the app. sends a string to the machine.
    The question is that i can't maintain that socket always connected, Sometimes disconnets.
    I was thinking of making the change of creating in both sides a server and a client, so that, for example, in the app. the client woul d handle the event msgs and the server would accecpt connections with alarms from the automaition machine.
    Since i'm a newbie in Java could somebody give me some tips, please?
    Thanks

    Thanks Peter....
    But i already do that....
    I have a thread who handles the connection management.
    If by some reaseon the connection is lost the thread reconnects it.
    My problem is that sometimes it reconnects every second, and i loose info provided by the automatian machine.
    The best thing to have it would be a socket listener, but Java does have any.
    Is there any API that does a socket listener?

  • Server Socket Leaks on stopping Java Processes

    I have a strange problem on Windows 2000 Advanced Server with JDK1.5.10. Our application runs on a Tomcat 5.5.12 and is opening 2 server sockets along with Tomcat's own 8080 port. Also we deployed a stand alone application that also opens a server socket. Whenever we stop Tomcat service or our Application service (Windows services) these server sockets are not getting closed. If we use "netstat" to check if any sockets are still open it is NOT showing any sockets.
    But when we use "netstat -a" command it is showing entries like
    TCP    10.40.1.162:8080    10.40.1.162:0  LISTENING
    TCP    10.40.1.162:22222    10.40.1.162:0  LISTENING
    TCP    10.40.1.162:33334    10.40.1.162:0  LISTENINGHere 8080 (tomcat), 22222, 33334 are the ports on which the server sockets are opened earlier. We check in Task Manager but there is no java process running. If we try to restart the same java process it is throwing JVM_Bind exception. If we reboot the box the we are able to restart the services. Similar behaviour we observed sometimes on Linux also. I guess some settings in the OS we need to tweak to fix this issue. Can somebody please help me what are those settings for Windows and Linux platforms which reclaims unused server sockets faster??

    The state is LISTENING not TIME_WAIT. There is a cleanly closure of sockets provided in the code. It happens to Tomcat's own ports also. If you telnet to these sockets from another box, it is connecting and staying instead of "Connection Failed" error. But in Task Manager or "Services.msc" Console no service or process running! One more observation is that there is heavy load of threads and a huge number of clients socktets were interacting with these sockets just before shutdown.

Maybe you are looking for