Help: Send and Receive through Datagram Socket

I am trying to create a client/server using Datagram Socket (UDP) as communication. I have a Recive and a Send class that implements runnable and are responsible for receiving and sending of message. I have two other classes Server and Client that are utilizing these. Now i can get the receive and send to work fine, but i am having trouble retrieving the message from the receive thread that i created in each of server/client. I've tried inserting a method so the server/client can call on to get the message (Receive.Get_Message()) but unfortunately this isn't working as i wanted. Since my server and clients are not implemented as runnables, i can only issue the command in some serialize fashion. What i really want to do is that whenever the message is receive by the Receive thread, it will immediately be send back to server/client and display right then, independent of what i was doing. (i have a command interface for S/C so it just sits there to wait for command, now what i would like is to have the S/C display the message it gets immediately after it gets it even when it's waiting for user input. since my program is waiting for a command, i really could not use the method describe above to achieve this) Could anyone help me with this?
Thanks!
Hung-Hsun Su

u cant use the observer pattern. or at least i can't figure out how to implement it with sockets.
you should use threading.
public void run()
  while(true)
     //keep reading from socket
     InStream output = socket.getInputStream();
     InputStreamReader ir = new InputStreamReader(output)
     BufferedReader reader = new BufferedReader(ir);
     String s = null;
     while(s == null)
       s = reader.readLine();
     //then do whatever you want to the received string "s"
}

