How use multithead with socket

How use multithead with socket
I need do a client and server program that accept multitherad issue
Thanks who can help me

you'd have to do something like this:
(this is all assuming you want to read Strings from the socket. setSoTimeout works for any read() call to the InputStream associated with the Socket)
ServerSocket ss = new ServerSocket(myPort);
Socket s = ss.accept();
s.setSoTimeout(5*60*1000); // 5 mins * 60 secs * 1000ms
BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
boolean running = true;
while(running)
try
String readIn = in.readLine();
// do whatever you want with the data read
catch(SocketTimeoutException)
running = false;
Now. That's what I think needs to be done. I don't have Java on the machine I'm currently on, so I can't test/verify it, but it goes something like that.
Good luck,
Radish21

Similar Messages

  • How to use setSoTimeOut() with socket ??

    HI All!
    I eagerly need to know how to use setSoTimeOut() with socket (on server side).
    Actually the scenario is that My Server accepts connection and waits for connected client to send data to it. I WANT TO KEEP, IF CLIENT DOENS'T SENDS ANY DATA TO SERVER WITHIN 5 min. THEN SERVER MUST CLOSE THE CONNECTION, BUT IF SERVER RECEIVES STILL A BYTE FROM THE CLIENT WITHIN 5 mins., THE SERVER MUST RESET CHECKING TIME OUT FOR NEXT 5 MINUTES.
    How can i do that??
    Any help with example will be appreciated!!
    Thanx in advance

    you'd have to do something like this:
    (this is all assuming you want to read Strings from the socket. setSoTimeout works for any read() call to the InputStream associated with the Socket)
    ServerSocket ss = new ServerSocket(myPort);
    Socket s = ss.accept();
    s.setSoTimeout(5*60*1000); // 5 mins * 60 secs * 1000ms
    BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
    boolean running = true;
    while(running)
    try
    String readIn = in.readLine();
    // do whatever you want with the data read
    catch(SocketTimeoutException)
    running = false;
    Now. That's what I think needs to be done. I don't have Java on the machine I'm currently on, so I can't test/verify it, but it goes something like that.
    Good luck,
    Radish21

  • How use jdbc with swing ? i am new in this concept.

    hi
    freinds,
    i am new in java can any one give the example which explain the how to use jdbc with swing.
    thanks in advace.
    satish
    thanks.

    See here  >  http://support.apple.com/kb/HT4236
    More info in the User Guides for your Devices...

  • How use Tomcat with MySQL

    Can anybody suggest me as how to use Tomcat with MySQL server.
    Thanks in advance.
    Khiz_eng

    add the classpath to the JDBC-driver to the tomcat-
    environment (I did it in tomcat.sh)
    Then put your code accessing MySQL into a servlet....
    You can put the user-ID and the password into a session-
    object or read them in as parameters.
    The book 'core Servlets and Java Server Pages' from
    Marty Hall gave me a lot information.
    Regards
    Fredy

  • How to use channel with sockets?

    Hello
    i am impleme3nted a sinple client/server application. The serv handles multiple connection via multithread(one thread per connection). Here is my code
    private void listen(int port) throws IOException {
    ss = new ServerSocket(port); // Create the ServerSocket
    System.out.println("Listening on " + ss);
    while (true) {
    Socket s = ss.accept(); // Grab the next incoming connection
    //s.setKeepAlive(true);
    System.out.println("Connection from " + s);
    // Create a DataOutputStream for writing data to the other side
    //dout = new ObjectOutputStream(s.getOutputStream());
    // dout.useProtocolVersion(ObjectOutputStream.PROTOCOL_VERSION_1);
    Thread clientThread =new ServerThread(s); // Create a new thread for this
    clientThread.start();
    // connection
    My client and server exchange object(serializable). How can i change this in order to add the ServerSocketChannel feature so that one thread deals with many connection?
    thanks a lot
    sebastien

    Hi, yes i have seen that document
    but i don't really know how i cna use it to update my code with channel feature.
    how can we do, please provide me an update of my previously posted code. I would be so thankful.
    thanks a lot
    sebastien

  • How use REPORT_DESTYPE with WebDAV

    Hi,
    How can I use the RUN_REPORT_OBJECT command to send report to Portal via WebDAV. If I try:
    SET_REPORT_OBJECT_PROPERTY( repid, REPORT_DESTYPE,WEBDAV);
    there is an error:
    identifier "WEBDAB" must be declared !
    In the Document " Oracle Application Server 10G -Integrating Oracle Reports in Oracle Forms Services applications" It said the REPORT_DESTYPE may be FILE, PRINTER, MAIL or CACHE only. What about other types like OraclePortal and WebDAV ?

    Hi Fang,
    As far as I know, SQL Server Reporting Services (SSRS), have no permission extension. In Reporting Services, it is use role-based security to grant user access to a report server. There are two types of roles: Item-level roles and System-level roles.
    Based on my test, if we assign user with System User System-level role, the user will have permission to user Report Builder to create report. However, if we only assigned Browser or Report Builder Item-level role to the user, he/she will have no permission
    to publish the report to the report server. In this situation, although user have permission user Report Builder to edit the report, it will have no effect of the report in report server. User who has assigned Browser or Report Builder Item-level role will
    have no permission to delete report in the report server.
    There is an article about Setting Permissions in Reporting Services, you can refer to it.
    http://technet.microsoft.com/en-us/library/aa337491(v=sql.105).aspx
    Hope this helps.
    Regards,
    Alisa Tang
    Alisa Tang
    TechNet Community Support

  • How use locator with sax to get line number of an element?

    dear friends,
    it's clearly stated in subject. after trying for hours, i still couldn't figure out how to get line numbers. my class extends defaulthandler. please help.
    ozgur

    hi
    i am also struggling with same problem
    someone plssssssss help.....
    how can i use Locator to get line number of the XML document.
    in my extended DefaultHandler class i have just implemented this,
    public void setDocumentLocator(Locator location) {
         lineNumber = location.getLineNumber();
    but no help...
    how to register my parser to the documnet locator events?
    plzzzzzzz help...
    -Soni

  • How use xml with namespaces

    I have the following xml which is output from Oracle Bpel.
    <OglRapportPerAdresnrResponse xmlns="http://www.itude.com/technology/Ogl/RapportPerAdresnrResponse">
    <AdresGegevens>
    <Adresnr>54321</Adresnr>
    <Straatkode>12345</Straatkode>
    </AdresGegevens>
    </OglRapportPerAdresnrResponse>
    If i remove the namespace info everything works fine but with the namespace info the output is empty if i insert e.g. <Adresnr> into a template. The field browser shows everything fine and also the value but when rendering a PDF it disappears. I read in the user guide that i need to declare the namspace in a form field like <?namespace:namespace name= namespace url?> but how do i do that with the above namespace notation where the namespace name is empty ?
    Regards,
    Andre

    Hi Tim,
    I found part of the solution but i am still stuck when i need to use <?for-each?> tags. When i use the following XML:
    <OglRapportPerAdresnrResponse xmlns="http://www.itude.com/technology/Ogl/RapportPerAdresnrResponse">
         <AdresGegevens>
              <Adresnr>8391</Adresnr>
              <Straatkode>11070</Straatkode>
         </AdresGegevens>
         <Basisgegevens>
              <paramPResult xmlns="urn:generated.ws.kgb.itude.com">
                   <paramAdresnr>8391</paramAdresnr>
                   <paramGegevenstype>GEBRUIK</paramGegevenstype>
              </paramPResult>
              <paramPResult xmlns="urn:generated.ws.kgb.itude.com">
                   <paramAdresnr>8391</paramAdresnr>
                   <paramGegevenstype>STADSDEEL</paramGegevenstype>
              </paramPResult>
         </Basisgegevens>
    </OglRapportPerAdresnrResponse>
    I read the xml file in Word. I then have access to the fields but when i select AdresGegevens/Adresnr the output is not rendered. The namespace is a default namespace for that element. I found out that if i define a namespace like <?xmlns:bpel=http://www.itude.com/technology/Ogl/RapportPerAdresnrResponse?> and then access the AdresGegevens/Adresnr through <?bpel:Adresnr?> it works!
    I then defined a second namespace <?xmlns:bpel2=urn:generated.ws.kgb.itude.com?> and tried to render the paramPResult tags with:
    <?for-each:paramPResult?>
    <?bpel2:paramAdresnr?>
    <?bpel2:paramGegevenstype?>
    <?end for-each?>
    But the above does not work. Any ideas?
    Regards,
    Andre Jochems

  • How use USB with VISA resource name?

    Hi, 
    I'm new at LabVIEW and I'm working on a code that has to acquire data from a measurement device.This device only has a USB output so I have to work with it. As far as know the block that is used to refer a external port is VISA resource name. I have installed a driver that recognizes the serial ports, and they appear in the list of VISA resource file at front panel. So I figured that installing the product's USB driver so the USB's ports would appear. I installed and nothing of USB ports. I don't know it is that simple or working with USB ports is a little bit harder. I've tried a lot of things and nothing worked so here I am.
    PS: I have noticed that the driver's version is 64 bits (my pc is 64 bits)  and my LabVIEW version is 32 bits, so could that be the problem?
    The device by the way is Digital Analyzer WT500, Yokogawa.
    Thank you.
    Solved!
    Go to Solution.

    Victor,
    the suggestion of Instrument Driver is to make more easy using the instrument. 
    Normally, you should install a windows drive from manufacturer (if it isn't installed, the instrument will appear like a pendrive in device manager) and the NI VISA. But for some instruments, the manufacturers have API's that uses NI VISA to communicate with your equipments.
    So check if your instrument appear correctly in device manager (as indicated by Yokogawa). If not, check if Yokogawa has an appropriated driver for this instrument and install it. 
    Is it clear?
    If you prefer, contact NI Brazil Support by website or by phone (11)3149-3149 Ext 3.
    Ricardo Ramos
    Engenheiro de Vendas - Sul
    National Instruments Brasil

  • E72 - How Use email with 3G or WLAN connection

    1) CONNECTION CONFIGURATION
    To configure the Phone to prompt always the selection of Access Point to use, you should go here:
    Menu -> Ctrl. Panel -> Settings -> Connection -> Destinations.
    then, with in the Options menu, select Default Connection, and set it as ASK ALWAYS.
    2) EMAIL CONFIGURATION 
    Each email account allow the configuration of the default "Destination" that should be used:
    Menu -> Email -> Settings -> "Your Account" -> Mailbox Setting -> Advanced Mailb. Settings ->
                      - > Incoming email -> Access point in use := ASK ALWAYS
                       -> Outgoing email -> Access point in use := ASK ALWAYS
    If you use the Push Email functionality, the configuration of access point is here:
    Menu -> Email -> Settings -> "Your Account" -> Account Settings -> Account Information -> Access Point 
    But for this functionality it's not possible to set as ASK ALWAYS, you should configure a fixed access point.
    I hope that now you are able to use the email (not only email, but all apps) with the correct connection.
    Bye from Italy.
    Edi

    Hi, Thanks for the info.... I also looking for the solution to set/assign "connection group" instead of define single connection... but i guess this is not feasible in current firmware... hope to available future firmware relase.
    Regards,
    Anandharaj
    www.raj2u.net :: E72-1 | RM-530 | 023.007

  • How use SetIntArrayRegion with std::vector int ?

    I have a vector of ints that i want to put into a jintArray. How do I do this?
    When I tried the below code, it didn't work but instead when i printed out the int values on the java side, they were all messed up.
    jintArray arr = env->NewintArray( intVector.size() );
    env->SetintArrayRegion( arr, 0, intVector.size(), ( jint * ) &( intVector ) );This returns weird values. What am I doing wrong?

    This isn't a Java/JNI-specific issue. Your code also wouldn't work if you tried to do this:
    void foo( int* );
    void bar() {
        vector<int> a(10);
        foo( (int*)&a );
    }Hint: using a cast is a bad idea. It's wrong for the same reason the following code is wrong:
    void foo( double* );
    void bar() {
        double d = 42.0;
        foo( (int*)&d );
    }You can't just use a cast as a sledge-hammer and magically expect the right thing to happen. In your original code, you're passing the address of the C++ vector object as if it were the address of a plain old C-style array of int.
    Using old-style casts is a bad idea in general. This is why new-style casts were added to the language. Had you tried to use:
        static_cast<int*>( &intVector )the compiler would have correctly complained. Old-style casts assume you know what you're doing. In this case, your old-style cast is equivalent to a reinterpret_cast<int*>.
    That aside, there's intentionally no way to convert a vector<T> into the address of its first element because there's no guarantee that the implementation of vector will store array elements contiguously.

  • How use proxyclient with Reportexecution2005?

    Hi,
    I want to run a report from a SSRS-server in my C# code (i want to export the report in a 2007-2010 excel format).
    I know that I need to use the Reportexecution2005 WCF-service but I have never done this before and I can't find any nice examples on the web...
    The most examples doesn't deal with a "Soap-client" (they seems to use the webservice-class) and use another kind of Reder-method (with differende parameters).
    Here is my beginning:
    varclient =
    newReportExecutionServiceSoapClient();     
    var  result = client.Render(???)
    Hope someone can help me to with the code...
    regards,
    Marius H Enerud

    Hi Marius,
    On the basis of the description, I understand that you intend to use ReportExecution2005 web service to render reports in Excel format.
    The Reporting Services Execution Web service allows developers to programmatically process and render reports from report server. To process a specific report and render it in the specified format, we can use the “Render” method in the ReportExecutionService.
    Here, you can see these steps below to render the report:
    1. In the custom application, add a web service reference. The endpoint should be:http://<servername>/reportserver/ReportExecution2005.asmx
    2. Use the following code to render the report in the specified format:
    using System;
    using System.IO;
    using System.Web.Services.Protocols;
    using myNamespace.MyReferenceName; 
    class Sample{   
    static void Main(string[] args)   
    ReportExecutionService rs = new ReportExecutionService();       
    rs.Credentials = System.Net.CredentialCache.DefaultCredentials;        rs.Url= "http://myserver/reportserver/ReportExecution2005.asmx";         // Render arguments       
    byte[] result = null;       
    string reportPath = "/AdventureWorks Sample Reports/Employee Sales Summary";     
    string format = "Excel";       
    string historyID = null;       
    string devInfo = null; // Prepare report parameter.       
    ParameterValue[] parameters = new ParameterValue[3];       
    parameters[0] = new ParameterValue();       
    parameters[0].Name = "EmpID";       
    parameters[0].Value = "288";       
    parameters[1] = new ParameterValue();       
    parameters[1].Name = "ReportMonth";       
    parameters[1].Value = "6";  // June       
    parameters[2] = new ParameterValue();       
    parameters[2].Name = "ReportYear";       
    parameters[2].Value = "2004";       
    DataSourceCredentials[] credentials = null;       
    string showHideToggle = null;       
    string encoding;       
    string mimeType;       
    string extension;       
    Warning[] warnings = null;       
    ParameterValue[] reportHistoryParameters = null;        string[] streamIDs = null;               
    ExecutionInfo execInfo = new ExecutionInfo();        ExecutionHeader execHeader = new ExecutionHeader();        rs.ExecutionHeaderValue = execHeader;       
    execInfo = rs.LoadReport(reportPath, historyID);        rs.SetExecutionParameters(parameters, "en-us");         String SessionId = rs.ExecutionHeaderValue.ExecutionID;        Console.WriteLine("SessionID: {0}", rs.ExecutionHeaderValue.ExecutionID);       
    try       
    result = rs.Render(format, devInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs);           
    execInfo = rs.GetExecutionInfo();            Console.WriteLine("Execution date and time: {0}", execInfo.ExecutionDateTime);
    catch (SoapException e)       
    Console.WriteLine(e.Detail.OuterXml);       
    }        // Write the contents of the report to an PDF file.       
    try       
    FileStream stream = File.Create("report.pdf", result.Length);           
    Console.WriteLine("File created."); 
               stream.Write(result, 0, result.Length);           
    Console.WriteLine("Result written to the file.");           
    stream.Close();      
    catch (Exception e)       
    Console.WriteLine(e.Message);       
    For more information, please see:
    ReportExecutionService.Render Method
    ReportExecution2005 Namespace
    If I have any misunderstanding, please feel free to contact me.
    Regards,
    Heidi Duan
    If you have any feedback on our support, please click
    here.
    Heidi Duan
    TechNet Community Support

  • How use Cookies with flex

    Hi,
    Can we use cookies in flex. If so, can any body give me the
    sample code for that.
    Thanks
    Satish KC.

    Rather than ordinary cookies, use Local Shared Object. It is
    much more powerful than standard cookies.
    I'll look for an example. What version of Flex are you using?
    Tracy

  • How use badi with 0crm_sales_act_1 datasource

    Hi
    i am working on crm extractor, 0crm_sales_act_1.To meet my requirements i need to enhance it, it is based on BADi.
    I don't know the BADi. but i am having some abap knowledge.
    If you send me exemple or program.
    best Regards,

    thx

  • Need help with sockets!

    I am fairly new to network programming. All help is very appreciated!
    I know how to work with sockets and serversockets, and how to transmit data between the host and the clients. My problem is that I have no idea how to get my working program to work online.
    -It works fine when I have both the client and host programs running on my computer.
    -It works fine when I have the host on one computer (192.168.1.103), and the client running on another one (192.168.1.102 I think). I guess in this case I'm just using the linksys network, not the internet.
    -IT DOES NOT WORK WHEN I upload the files to my website, and run them from there. I am not sure what the cause is; the host correctly creates the serversocket and waits, but never receives a connection to the client. The client seems to connect; it does not throw any exceptions, and creates a socket, but never actually communicates with the host.
    Could the problem be with my applets' permissions?
    What hostname/IP should I have the client connect to? It is on the same server, so would localhost work, or do I need to connect to my websites ip, or to the hostname?
    What other problems could there be?!?!?!?!
    Thank you so much for your help!!!!!!!!!!

    Donv7 wrote:
    1) Is the server program running on the same machine as the webserver?
    2) How are you opening this Socket in the applet? You mentioned something about localhost, that would be wrong. You should use the www hostname. Same as the host that served the HTML that the applet lives in.1- My server program and client program are actually the same thing. This doesn't sound too good.
    And applet is not a suitable endpoint for a P2P application. An applet is going to be a client. Not a server.
    Are you actually running a server (of your program) on the webserver? Or are you hoping that two applets will talk to each other with one acting as a server? Because that's not going to work.

Maybe you are looking for

  • Free space not showing after shrinking BootCamp Partition

    I gave a lot of space for the windows 8 bootcamp partition because I thought I am going to install Lots of stuff on it. After 3 months I found out that my lion partition is almost full!  And I have 100 GB of free (Unused) partition on my bootcamp par

  • Converting DOS import file to UNIX

    We had an HTMLDB install on a now defunct W2K machine. We exported the apps in DOS file format. We are now trying to import the apps into a UNIX HTMLDB install on an HP itanium. We keep getting the same error: ORA-20001: GET_BLOCK Error. ORA-20001: G

  • Error code 8103010d

    I have a NOkia LUmia 520 and when updating my sofwtare I got an error code 8103010d for teh calendar anyone can help me solve it?

  • Deleting Workflow definition

    I am thinking of using script wfrmitt.sql to drop the design and run time information for one specific item type. After the delete I am planning to apply the new workflow definition for the same item type. This is because changes made to the workflow

  • Where do I find "Rights", to create a "Rights Enabled" PDF?

    My form has the following message when opened in Reader, "Please fill out the following form.  You cannot save data typed into this form. Please print your completed form if you would like a copy for your records." I want to find the rights in Acroba