Is code in ParserCallback executed in a different thread?

Hello everybody,
I have a question regarding the javax.swing.text.html.HTMLEditorKit.ParserCallback class. I 've read that parsing an HTML page using HTMLEditorKit.Parser.parse() isn't taking place in the same thread as the code in the HTMLEditorKit.ParserCallback class (of course, in my case, a subclass). Therefore I shouldn't assume that the HTML page is completely parsed when HTMLEditorKit.Parser.parse() returns. Can anyone confirm this?
I did read the source, but to me it seems that parsing and callback is taking place in the same thread :-|
Thanks,
KeRMiT1281

My Vote is no, altho since this parser is replaceable, perhaps others are free to do that. But here's a test with the default one.
import javax.swing.text.*;
import javax.swing.text.html.*;
import java.io.*;
public class HTMLParserTest
     static class MyKit extends HTMLEditorKit
          public HTMLEditorKit.Parser cheat()
               return getParser();
     public static void main(String[] args)
          try
               MyKit kit = new MyKit();
               HTMLEditorKit.Parser p = kit.cheat();
               StringReader sr = new StringReader("<html><body><a href='foo'>bar</a></body></html>");
               HTMLEditorKit.ParserCallback cb = new HTMLEditorKit.ParserCallback()
                    public void handleStartTag( HTML.Tag t, MutableAttributeSet a, int pos )
                         System.out.println( "Callbacks thread " + Thread.currentThread().toString());
               System.out.println( "Main thread " + Thread.currentThread().toString());
               p.parse(sr, cb, true);
          catch (Exception e)
               e.printStackTrace();
}