Similar Messages

  • Does the ibackupbot help send and receive picture msg through T-Mobile network?

    I got my friend an unlock iphone 4s on a T-mobile. He have data and can send picture msg, BUT cant recieve! How can he fix this? I heard the ibackupbot works, but have anyone tried it and it works???

    T-Mobile in the US? I've heard of people getting it to work, but there's very little anyone here can help you with. T-Mobile in the US is not a supported carrier and is not fully compatible with the iPhone.
    The like to brag about how many unlocked iPhones are on their network. Perhaps their support people can tell you what you have to do.

  • Can u tell how to send the pictures using datagrams sockets in java

    hi to all, i am making chat application , i am datagrams socket(packets) for sending and receiving messages . datagrams only send and receive messages in bytes . can u tell me how to send the picture to other person using datagrams.
    Thankyou.

    look her
    http://forum.java.sun.com/thread.jsp?forum=31&thread=330989&tstart=0&trange=15
    and look up Serialisation

  • Help!!! My text application on Blackberry Torch 9800 disappeared!!! I can't send and receive texts :-(

    Hi everyone,
    I need your help!!!
    The application to send and receive text does not appear on my phone Blackberry 9800 anymore... So, I can't send and receive texts...
    I tried lots of things but the problem is still existing.
    I have one error message everytime I turn on and reset the phone: "Uncaught exception: Index 14 >= 14" !!!
    Any idea of what to do???
    Thanks
    Rachel

    Hi and Welcome to the Community!!
    There's pretty much no diagnosing those -- they are the equivalent of the random errors in Windows for which tracing the root cause is fruitless. Basically, these are the last out in the programming code -- some event occurred for which there is no handler in the code. The fix is a code update that handles the event...but, again, knowing what the event is is pretty much impossible. So, there are a few things to try:
    Sometimes, the code simply becomes corrupt and needs to be refreshed -- just like a reboot:
    Anytime random strange behavior or sluggishness creeps in, the first thing to do is a battery pop reboot. With power ON, remove the back cover and pull out the battery. Wait about a minute then replace the battery and cover. Power up and wait patiently through the long reboot -- ~5 minutes. See if things have returned to good operation. Like all computing devices, BB's suffer from memory leaks and such...with a hard reboot being the best cure.
    If it won't boot up cleanly, then you may need to try Safe Mode:
    KB17877 How to start a BlackBerry smartphone in safe mode
    There might be an updated code set from the carrier -- check them via this portal:
     http://na.blackberry.com/eng/support/downloads/download_sites.jsp
    The toughest possible cause is a badly behaving app. To find it, there are a couple of options. One is to see if you can read the log file:
    Go to the home screen. Hold down the "alt" key and type 'lglg'. (You will not see anything while you type).This will bring up the log file. Scroll down (probably many pages) untill you see a line that says 'uncaught execption'. Click on this line. The name of the app will be in the info. Alternative methods for bringing up the logs are in this KB:
    KB05349How to enable, access, and extract the event logs on a BlackBerry smartphone
    The other method is to remove apps one at a time, waiting a while in between (I usually recommend a week), until the problem ceases...thereby discovering the offending app. Still another method is to reload the BB OS cleanly, leaving some time between adding other apps onto the BB so as to be able to determine exactly which one is the cause.
    Good luck and let us know!
    Occam's Razor nearly always applies when troubleshooting technology issues!
    If anyone has been helpful to you, please show your appreciation by clicking the button inside of their post. Please click here and read, along with the threads to which it links, for helpful information to guide you as you proceed. I always recommend that you treat your BlackBerry like any other computing device, including using a regular backup schedule...click here for an article with instructions.
    Join our BBM Channels
    BSCF General Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • Is there a software in which I can hook up my iPhone 4s to my computer and send and receive text messages and calls (via headset) through my computer?

    Is there a software in which I can hook up my iPhone 4s to my computer and send and receive text messages and calls (via headset) through my computer? Whether it's free or cost money, can someone please give me a name of a program or software that allows me to do this? I can't seem to find anything like this for the iPhone.

    No.

  • TS2755 Me and my wife r sharing the same Apple ID, with the conversion IOS7 all of a sudden my wife can read all my sended and received iMessages! What t.f is going on? I tried all kind of things, pls help

    Gentlemen,
    Me and my wife r sharing the same Apple ID, with the conversion to IOS7 all of the sended and received iMessages on my phone comes in also on my wife's phone! Tried all kind of things, pls help
    Marco

    Are you both using the same Apple ID?
    What do you have here:
    Settings > Phone > My Number > ?

  • Sending and receiving Signal through Internet connection

    Hello,
    I want to send data that is a continuous generated signal through internet.
    I want to transmit this signal live through internet technology.
    I don't have any background of web development
    Can anyone suggest me how could I send and receive data using internet.
    Regards

    Hello,
    I have made a basic VI using Network Stream, it send Random Number generator which i want to plot on a waveform chart on the other side.
    But when i run the VI on continuous mode it gives an error as End point broken on the client side.
    Kindly guide where i am lagging.
    Regards
    Attachments:
    streams.vi ‏14 KB

  • My messages are not going through or coming in from other iOS devices.  Having to send and receive in SMS.  What is up?

    My messages are not going through or coming in from other iOS devices.  Having to send and receive in SMS.  What is up?  Anyone else having these issues?

    There's an article that Apple has acknowledged this issue. They recommend turning off imessages, reset all settings and then reactivate imessages.
    If that doesn't work, you may just have to wait until they release an update, which should be pretty soon.

  • BPM when both sender and receiver systems are Sync. Please help!

    Hi Experts,
       I want to use BPM when both sender and receiver systems are Sync. For example: web service ---> RFC
    I have tried the solution as given in the blog
    https://weblogs.sdn.sap.com/pub/u/39730 [original link is broken] [original link is broken]
    but it does not work. I am getting Time Out error.
    Can somebody tell me the correct way of configuring BPM for sync-sync scenario?
    Kindly give the integraion directory steps also.
    Thanks
    Gopal

    Hi Hemant,
       I have already tried the solution as given in the blog (https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/1403 [original link is broken] [original link is broken] [original link is broken])but it does not work. When I run the scenario I am getting Time out error.
    <SAP:Error xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:mustUnderstand="1">
      <SAP:Category>XIServer</SAP:Category>
      <SAP:Code area="INTERNAL">PL_TIMEOUT</SAP:Code>
      <SAP:P1 />
      <SAP:P2 />
      <SAP:P3 />
      <SAP:P4 />
      <SAP:AdditionalText />
      <SAP:ApplicationFaultMessage namespace="" />
      <SAP:Stack>Timeout condition of pipeline reached</SAP:Stack>
      <SAP:Retry>N</SAP:Retry>
      </SAP:Error>
    Please help!
    Thanks & Regards,
    Gopal

  • Help please:set up mac 10.4.11 with ext dsl modem to send and receive faxes

    Hi and thanks in advance. I have a G4MDD dual processor, and have a dsl modem for internet connection. I want to set up to send and receive faxes. I can make and receive phone calls while connected to the internet. any ideas or help appreciated. Thanks again.
    Message was edited by: R.Andom

    I cannot send/receive faxes via my dsl, I have to use my regular phone line. (My DSL modem only has one phone jack port, and that is to connect it to the outside world. Pretty sure this is true of every DSL modem.)
    When I need fax capability, I unplug the phone line to my telephone at the phone end, and plug that cable into the modem port in the back of the G4. (The modem is built-in.) After sending / receiving, I switch the cable back to the phone.
    You set up fax capability in System Preferences / Print and Fax.

  • I'm unable to send and receive email through Apple Mail 4.  I've checked my settings on Preferences, and my password to Gmail is up to date for syncing with IMAP, but it still won't connect.  Suggestions?

    I'm unable to send and receive email through Apple Mail 4.  I've checked my settings on Preferences, and my password to Gmail is up to date for syncing with IMAP, but it still won't connect.  Suggestions?

    I think it's trying to open it in a gMail eMail & is losing your gMail password that it needs log into gMail, but not 100% positive.
    Have you tried Right clicking or Control+click on the eMail link & choose Copy? Works on some, not others.

  • Can't send and receive icloud email. Mountain Lion user. Please help.

    Using OS X Mountain Lion. Can't receive and send mails in icloud. please help. Thank you.

    After my post, suddenly and unexpected, i was able to send and receive messages. So posting in this community helps

  • HT5622 Unable to send and receive iMessages, help!

    For some reason, I am suddenly unable to send and receive Imesages? Iv rang Vodafone customer services, who were no,help at all.
    Iv tried lots of suggestions on the internet, but no luck!
    Any help would be appreciated
    Thanks

    Hello, Theresa132. 
    Thank you for the question.  The article below will help you troubleshoot your issue with iMessage.
    iOS: Troubleshooting Messages
    http://support.apple.com/kb/ts2755
    Cheers,
    Jason H.

  • Can I send and receive e-mails on my iPad through Verizon?

    Can I send and receive e-mails on my Ipad (third generation) the same as I do on my iPhone 4s? Both are through Verizon. And if I can, where do I set it up at? Thanks.

    Yes. Why couldn't you use the same email account?
    Settings>Mail, Contacts, Calendars>Add Account>Other. Start there.

  • Hi, imessages won't send from my macbook pro. I am still able to recieve them on mac. I am also able to send and receive on iphone. However on mac every time i press send (enter/return) it disappears, with no red '!' or anything. Any help?

    Hi, imessages won't send from my macbook pro. I am still able to recieve them on mac. I am also able to send and receive on iphone. However on mac every time i press send (enter/return) it disappears, with no red '!' or anything. Any help?

    Triple check the Outgoing Mail server info that you entered in your Mail account. If that area says the info is optional enter the outgoing mail server and your password anyway. Also if you have more than one email account check the server that is selected for the GoDaddy account and make sure it's the correct server for the account.

Maybe you are looking for

  • Numeric getting multiplied by 10 at table level

    Hello Experts, 1) When we save PO, suppose if we have 1 Qty , netprice = 80, it is getting saved in PO as it is. Whereas at table level, it is getting multiplied by 10 and the value  800 is getting saved at the table level. 2)Even in material master

  • BB 9300 won't detect Wifi

    Hi,  I am wondering why my BB 9300 won'z detect any wifi networks. Even if I set up an ad-hoc network without security on my laptop and have the BB right next to it, it would not detect any wifi networks, which is kind of strange.  I run OS 6, all ot

  • Setting $PATH using the terminal

    Hi All! I am a newbie with OS X and I am wondering as to how to add a directory into the PATH using the terminal. Thank you very much!

  • FreeNX, black screen.

    Hi all, i686 here. Chakra installed ok. I'm trying to make nxserver, freenx package, run. But after the NM logo I get a black screen and nothing more. Client is working fine with another nx server, ubuntu based. I've followed the indications at the A

  • AnyConnect List of Gateways in Connection Tab

    Some of our users (e.g. researchers, technicians,...) need to connect to multiple VPN Gateways outside the scope of our Installation, often alltogether  different companies. They find it tedious to manually change the gateway in the connection tab ba