How can I have threads communicate with each other?

I'm working on a project that requires a group of classes communicating with each other. I decided on using a server and carrying out communication that way. However, my app only has communication between the client and server. I need the clients to be able to communicate with each other. Does anyone know how I can do this or point me to a good tutorial?

Sorry, here's a bone stock example of my server and client:
<SERVER>
package testserver;
import java.io.*;
import java.net.*;
import java.util.*;
public class TestServer
static int portOpen;
public static void main(String[] args)
portOpen=4000;
try
ServerSocket portListener = new ServerSocket(portOpen);
TestServer userThreads = new TestServer();
while (1==1)
Socket userConnection=portListener.accept();
userThreads.new PortConnection(userConnection);
catch (Exception e)
System.out.println("The server encountered a serious error. Server shut down.");
e.printStackTrace();
System.exit(0);
class PortConnection extends Thread
//Declare variables to handle connections.
Socket ourConnection;
BufferedReader serverInput;
PrintWriter serverOutput;
PortConnection(Socket userConnection)
try
ourConnection=userConnection;
serverInput=new BufferedReader(new InputStreamReader(userConnection.getInputStream()));
serverOutput=new PrintWriter(userConnection.getOutputStream(),true);
start();
catch (Exception e)
System.out.println("An error occurred when a user attempted a connection.");
public void run()
serverOutput.println("Welcome to the Server.");
try
serverOutput.close();
serverInput.close();
ourConnection.close();
catch (Exception e)
</SERVER>
<CLIENT>
package testclient;
import java.io.*;
import java.util.*;
import java.net.*;
public class TestClient {
static BufferedReader userInput;
static Socket quizServer;
static BufferedReader serverInput;
static PrintWriter serverOutput;
static String serverData;
public static void main(String[] args) {
userInput = new BufferedReader(new InputStreamReader(System.in));
try {
quizServer=new Socket("localhost",4000);
catch (Exception e) {}
try
serverInput=new BufferedReader(new InputStreamReader(quizServer.getInputStream()));
serverOutput=new PrintWriter(quizServer.getOutputStream(),true);
catch (Exception e) {}
try {
serverData=serverInput.readLine();
catch (Exception e) {}
System.out.println(serverData);
</CLIENT>

Similar Messages

  • I have the iPhone and my own Apple ID. I would like the iPad to have my husbands Apple ID so we are able to communicate with each other (he is deaf). How can FaceTime and iMessage be set up to do this?

    I have the iPhone and my own Apple ID. I would like the iPad to have my husbands Apple ID so we are able to communicate with each other (he is deaf). How can FaceTime and iMessage be set up to do this?

    Log into each device with your own Apple ID's in Settings > iCloud.
    Then, so you can share preiously purchased apps, log into both devices using the Apple ID used to make those purchases, but ONLY in Settings > iTunes and Apps Stores.
    Verify that each device uses your own Apple IDs in Settings > Facetime and Settings > Messages.

  • Is there a way to have 2 threads communicate w/each other?

    I'm working on a program which requires 2 threads to communicate with each other. I was wondering how I can do this? How can I find out an id to reference a thread?

    I am not sure that there is .. not directly anyway. You can creat an intermediate class and pass copies of its objects to your threads. And then your threads can use it as a means of communication between them. For example:
    class A {
    // you have some private and public methods here.. which you can use to communicate between threads
    class B extends Thread {
    private A aVar;
    public B (A a) {
    aVar = a;
    //you have your run method here..
    class C extends Thread {
    private A aVar;
    public C (A a) {
    aVar = a;
    //you have your run method here..
    class D {
    public static void main(String [] args) {
    A a = new ();
    B b = new B (a);
    C c = new C(a);
    b.start();
    c.start();
    }

  • How do I enable two wireless clients to communicate with each other?

    I have a WRT54GL with the latest firmware.  I have two computers which are both connected to the router, with IP addresses assigned via DHCP.  Neither has a firewall running.  I cannot get them to communicate with each other -- even ping doesn't work.  I can ping the router itself using the IP address assigned to it on the WAN side by my ISP.   Both computers have no problem reaching the internet through the router.
    What settings on the router will enable the communication to occur?  I can't find anything in the router's user interface which appears to control this. 
    Thanks.
    Solved!
    Go to Solution.

    Hi annie25,
    I think it would be best to check on netgear or belkin technical forums how to make these two talk. 
    Yesterday is history. Tomorrow is mystery. Today is a gift.

  • Migration between two environments which can't communicate with each other

    My customer is intending to do migration from test environment to production environment using CCM.
    But the two environments are not in the same network.
    The environments' setting is as blew.
    BO TEST Repository can communicate with Web BO Server.
    BO PRODUCTION Repository (Cluster environment) can communicate with Web BO Server.
    BO TEST Repository and BO PRODUCTION Repository (Cluster environment) are in the different network, they can't communicate with each other.
    Setting Target Repository manually in CCM.
    Questions are:
    1. In CCM, as long as both Source Repository and Target Repository can communicate with Web BO Server, the migration will be successful.
       Is that right?
    2. If 1 is not right, is there additional setting should I do?
       For example, If I need to open some firewall port?
    3. Is there other attentions should I notice?
    Thanks

    Questions are:
    1. In CCM, as long as both Source Repository and Target Repository can communicate with Web BO Server, the migration will be successful.
    Is that right?
    Yes that is correct
    2. If 1 is not right, is there additional setting should I do?
    For example, If I need to open some firewall port?
    You have another option which is to use the BIAR files. Export your objects to a BIAR file in source environment, and import them from BIAR into the target environment
    3. Is there other attentions should I notice?
    when using BIAR files as solution, Make sure that you keep them < 1GB size to avoid corruption
    you may have to increase or adjust timeouts on input and output repository servers as well

  • Hi, I'd like to set alarms or reminders on my I phone or I pad so that it can update or sync automatically with each other. I don't know if this is possible or how to do it. I hope you can help..

    Hi, I'd like to set alarms or reminders on my I phone or I pad so that it can update or sync automatically with each other. I don't know if this is possible or how to do it. I hope you can help.

    HI, if I did this, then I believe that I cloud would then hold my info which I don't want. Is that the case? The reason is that I'm an old git, therefore used to not giving out info. Would I be right?
    Thank-You so much for taking the time to answer.
    John.

  • I have a mac book pro, an ipad and an iphone.  i have an icloud account that allows my iPad and imac to sync.  but my mac book only has a connection to 'mobile me'.  how can i include my macbook with my other devices?  help!  thanks

    i have a mac book pro, an ipad and an iphone.  i have an icloud account that allows my iPad and imac to sync.  but my mac book only has a connection to 'mobile me'.  how can i include my macbook with my other devices?  help!  thanks

    You need OSX 10.7.2 or higher in order to access icloud.  The mobile me account is now defunct (it closed down more than a year ago).

  • HT5232 does ipad mini have a usb port? if not then how can i share my documents with devices other than apple?

    does ipad mini have a usb port? if not then how can i share my documents with devices other than apple?

    Wireless Flash Drive (tap to enlarge image)

  • How can we get help/advice amoungst each other? I have questions

    How can we get help/advice amoungst each other? I have questions which might not be bug related and thought it would be nice if we could bounce questions off each other.
    Example:
    Why is my Reflow sample behaving like this?
    Should I have some kind of settings set so things don't get all weird?
    I didn't set any breakpoints yet, but things are going weird.
    Image attached! Any insights?
    Thanks.

    You can post questions here too. If they are design questions if people know the answer they can respond too.
    For this particular issue, it does look like a design problem. From the screen shots, I'm guessing that the light gray box is using negative top margin to overlap the darker dray box. I think for this change the dark gray box to use height:auto and add a padding-bottom to it for the current space below the text. That way when the text starts to push down there will be a constant amout of space from the bottom of the text to the bottom of the dark gray box and that will push the light gray box down as well.

  • 2 J2EE RI servers which communicate with each other

    Hi all,
    I'm wondering whether the following scenario is possible, and if so, of course I would like to now how I have to achieve it.
    I want to run two j2ee ri application servers on two different machines. What I want, is that the applications on the two different servers can communicate with each other.
    Any help on this will be greatly appreciated.

    Greetings,
    that does the lookup, so I have the bean clasees in
    the classpath of the project (is that what you
    ment?).In addition to the bean classes, the client needs the stub files generated by deploytool - the reason for the ClassCastException is due to that the cast actually gets made against the server stub(s) which, in this case, isn't available to the client. The stubs are generated during deployment and have the same name as your interfaces with the suffix '_impl' (implementation). The first dialog of the deployment wizard has the option to "Return client jar" - select it (a checkbox) and add the resulting jar file (has the same name as your .ear file with the ending 'Client.jar'), to your client's CLASSPATH (just mount it as a filesystem in Forte4J ;). This file has the stubs along with the rest of your bean's associated classes.
    Can you help? I'm realy stuck.I hope this helps.
    Thanks.
    Oded "Shushu" HasidiRegards,
    Tony "Vee Schade" Cook

  • Two PCs connected via TC can't seem to communicate w/ each other

    I have two PCs running XP pro connected to a TC. The TC is also connected to a cable modem. Each PC has successfully obtained an IP address (10.0.1.2, 10.0.1.3). Each can retrieve web pages from the internet. However, they don't seem to be able to communicate with each other. I have re-run my network setup wizard on both PCs and created a home workgroup. When I try use My Network Places ... Home, I only see the local PC. If I ping the other address, the ping times out. I can ping the TC (10.0.1.1) however.
    Any ideas as to why the two computers would not be able to communicate w/ each other but can communicate w/ the internet?

    I just spoke with Apple Care. The support rep did some research and believes the problem is with settings on my computers. This network was working with a different router (and different private network addresses) before I swapped it out for the Time Capsule.
    Anyone have any ideas what might be blocking network replies (or incoming packets) on the various XP computers?

  • I've got a G5, OS 10.5, and an IBook OS 10.4.  Both can reach the internet wirelesly.  How can I make them aware of each other, so they can exchange files

    I've got a G5, OS 10.5, and an IBook OS 10.4.  Both can reach the internet wirelesly. 
    How can I make them aware of each other, so they can exchange files?  Both have network
    icons in the systems peferences, but I can't see how to hook them up.

    That got me closer, but I'm not quite there yet.  On each ofthe two computers I've allowed all users File Sharing and Remote Management.  Each computer has an address 192.168.1.2 (or 4).  When I enter those addresses into "connect to server" the reponse is either 'drop box' or 'public folder'.  So it seems that only very basic sharing is allowed. I have'nt  set up a public folder on either one.

  • How can I have two fields with the same name if it makes sense?

    Hello, folks :)
    I have a pretty hard time figuring out how I can have two text fields with the same binding name.
    The whole problem is that when I need two fields with the same binding name they are still differnent coz they have the same name but differnt indices.
    I should make a form filled at runtime by merging a pdf form file and an fdf file data file. And I have no choice to do it differently. And my form file needs some data like customerName, companyName twice in one form. But there's only one possible buinding name indexed zero.
    How can I create a field with absolutely the same name or is it just impossible due to possible name conflicts? And is there a workaround to this problem? I just need one piece of data repeated in different places.
    Thanks for your replies :)
    P.S. if u think that the problem is not clear enough let me know. I'll supply you with more details. But the general process can not be changed.
    One pdf should be mergred with an fdf with as the result of their merge a new filled and flattened form. I have no control over fdfs their are generated by Oracle and I can not fill the form using XML files coz this process should be integrated in a working application.

    I just thought about a really ugly workaround with a server-side script adding values to fdf files but it's a bit of work and tests and personally i think it's a bad idea :-(

  • How can I have one row for each object?

    Post Author: farnaz
    CA Forum: WebIntelligence Reporting
    I have 3 objcts that one of them is ID and second one is internal code and the third one is quantity.There is more than one value for each ID (becouse of internal code).I want to create a report based on ID and quantity (not based on internal code).I make a break on ID but the result shows me more than one row for each ID.so how can i have just one row for each ID?
    another question:
    how can I post screen shot of the results to my messag in forum?

    Post Author: jsanzone
    CA Forum: WebIntelligence Reporting
    farnaz:
    Have you tried to omit "internal code" from your grid?  In normal circumstances, if you have "ID" and "Quantity" on the grid, then WebI will on its own summarize Quantity based on ID, however, this is provided that Quantity has been set up as a measure (or metric).  The quickest way to tell if Quantity is a metric or not is to observe the color of its icon when you look at it in the data panel.  If it is a purple (or sometimes appears as pink or fuscia) dot, then it's a measure, but if it is a blue box then it is a dimension.  If you need Quantity as a measure then this will have to be modified at the universe (make it look like "sum(Quantity)" in the select phase of the object, and insure the object is defined as a number....

  • For WRT1900AC, how do the 4 antennae work with each other?

    I am curious how the 4 antennae work with each other.  Does a wifi client need to communicate with all 4 antennae?  Or just 1 (or 2)?  I am curious, as I would like to move 1 or 2 of the antennae via proper cable to expand the coverage area.  

    bigdave240 wrote:
    spec on that cable is 10.8dB per 100 feet. I would think that the router would still have a problem with that. Not sure how long the OP was going to make it but with the beaming technology i would think it would throw it off balance.
    My maximum is 60ft when using LMR400 for standard wireless applications. I have done that many many times.
    These days they typically integrate the higher gain antenna right into the bridge housing or mount the outdoor bridge right next to the antenna.
    Please remember to Kudo those that help you.
    Linksys
    Communities Technical Support

Maybe you are looking for