Similar Messages

  • Different execute queues with different thread priorities

    We are running WebLogic 6.1, SP2 on Solaris 2.8 and I have a question related to the
    use of Execute queues
    I'm aware that the administration console servlets, and the rest of requests given
    to the server run in separate execution queues each with their own pool of threads.
    There is an <executequeue> element in the config.xml that allows you to change the
    parameters of the default execute queue that most requests are handled in.
    My question is is it possible to create new execute queues, each with a given number
    of threads running at a different priority. Then one could assign a particular WAR
    deployment to a queue and hence control the priority that certain requests run at
    governed by the deployment that received the initial request.
    Essentially the problem that I'm trying to address is that I have a JAR with MDBs
    in it. I also have JARs with Entity and Session EJBs and WARs. They are all using
    the same pool of threads to execute. I want to be able to throttle the MDBs as they
    receive messages so they don't take over the machine and interfere with interactive
    use. Now I can limit the number of MDBs in the MDB pool, but then if the machine
    is not being used by users, then the machine resources are wasted only allowing one
    MDB to be active at a time when there are a lot of messages in the queue.
    What I want to be able to do is to have as many MDBs run as I can, up to a certain
    limit, say 15 for example, but not to pull from the same thread pool/execute queue
    as the requests for URLs in the WAR. Also I want the MDB threads to run at a much
    lower priority and always give preference to interactive requests.
    So interactive threads will always win and grab the processors if interactive use
    is high, but if it's not, the MDBs can run instead.
    Regs,
    Paul

    Hi,
    I had a chat with BEA support about my issue. You can create multiple ExecuteQueues
    and assign them to servlet definitions in WARs in the web.xml, and with an option
    to the EJBC compiler, you can assign a particular class of EJB to an ExecuteQeueue.
    For details see http://e-docs.bea.com/wls/docs61/perform/AppTuning.html#1106284
    Presumably it's the thread of the initial request that counts, i.e. if a WAR calls
    an EJB, then it's the thread in the execute queue of the WAR that will be used right
    the way through the request, not that of the EJB being called, assuming they are
    both deployed in the same WebLogic instance. If they were in different instances,
    you would obviously have a thread from the WAR queue on one instance, and a thread
    from the EJB queue on another instance.
    If a plain Java command-line client connected directly to an EJB, then it would be
    the thread from the ExecuteQueue of the EJB that would get used.
    I've been told that MDBs always run in the default queue, so it seems that the way
    for me to do what I want is just to create an ExecuteQueue, set the priority of the
    threads in this queue to be higher than that of the default queue, and assign this
    queue to my WARs. I can leave my EJBs running in the default queue.
    Regs,
    Paul
    "Dimitri I. Rakitine" <[email protected]> wrote:
    Don't know about 6.1 (One can find out very easily what the possible config
    parameters
    are by deploting
    http://dima.dhs.org/misc/listMBeans.jsp and
    http://dima.dhs.org/misc/showMBean.jsp
    abd looking at the XXXConfig mbeans), but in 7.0 there are quite a few
    things which
    can be tuned in the executequeue config (and priority is one of them. also
    interesting
    is that it is possible to configure it to increase number of execute threads
    when queue
    length exceeds some specified threshold) :
    QueueLength
    Returns the maximum length of this queue.
    ThreadPriority
    Returns the priority of the threads associated with this queue.
    ThreadCount
    Returns the number of threads assigned to this queue.
    QueueLengthThresholdPercent
    Returns the threshold percent for length of this queue, set in QueueLength.
    ThreadsIncrease
    Returns the number of threads to grow when a queue is within QueueLengthThresholdPercent
    of the set QueueLength.
    ThreadsMaximum
    Returns the maximum number of threads in the pool.
    ThreadsMinimum
    Returns the minimum number of threads in the pool.
    Dimitri

  • Run sql query on a different thread

    Hello,
    I have a swing app that queries an MS SQL database and it works fine and everything happens in the same thread. However for improved performance and to avoid freeze ups, I want the SQL queries themselves to execute on a different thread as a different class, other than the swing app class. The query results (Result Set) I want them back to my swing app so I can present them on a JTable.
    Here is an example of what I am trying to accomplish:
    - Press button in my swing app.
    - Call class that implements Runnable
    - In the Run method of the new class do the following (this code will execute in a new thread):
    url = "jdbc:sqlserver://ServerName:1433;databaseName=Database;user=UserName;password=password";
    try{
         Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
         Connection con = DriverManager.getConnection(url);
         Statement stmt;
         ResultSet rs;
         stmt = con.createStatement();
         String queryString = "select * from databaseName";
         rs = stmt.executeQuery(queryString);
          con.close();
    catch(Exception em){
          em.printStackTrace();
         JOptionPane.showMessageDialog(null,em.toString());
    }- Get the ResultSet rs back from the class
    - Work with the results back in my swing app and present them in the JTable
    while(rs.next()){
                //do some stuff
         }Any help or hints are greatly appreciated.
    Thanks,
    Chris

    Two suggestions:
    -- Take a look at SwingWorker for taking care of the threading issues
    -- Keep all database handling code together. Collect the records into a Collection -- most likely ArrayList -- and return that. This way you can close the Connection and RecordSet within the same method that opens them.
    Just my 0.02.
    db

  • How to set up a pdf embeded with different code so that people can get different excess code after they paid on-line?

    For example, I want to set up a pdf embeded with code, and send it on-line. People who want it should pay for it first and get the access code. I need to set different access code in order to avoid people A give the access to people B.

    Unless you use a very expensive DRM protection measure, I don't see how it's possible. How can you prevent someone from sending a file with the password to someone else?

  • Double contacts as "iPhone"...my phone saves the same number twice, once with a 1 before the area code and one without it. It causes two different threads in my texts even of they're saved as the same contact

    my phone saves the same number twice, once with a 1 before the area code and one without it. It causes two different threads in my texts even of they're saved as the same contact

    My wife is having the same problems as a reciever. She works in a school as a teaching assistant and her teacher sends messages that are mixed with previous texts from ages ago.
    Can anyone shed some light on this problem or is it only her and this poster?
    2m42s

  • Call to java bean but code not being executed.

    Making a call to my javabean class called ch06_03.java from a jsp program shown below:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Using a java package.</title>
    </head>
    <body>
    <% beans.ch06_03 messager = new beans.ch06_03(); %>
    The message is: <%= messager.msg() %>
    </body>
    </html>
    The call from jsp to javabean program is only returning the hello from java and NOT EXECUTING ANY OF THE CODE in the msg() method. I am checking my table landings_hold and nothing is there, my log file shows nothing. Why is the code not being executed except for the return statement?
    My javabean program is shown below:
    package beans;
    import java.io.*;
    import java.util.*;
    import java.text.*;
    import java.sql.*;
    public class ch06_03 {
    StringTokenizer st1;
              String val1, val3, val4, val5, val9, val10, val11, val12, val13, val14, val16;
              String val2, val6, val7, val8, val15, val17, val18, val19, val20;
              int cnt;
              String filetext = "Starting RIFIS Upload";
              java.util.Date d = new java.util.Date();
              SimpleDateFormat form = new SimpleDateFormat("dd/MMM/yyyy hh:mm:ss");
              String dateString = form.format(d);
    public String msg() throws Exception {
         try {
         Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
    Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@xxxxx.xxxx.xxx:1521:xx","xxxxxx","xxxx");
              Statement st = conn.createStatement();
         File f = new File("C://upload");
              FileWriter outFile = new FileWriter("C://RIFIS/log/logfile.txt", true);
              outFile.write(System.getProperty("line.separator"));
              outFile.write(filetext+" - "+dateString);
              if (f.isDirectory())
              { String [] s = f.list();
              for (int i=0; i<s.length; i++)
              { outFile.write(System.getProperty("line.separator"));
                   outFile.write("Found file - "+f+"/"+s);
              FileReader file = new FileReader(f+"/"+s[i]);
                   File inputFile = new File(f+"/"+s[i]);
                        File outputFile = new File("C://RIFIS/archive/"+s[i]);
                   BufferedReader buff = new BufferedReader(file);
                   boolean eof = false;
                   String val0="";
                   ResultSet rec = st.executeQuery("SELECT landings_hold_batch_seq.nextval FROM dual");
                        while(rec.next())
                        { val0 = rec.getString(1); }
                        cnt=0;
                        while (!eof)
                        { String line = buff.readLine();
                        if (line == null)
                        { eof = true; }
                             else
                             { cnt = cnt+1;
                                  st1 = new StringTokenizer(line,",");
                                  val1 = st1.nextToken();
                                  val2 = st1.nextToken();
                                  val3 = st1.nextToken();
                                  val4 = st1.nextToken();
                                  val5 = st1.nextToken();
                                  val6 = st1.nextToken();
                                  val7 = st1.nextToken();
                                  val8 = st1.nextToken();
                                  val9 = st1.nextToken();
                                  val10 = st1.nextToken();
                                  val11 = st1.nextToken();
                                  val12 = st1.nextToken();
                                  val13 = st1.nextToken();
                                  val14 = st1.nextToken();
                                  val15 = st1.nextToken();
                                  val16 = st1.nextToken();
                                  val17 = st1.nextToken();
                                  val18 = st1.nextToken();
                                  val19 = st1.nextToken();
                                  val20 = st1.nextToken();
                                  st.executeUpdate("INSERT INTO LANDINGS_HOLD (lh_id, lh_batch, supplier_dr_id, supplier_unique_id, supplier_dealer_id, supplier_cf_id, supplier_vessel_id, unload_year, unload_month, unload_day, state_code, county_code, port_code, itis_code, market, grade, reported_quantity, unit_measure, dollars, lh_loaddt, lh_loadlive, purch_year, purch_month, purch_day)" +
                        "VALUES (0,'"+val0+"','"+val1+"',"+val2+",'"+val3+"','"+val4+"','"+val5+"',"+val6+","+val7+","+val8+",'"+val9+"','"+val10+"','"+val11+"','"+val12+"','"+val13+"','"+val14+"',"+val15+",'"+val16+"',"+val17+",SYSDATE,NULL,"+val18+","+val19+","+val20+")");
                             } // while else end
                        } // parent while end
                        FileReader in = new FileReader(inputFile);
                        FileWriter out = new FileWriter(outputFile);
    int c;
                        while ((c = in.read()) != -1)
                        { out.write((char)c); }
                        in.close();
                        out.close();
                        outFile.write(System.getProperty("line.separator"));
                        outFile.write("Number of records inserted - "+cnt);
                        outFile.write(System.getProperty("line.separator"));
                        outFile.write("Copied upload file to archive directory");
                        outFile.write(System.getProperty("line.separator"));
                        outFile.write(f+"/"+s[i]+" - Has been removed from upload directory");
                        buff.close();
                        inputFile.delete();
                   } // for end
                   outFile.write(System.getProperty("line.separator"));
                   outFile.write("Upload Complete...NO ERRORS");
                   outFile.write(System.getProperty("line.separator"));
                   outFile.write("*************************************************************");
                   outFile.write(System.getProperty("line.separator"));
                   conn.close();
              } // if end
              else
              { outFile.write("No files to process"); }
              outFile.flush();
              outFile.close();
              } // try end.
              catch(Exception e)
              { FileWriter errFile = new FileWriter("C://RIFIS/log/errfile.txt", true);
              errFile.write(System.getProperty("line.separator"));
              errFile.write("ALERT....ALERT....ALERT");
              errFile.write(System.getProperty("line.separator"));
              errFile.write("Error Occurred in ReadSource.java - RIFIS Upload");
              errFile.write(System.getProperty("line.separator"));
              errFile.write("My Error: " + e);
              errFile.write(System.getProperty("line.separator"));
              errFile.write("*************************************************************");
                   errFile.flush();
                   errFile.close();
              } // catch exception end.
         return "Hello from java";
         } //public msg block
         public ch06_03()

    Since you didn't use code-formatting tags ([ code ] and [ /code ] without the spaces) it's kinda hard to look at it. But I'm sure it DID execute much more than just the return statement - maybe you're not closing a file or db connection, or maybe you're seeing a cached page, so it actually isn't executing ANYTHING on the server (is your browser set to never check for newer pages so it (almost) always returns from cache, for example?)

  • What does this mean and how do I fix it? Error ITMS-9000 "Invalid Code Signing The executable ´viwer.app/ viewer´ must be signed with the certificate that is contained in the provisioning profile"

    What does this mean and how do I fix it? Error ITMS-9000 "Invalid Code Signing The executable ´viwer.app/ viewer´ must be signed with the certificate that is contained in the provisioning profile"

    If you had Firefox save your Yahoo password, first try deleting that here:
    orange Firefox button ''or'' classic Tools menu > Options > Security > "Saved Passwords"
    The "signed out" message seems to be related to how Yahoo authenticates you. Some users have reported that disabling automatic proxy detection solves the problem, and it also resolves an issue of getting logged out every few minutes, if you have ever experienced that.
    To make the change:
    orange Firefox button ''or'' classic Tools menu > Options > Advanced
    On the "Network" mini-tab, click the "Settings" button, then choose "No Proxy" and OK your way back out.
    If your work connection requires you to use a proxy server, try the "Use system settings" option instead.
    Does that help?

  • Unhandled exception was thrown by the sandboxed code wrapper's Execute method in the partial trust app domain

    Hi All,
      I have created a custom web part in VS 2008 for Share point server 2010 with DevExpress v12.2.17, and deployed as Sandboxed solution. when i add that web parts in web part zone i am getting the error as "Web Part Error:
    Unhandled exception was thrown by the sandboxed code wrapper's Execute method in the partial trust app domain: An unexpected error has occurred. ".
    If there is any way to get detailed error either log file or event viewer.
    Kindly advice to find the cause of the problem.
    Thanks,
    Selvakumar.S

    Hello,
    Are you impersonating your code? Have you tried to debug your code by attaching SPUCHostService.exe? if not please do so.
    You also need to check ULS log for more information about this error. Here is one ref link if this could help
    http://sohilmakwana.wordpress.com/2013/11/29/sandbox-error-unhandled-exception-was-thrown-by-the-sandboxed-code-wrappers-execute-method-in-the-partial-trust-app-domain/
    Hemendra:Yesterday is just a memory,Tomorrow we may never see
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

  • HT201210 I am using a 3GS iphone.While attempting a download of the new OS IO6 my phone has frozen on the itunes screen. When i attempt to restore I get the Error code 1611. This happens on different laptops. I've followed all the given resolutions with n

    I am using a 3GS iphone. While attempting a download of the new OS IO6 my phone has frozen on the itunes screen. When i attempt to restore I get the Error code 1611. This happens on different laptops. I've followed all the given resolutions with no change.I am using a 3GS iphone.While attempting a download of the new OS IO6 my phone has frozen on the itunes screen. When i attempt to restore I get the Error code 1611. This happens on different laptops. I've followed all the given resolutions with no change?

    If you are having the same issue on several computers then it is a hardware issue! Not a software issue! Replacement is the only resolution!
    http://support.apple.com/kb/index?page=servicefaq&geo=United_States&product=ipho ne

  • Workflow 2013 execute as a different user

    I have seen references on the internet where workflow 2013 can execute as a different user. This is referred to 'as on the behalf of'. I believe there is somewhere on the main site collection page where this can be setup at. Thus since I am a site administrator
    on my own collection, would you show me from the site administration page where I can setup the access for 'as on the behalf of'?

    Hi jazz, I don't believe there's a way to do this out of the box. You may also be talking about an impersonation step in a SharePoint Designer workflow. See the following link for reference:
    https://social.technet.microsoft.com/Forums/sharepoint/en-US/f2140235-887f-45a7-8264-566372b81fe9/sharepoint-2013-users-work-on-behalf-of-another?forum=sharepointgeneral
    cameron rautmann
    Actually it may be possible, but I haven't tried this:
    https://msdn.microsoft.com/en-us/library/w070t6ka.aspx

  • TS3694 my i pad is showing connect to i tunes picture when i connect to i tunes it tells me i need to restore, but when i do it keeps coming up with error code!! which is a different one each time can anyone offer some advise to solve this frustrating pro

    my i pad is showing connect to i tunes picture when i connect to i tunes it tells me i need to restore to factory settings, but when i do it keeps coming up with error code!!   which is a different one each time can anyone offer some advise to solve this frustrating problem.

    iPad: Basic troubleshooting
    http://support.apple.com/kb/TS3274
    iTunes: Specific update-and-restore error messages and advanced troubleshooting
    http://support.apple.com/kb/TS3694
     Cheers, Tom

  • Any reason why my code isn't executing the "stop" action?

    Any reason why my code isn't executing the "stop" action?
    sym.getComposition().getStage().getSymbol("_001").$("_002").$("_003").bind('mouseenter',fu nction(e){
    e.preventDefault();
    $(this).unbind('mouseenter');
    sym.getComposition().getStage().getSymbol("_001").$("_002").$("_003").stop("over");
    See my file here http://twistedpancreas.com/edge/misc/dropDownNotWorking.zip
    The dropdown should change to orange when rolled over, but it's not
    Any help is appreciated.

    Thanks rhemanthkumar,
    so .$ should only be referenced in the last mention of a symbol, all others should be .getSymbol ?

  • Invoking method on different thread

    Hi
    I'm developing an addin a application. The addin runs on the main thread. However I need to perform some blocking system calls, which can't be called from the main thread, since it also blocks the application. Therefore, I have a worker thread which performs the blocking call. When the blocking call returns, I need to invoke a method on the main thread. The method must be executed by the main thread, because the method uses some of the applications api functions. If these api functions are called from any other thread than the main thread, the application will crash.
    My problem is that I dont know how to invoke a method on a different thread. I guess I need to do the same thing as the SWING package, where gui components should be modified from the event dispatcher thread.
    Simplyfied, my code looks something like this:
    public class Main
        public static void main(String[] args)
           Main m = new Main();
           m.Test();
        public void Test()
            //runs on main thread here
            //start a new thread which blocks while waiting for user input (simulate my service)
            ThreadClass tc = new ThreadClass();
            new Thread(tc).start();
            while (true)
               //perform normal work on gui thread
               Thread.yield();         
       public void MethodNeedsToRunOnMainThread(int c)
           //Do something on main thread here
    public class ThreadClass implements Runnable
        public void run()
            ThreadFunction();
        public void ThreadFunction()
            int c = System.in.read(); //blocking call
            //Invoke method on main thread here!   
            MethodNeedsToRunOnMainThread(int c);
        }Hope some of you might point me in the rigth direction!
    \Bjarne

    pdm wrote:
    Using a BlockingQueue, the main thread will block while waiting for something to be put in the queue by the worker thread. This will block the program in which my add-in runs, since the main thread is responsible for gui updates etc. Therefore, this is not an option.
    Maybe it is simply not possible to what I need.
    \Bjarnedepending on what kind of responsiveness you need, you could make your add-in periodically check for these events. call poll() instead of take(), and then continue on with your add-in if poll() returns nothing. the frequency with which your code polls the queue will determine the lag between queueing from the other thread and executing on the main thread.

  • Running the TSQCallback function in a different thread?

    Hi,
    I am looking at the example code directPtrAccess.c where the TSQcallback function is set to be executed in the same thread that generates the data. However, in application, I would like to run the call back function in a separate thread.
    I would greatly appreciate if some one can clarify whether this is possible and if yes how it should be done?
    Thanks!
    Sripad

    In that example the TSQ callback is not executed in the generation thread: it is executed in the main thread instead.
    The generation thread is unknown (the thread ID is not saved in any variable) but is it different from the main thread, which is the one that handles the user interface.
    As you can see, the TSQ callbacl is installed receiving CmtGetCurrentThreadID() in Callback Thread ID; that is to say, it receives the ID of the main thread and executes there.This is a very common situation, where generation / acquisition of data and other tasks are executed in a separate thread and presentation of data and UI handling are executed in the main thread.
    If you had previously created a different thread and saved its ID, you could pass it in this parameter and obtain the callback to run in that thread.
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • Problem using a GUI, a loop and a different thread for the loop

    Hi everyone!
    First of all sorry if my post is in the wrong forum.
    I'm designing a client-server project to allow users to comunicate with each other, and I have a problem in the client class. I'm using the UDP transport protocol, and I'm not allowed to use TCP. The thing is, each client is allowed to send and receive a message at any time, so by pushing a button the "sending event" triggers and sends it, and in order to receive i've launched a receiving process in another different thread, so the sending procces wouldn't be blocked.
    This is the code of the client class, called Conversacion:
    package mymessenger;
    import javax.swing.*;
    import java.net.*;
    import java.io.*;
    import java.lang.*;
    import java.awt.*;
    import java.util.*;
    public class Conversacion extends javax.swing.JFrame {
        private InetAddress MaquinaServidor;
        private int PuertoServidor;
        private DatagramSocket MiSocket;
        private DatagramPacket PaqueteSalida;
        byte [] BufferEntrada= new byte[1024];
        private DatagramPacket PaqueteEntrada= new DatagramPacket (BufferEntrada,BufferEntrada.length);
        byte [] BufferSalida;
        int ack=0;
        int puerto_contrario;
        String direccion="192.168.1.102";
        String direccion_contraria;
        String destinatario_completo="";
        String nombre_destinatario="";
        String nombre_local="";
        String mensaje_recibido=""; // This is the variable I want to use every time a client receives a message
        boolean salir=false;
        public Conversacion()
            initComponents();
            esperar();
    @SuppressWarnings("unchecked")
    // Here would come the generated code by Netbeans, which is not relevant in this case
    private void enviarActionPerformed(java.awt.event.ActionEvent evt) {                                     
       // This is the sending event that calls a function to send the message to the server, i'll post it in another message
        void enviar (String mens) 
            // Function used to send the message to the server, i'll post it in another message
        void esperar() // Here's the problem (I think)
            new Thread(new Runnable() // I launch it in a new thread, so I don't block "enviar"
                public void run() // At first, the client sends some message to the server, so the server knows some data of the client. Go to the while() command please
                    String respuesta="";
                    try
                        MiSocket= new DatagramSocket();
                        MaquinaServidor= InetAddress.getByName(direccion);
                        PuertoServidor=7777;
                        String comando="ENVIAME LOS DATOS AQUI, A LA CONVERSACION";
                        byte[] na={(byte)(ack%2)};
                        comando= (new String (na))+comando;
                        BufferSalida = comando.getBytes();
                        PaqueteSalida = new DatagramPacket(BufferSalida,BufferSalida.length,MaquinaServidor,PuertoServidor);
                        segsend(PaqueteSalida);
                        ack++;
                        System.out.println("Estoy esperando un mensaje del servidor");
                        segreceive(PaqueteEntrada);
                        String retorno = new String(BufferEntrada, 1,PaqueteEntrada.getLength()-1);
                        int pos= retorno.indexOf("(");
                        int pos2=retorno.indexOf("]");
                        int pos3=retorno.indexOf("Ð");
                        nombre_destinatario=retorno.substring(0,pos-1);
                        destinatario_completo=retorno.substring(0,pos2+1);
                        direccion_contraria=retorno.substring(pos2+1,pos3);
                        nombre_local=retorno.substring(pos3+1);
                        setTitle(destinatario_completo+" - CONVERSACIÓN");
                        segreceive(PaqueteEntrada);
                        respuesta = new String(BufferEntrada, 1,PaqueteEntrada.getLength()-1);
                        puerto_contrario = Integer.parseInt(respuesta);
                        while (!salir) // Here begins the infinite loop I use to receive messages over and over again
                            segreceive(PaqueteEntrada); // I use segreceive that is kind of the same as "receive". No big deal about this
                            mensaje_recibido = new String(BufferEntrada, 1,PaqueteEntrada.getLength()-1); // Every time a client receives a message, I want to store it in the variable "mensaje_recibido"
                            int pos4 = mensaje_recibido.indexOf(":");                     // This next 4 commands are not relevant
                            String auxiliar=mensaje_recibido.substring(pos4+2);
                            if (auxiliar.equals("FINALIZAR CONVERSACION"))
                                setVisible(false);
                            SwingUtilities.invokeLater(new Runnable() // Now I want to asign the value of mensaje_recibido (the message I just received) into texto_total, a Swing text area
                                public void run()
                                    String auxi=texto_total.getText();
                                    if (auxi.equals(""))
                                        texto_total.setText(mensaje_recibido); // if the text area was empty, then then i put into it the message
                                    else
                                        texto_total.setText(auxi+"\n"+mensaje_recibido); // if it's not, then i put the message in the next line of the text area
                            Thread.sleep(1000);
                    catch (Exception e3)
                        System.out.println(e3);
            }).start();
        }The communication starts and one user is able to send all the messages he wants to the other one, but when the other wants to send one to the first user, the first user receives a message with the same character over and over again that looks like an square &#9632;. Again, this problem comes when a user that already sended a message, and wants to receive one for the first time (and next times). I searched in these forums all day and so far I couldn't fix it.
    This problem happens in the receiver client, not in the sender client and not in the server. I already looked into that and those things are doing what they have to. I would be really really grateful if somebody could tell me which is the problem or how to fix this, because I'm becoming nuts.
    Now I'm going to post the function "enviar" which sends the message, and the content of "enviarActionPerformed" which calls "enviar".
    Again, excuse me if this is the wrong forum for this question. and sorry for my English too.

    This is the rest of the code, though I don't think the problem is here, maybe by pushing the sending button it causes the receiving problem:
    private void enviarActionPerformed(java.awt.event.ActionEvent evt) {                                      
            String mensaje=texto.getText();
            mensaje=nombre_local+" dice: "+mensaje;
            texto.setText("");
            String auxiliar=texto_total.getText();
            if (auxiliar.equals(""))
                texto_total.setText(mensaje);
            else
                texto_total.setText(auxiliar+"\n"+mensaje);
            enviar(mensaje);
        void enviar (String mens)
            String respuesta="";
            try
                MiSocket= new DatagramSocket();
                MaquinaServidor= InetAddress.getByName(direccion);
                PuertoServidor=7777;
                BufferedReader Teclado= new BufferedReader(new InputStreamReader(System.in));
                BufferEntrada = new byte[1024];
                PaqueteEntrada = new DatagramPacket (BufferEntrada,BufferEntrada.length);
                BufferSalida=new byte[1024];
                String comando="RETRANSMITIR MENSAJE";
                byte[] na={(byte)(ack%2)};
                comando= (new String (na))+comando;
                BufferSalida = comando.getBytes();
                PaqueteSalida = new DatagramPacket(BufferSalida,BufferSalida.length,MaquinaServidor,PuertoServidor);
                segsend(PaqueteSalida);
                ack++;
                String puerto= Integer.toString(puerto_contrario);
                int pos = mens.indexOf(":");
                String auxiliar=mens.substring(pos+2);
                comando=mens+"-"+direccion_contraria+"*"+puerto;
                byte[] nb={(byte)(ack%2)};
                comando= (new String (nb))+comando;
                BufferSalida = comando.getBytes();
                PaqueteSalida = new DatagramPacket(BufferSalida,BufferSalida.length,MaquinaServidor,PuertoServidor);
                segsend(PaqueteSalida);
                ack++;
                if (auxiliar.equals("FINALIZAR CONVERSACION"))
                    setVisible(false);
            catch(Exception e)
                System.out.println(e);
        }I'm gonna keep working on it, if I manage to fix this I'll let you know. Thanks a lot!

Maybe you are looking for

  • New MacBook Pro - continue with Time Machine backups or start over?

    I'm unsure of how I should proceed here ...  My old (late 2008 aluminium unibody MacBook) died last month and I now have a shiny new MB Pro.  I transferred my data from one of two backup drives I have using Migration Assistant but did not transfer th

  • Monitor suddenly went black/white (negative image)...

    ... in one blink of the eye. Nothing but black and white, but mostly black. What happened? How can i fix it? I have the white iMac that has the monitor on an 'arm". Thanks for any help you can offer!

  • Simple search question

    I want to find all the mail from Ted or Steve. If I create a smart mailbox, it's easy: if any of the following conditions are true: from Ted, from Steve. But how do I do this with search? If I type from:ted, it finds everything from ted, but adding |

  • 3D Tracking Retouchment/Replacement

    Hey guys. I have footage with an moving camera (threedimensional) and I want to remove something in the shot using AE CS6. Let`s use the "Blaster Walk" HD-Plate on http://www.hollywoodcamerawork.us/trackingplates.html as an example trying to remove t

  • How can i install shockwave with auto updates disabled?

    how can i install shockwave with auto updates disabled? i need to push out shockwave to all our machines and i need to have autoupdates disabled? whats the trick?