How to pass a string from a child thread to a parent thread ?

I have a Server class listening to a particular port continuously using TCP Sockets . Whenever a client connects to this server socket, a new thread is created to obtain the data from the client socket. The following code shows how this is done -
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.*;
public class TransportHandler extends Thread{
          ServerSocket server_socket;
          int myListeningPort;
          public String clientReq = "";
          public TransportHandler() throws IOException{
               super();
               myListeningPort = 80;
               CreateServSocket();
          //throw the socket exception outside, so that it can be handled
          public TransportHandler(int port) throws IOException{
               super();
               myListeningPort = port;          
               CreateServSocket();
          private void CreateServSocket() throws IOException{
                        //create serversocket
               server_socket = new ServerSocket(myListeningPort);
          public void printmsg(){
               System.out.println(clientReq);
          @Override
          public void run() {
               // TODO Auto-generated method stub
               StartListening();
          public void StartListening(){
               while(true){
                    //loop forever listening to connections
                    try {
                         Socket clientSocket = server_socket.accept();
                                         //create new thread to handle client connection
                         Thread clientthread = new Thread(new ClientConnectionHandler(clientSocket));
                         clientthread.setName("Client Handler");
                         clientthread.start();
                         printmsg();
                    } catch (IOException e) {
                         // TODO Auto-generated catch block
                         e.printStackTrace();
          public void StoreReq(String msg){
               clientReq.concat(msg);
          private class ClientConnectionHandler implements Runnable{
               Socket ClientSock;
               BufferedReader sockReader;
               InputStreamReader isReader;
               String messageFromClient;
               public ClientConnectionHandler(Socket sock){
                    ClientSock = sock;
                    try {
                         isReader = new InputStreamReader(ClientSock.getInputStream());
                         sockReader = new BufferedReader(isReader);
                    } catch (IOException e) {
                         // TODO Auto-generated catch block
                         e.printStackTrace();
               @Override
               public void run() {
                    // TODO Auto-generated method stub
                    int c= 0;
                    try {
                         while( (messageFromClient = sockReader.readLine())!= null){
                              StoreReq(messageFromClient);  
                         //System.out.println("clientreq = "+clientReq);
                    } catch (IOException e) {
                         // TODO Auto-generated catch block
                         e.printStackTrace();
}The TransportHandler is instantiated from another class HttpMessageHandler as shown below -
import java.io.IOException;
public class HttpMessageHandler {
     public static void main(String[] args){
          try {
               TransportHandler server = new TransportHandler();
               server.start();
          } catch (IOException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
}So in the above code when the server.start() is executed, the run() method in TransportHandler is executed. How do I get the string contained in clientReq in HttpMessageHandler after the data from client socket is fully read ?
Edited by: turing09 on Dec 12, 2009 2:13 PM

Okay, to make my problem more clear to you - basically I am trying to create a simple Http Server, wherein the HttpMessageHandler is an interface between the Http layer & the Transport layer (represented by TransportHandler class). I am trying to code it bottom-up. In my design I require the TransportHandler class to get the client http request data from the TCP socket and pass it onto the HttpMessageHandler class.
At the same time TransportHandler class must continuously listen to the port to receive other connections. For every client connection, the TransportHandler creates a new ClientHandler thread & this new thread gets the data. The TransportHandler instance & the ClientHandler instance are running in seperate threads. The HttpMessageHandler is running in the main thread. Please note: the member variable clientReq is private & not public
The problem I am facing here is that even when the ClientHandler thread finishes, I am not able to print the client request data in HttpMessageHandler thread.
I am able to print the String in the run() method of ClientHandler but not in HttpMessageHandler main() method.
Any solutions for this?
Edited by: turing09 on Dec 12, 2009 5:24 PM
Edited by: turing09 on Dec 12, 2009 5:25 PM

Similar Messages

  • How to pass a string from a servlet to client side

    hi,
    i would like to generate a string from a servlet and pass it to the client side. the client will receive the string by using request.getParameter(). How should i implement this system? Could anybody give me some hint?
    Best Regards,
    Henry

    Greetings,
    hi,
    i would like to generate a string from a servlet and
    pass it to the client side. the client will receive
    the string by using request.getParameter(). HowAre you referring to the instance of (Http)ServletRequest the 'request' object being passed to the "client"? What is the "client" in this case? If you mean a "traditional" client communicating over (or by tunneling through...) HTTP then no can do. The (Http)ServletRequest object is generated by the web container (a.k.a. "servlet engine"), not by the client, and it is not serializable so there is no way to pass it back to the client...
    should i implement this system? Could anybody give me
    some hint?It depends again on "what is the 'client' in this case?"
    Best Regards,
    HenryRegards,
    Tony "Vee Schade" Cook

  • Example of using a delegate in wpf forms to pass a paramater from a child to sub in parent

    Hi
    Looking for a example or explanation of how to use delegate to pass a parameter from a wpf form child to a sub in the parent to be executed in vb.net.
    Thanks

    Hi Paul
    As trying to use a delegate as declaring and referencing along the lines of  
    https://msdn.microsoft.com/query/dev12.query?appId=Dev12IDEF1&l=EN-US&k=k(vb.Delegate);k(SolutionItemsProject);k(TargetFrameworkMoniker-.NETFramework,Version%3Dv4.5);k(DevLang-VB)&rd=true
    Thanks
    RB_IA
    My experience with using delegates is related to Multi-threading or otherwise accessing members/methods running on separate threads.
    A WPF example of that would be something like this:
    Option Strict On
    Option Explicit On
    Option Infer Off
    Class MainWindow
    Delegate Sub dSetTitle(window As Window, text As String)
    Dim dispatched As Boolean = False
    Private Sub btnSafeCall_Click(sender As Object, e As RoutedEventArgs) Handles btnSafeCall.Click
    Dim th As New System.Threading.Thread(AddressOf SafeThread)
    th.Start()
    End Sub
    Private Sub btnUnsafeCall1_Click(sender As Object, e As RoutedEventArgs) Handles btnUnsafeCall1.Click
    Dim th As New System.Threading.Thread(AddressOf UnsafeThread)
    th.Start()
    End Sub
    Sub SetTitle(window As Window, text As String)
    If Not dispatched Then
    dispatched = True
    Dispatcher.Invoke(New dSetTitle(AddressOf SetTitle), window, text)
    Else
    dispatched = False
    window.Title = text
    End If
    End Sub
    Sub SafeThread()
    SetTitle(Me, "test2")
    End Sub
    Sub UnsafeThread()
    Me.Title = "test"
    End Sub
    End Class
    “If you want something you've never had, you need to do something you've never done.”
    Don't forget to mark
    helpful posts and answers
    ! Answer an interesting question? Write a
    new article
    about it! My Articles
    *This post does not reflect the opinion of Microsoft, or its employees.

  • How to pass query string from content editor webpart to another?

    Hi All,
    I am using content editor web-part to show GooglePiechart  for workflow status column in a list. When user click on chart, i need to show particular clicked area data in another list web-part. So that, i need to pass the query value from content editor
    web-part to another web-part. How to achieve this scenario?

    Hi Sam,
    What you can do is using SPD create a data view webpart which excepts query string value as filters as shown in the below article
    http://madanbhintade.wordpress.com/2012/01/08/sharepoint2010dataviewwebpart/
    http://sharepoint.stackexchange.com/questions/55184/how-to-filter-dataview-webpart-dvwp-from-query-string
    Then When you click on the pie charts particualr section perform a post back  by appending the required query string paramter to the same page on which your webpart exist
    Raghavendra Shanbhag | Blog: www.SharePointColumn.com
    Please click "Propose As Answer " if a post solves your problem or "Vote As Helpful" if a post has been useful to you.
    Disclaimer: This posting is provided "AS IS" with no warranties.

  • Passing a String from Java to Javascript

    Does anybody know how to pass a string from Java class to Javascript ? Can it be done?

    If you are talking in terms of web terminology...
    People do intialization of page in the following way.
    var java_script_variable = <%=String_variable%>

  • How to pass a string value from XL sheet cell to SQL query.

    Hi,
    I am using SQL query in XL sheet to fetch some data. for that i am using ODBC connection. Now I want to pass a string from XL sheet Cell value in the where clause of Select statement, Please let me know how to do this.
    Below is My code:
    nge("A4").Select
    With ActiveSheet.QueryTables.Add(Connection:= _
    "ODBC;DRIVER={Microsoft ODBC for Oracle};UID=xyz;PWD=xyz;SERVER=xyz;" _
    , Destination:=Range("A4"))
    .CommandText = Array( _
    "SELECT CRYSTAL_REPORT1.PROJECT, CRYSTAL_REPORT1.OBJECT" & Chr(13) & "" & Chr(10) & "FROM NAIODEV.CRYSTAL_REPORT1 CRYSTAL_REPORT1" _
    .Name = "Query from gg"
    Thanks,
    Priya

    What does "XL" (whatever that is) have to do with Crystal Reports which is what you are obviously working with have to do with the Oracle database?
    The rules for using Crystal with Oracle are quite clearly described in all the Crystal Reports docs ... you MUST use IN OUT ref cursors unless you are doing direct table or view access.

  • Re: Passing a string from Java class to JSP

    How can I pass a string from a function within my bean class to my JSP page?
    I would like to pass something like this with the necessary params filled in:
    String myString ="Successful <b>" + Sales.getActionType() + "</b> was made on <b>" + (new Date()).toString();
    The ActionType will be either a BUY or SELL and the current date need to be added in.
    Thank you in advance!

    SOLVED THE PROBLEM!!!

  • How to pass an object from jsp to other jsp using SendRedirect

    How to pass an object from one jsp to the other jsp using ssendRedirect with out using the session
    I am having 2 jsps
    x.jsp and y.jsp
    From x.jsp using sendRedirect iam going to y.jsp
    From x.jsp i have pass an object to the y.jsp
    Is it possible without putting the object in session
    Is it possible using EncodeUrl
    Please help me Its Urgent

    Is it possible without putting the object in sessionAnything is possible. Would you accept that it is very difficult?
    When you send a redirect, it tells the browser to send a new request for the target page. That means any request parameters/attributes are lost.
    Is it possible using EncodeUrl response.encodeURL() puts the session id into a url if the browser does not support cookies. It is purely for retaining the session.
    There are two ways that you can communicate across a sendRedirect.
    1 - use the session
    2 - pass a parameter in the url.
    parameters are string based, so passing objects is almost out of the question.
    Potentially you could serialize your object, encode it in base64 (so it is composed completely as characters) and pass it as a parameter to the other page, where you retrieve it, unencode it, and then load the serialized object.
    Or you can just use the session.

  • How to pass the data from a input table to RFC data service?

    Hi,
    I am doing a prototype with VC, I'm wondering how VC pass the data from a table view to a backend data service? For example, I have one RFC in the backend system with a tabel type importing parameter, now I want to pass all the data from an input table view to the RFC, I guess it's possible but I don't know how to do it.
    I try to create some events between the input table and data service, but seems there is no a system event can export the whole table to the backend data service.
    Thanks for your answer.

    Thanks for your answer, I tried the solution 2, I create "Submit" button, and ser the mapping scope to  be "All data rows", it only works when I select at least one row, otherwise the data would not be passed.
    Another question is I have serveral imported table parameter, for each table I have one "submit" event, I want these tables to be submitted at the same time, but if I click the submit button in one table toolbar, I can only submit the table data which has a submit button clicked, for other tables, the data is not passed, how can I achieve it?
    Thanks.

  • How to pass multiple values from workbook to planning function ?

    Hi,
    I have created Planning function in Modeler and it has one parameter(Variable represents = Multiple single values).
    When executing the planning function by create planning seq. in the web template : I see value of variable store data like ...
        A.) input one value -> V1
        B.) input three values -> V1;V2;V3
    This function execute completely in web.
    However, I want to use the planning function in workbook(Excel).
    The value of variable can't input V1;V2;V3... I don't know how to pass multiple values from workbook to parameter(Multiple single values type) in planning function ?
    thank you.

    Hi,
    Please see the attached how to document (page no 16).
    <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/f0881371-78a1-2910-f0b8-af3e184929be">how to</a>
    Hope this was helpful
    thanks

  • Is it possible to pass a string from an applet to the web site?

    Hi, everybody!
    Is it possible to pass a String from an applet to a web site (as a field value in a form, an ASP variable, or anything else). Basically, I have a pretty large String that is being edited by an applet. When a user clicks on the submit button, a different page will show up which has to display the modified string. The String is pretty large so it doesn't fit into the URL variable.
    Please, help!
    Thank you so much!

    Why do you want to do this in Java?
    Javascript is the correct language for these type of situations.
    for instance:
    in the head of your html document:
    <script language=javascript type="text/javascript">
    createWindow(form){
    if(form.text.value!=""){
    newDoc = new document
    newDoc.write(form.text.value)
    newWin = window.open(document,'newWin','width=200;height=150')
    </script>
    in the body:
    <form onSubmit="createWindow(this)">
    <p>
    Enter a String:<input type=text size=30 name="text">
    </p><p>
    <input type=submit value="submit"> 
    <input type=reset value="reset">
    </p>
    </form>

  • Regarding how to pass the data from web dynpro to workflow

    hi gurus,
    how to pass the data from web dynpro to workflow.
    Regards
    vijay

    Check this [thread|SAP_WAPI_START_WORKFLOW;

  • How to pass the data from web dynpro to workflow.

    hi gurus,
    how to pass the data from web dynpro to workflow.
    Regards
    vijay

    Hi
    you can use function module
    data   ls_input_container  TYPE swr_cont.
    data   lt_input_container  TYPE TABLE OF  swr_cont.
    CALL FUNCTION 'SAP_WAPI_START_WORKFLOW'
        EXPORTING
          task            = ptask
        IMPORTING
          return_code     = lv_return_code
          new_status      = lv_new_status
        TABLES
          input_container = pinput_container
          message_lines   = lt_message_lines
          message_struct  = lt_message_struct.
    where you pass the data in imnternal table "pinput_container" as
      ls_input_container-element = 'KUNNR'.
      ls_input_container-value = ls_skna1-kunnr ."wd_this->lv_kunnr.
      APPEND ls_input_container TO lt_input_container .
      ls_input_container-element = 'CLUSER'.
      ls_input_container-value = lv_cluser.
      APPEND ls_input_container TO lt_input_container .
      ls_input_container-element = 'BUKRS'.
      ls_input_container-value = lv_bukrs. " youe value as per requirement.
      APPEND ls_input_container TO lt_input_container .
      ls_input_container-element = 'VKORG'.
      ls_input_container-value = ls_sknvv-vkorg. " youe value as per requirement
      APPEND ls_input_container TO lt_input_container .
      ls_input_container-element = 'VTWEG'.
      ls_input_container-value = ls_sknvv-vtweg. "youe value as per requirement.
      APPEND ls_input_container TO lt_input_container .
      ls_input_container-element = 'SPART'.
      ls_input_container-value = ls_sknvv-spart. "youe value as per requirement.
      APPEND ls_input_container TO lt_input_container .
    *Also Forgot to mention where ptask is your workflow ID *
    Regards,
    Arvind
    Edited by: Arvind Patel on May 14, 2010 7:38 AM

  • HOW TO PASS THE DATA FROM SELECTION SCREEN TO STANDARD TRANSACTION?

    HI,
    HOW TO PASS THE DATA FROM SELECTION SCREEN TO STANDARD TRANSACTION?
    thanks,
    samba.

    By selection screen, what do you mean?   There is no selection screen in WDA as there was in classic dynpro. Do you mean you are using the Select-Options reusable component?  Are you wanting to call a standard transaction via ITS - SAPGUI for HTML?  Please provide more details to your question.

  • How to pass the data from wa_itab to  fieldcatlog?

    how to pass the data from wa_itab to  fieldcatlog?

    Your question doesn't appear to be Web Dynpro ABAP related. Please only post questions in this forum if they are directly Web Dynpro ABAP related.  There are several other more general ABAP related forums.

Maybe you are looking for

  • Plan Vs Actual report in PS

    Gurus, New in SAP PS module, appreciate your advice on the PS Plan Vs Actual cost reporting. What kind of standard extractor should we use in order to extract the Plan cost entered in PS? What kind of standard extractor shoud we use in order to extra

  • Could someone clarify some questions I have about the download folder?

    I use my computer mainly for audio recording. I'm constantly downloading updates to virtual instruments, updates for programs, new applications, etc. Once I download something and install it, can I delete the file from the download folder? If it's an

  • Moving music from pc (crashed) based ipod to new imac

    I haven't found this exact situation on the forums, so I hope someone can help. I have a windows-based ipod mini. My windows machine crashed and the only place I have all of my music is on my ipod. I am ordering a new imac next week and can't wait to

  • Query related to smartform.

    Hello sir's, I am doing smartform , in that i have a query that, In one delivery number , if there are 10 items then i want all details of that item numbers and also the sub-totals of that items. Also the final total of all items. Can it is possible

  • BUG?  Invalid use of an Aggregate Calculation

    Please Help: I am trying to create a mandatory Filter in a BU that is COUNT_DISTINCT(ID) > 3; When Mandatory an error pops up: Invalid use of an Aggregate Calculation If Optional filter works and can be used in a workbook. This should be allowed. The