UDP Sender and Receiver.

Hi! I want to know if it is possible to convert the file UDPSender.java into a method that can be called by clicking a button? I slightly modified the UDPReceiver.java for it to be listening indefinitely and UDPSender.java I found on the net. And I created a what is supposedly my main file called Button.java.
What I want to do is that for this Button.java which only has a button when clicked is supposed to do a UDPSender. But I have no idea how to do it. Hope someone can answer this.
====================================================================================================================
====================================================================================================================
The code below is for UDPReceiver.java
====================================================================================================================
====================================================================================================================
* @(#)UDPReceiver.java
* @author
* @version 1.00 2008/10/19
import java.net.*;
import java.util.*;
import java.io.*;
public class UDPReceiver {
     * Creates a new instance of <code>UDPReceiver</code>.
    public UDPReceiver() {
     * @param args the command line arguments
    public static void main(String args[]){
        try{
             //Bound to socket 7 for receive
             DatagramSocket socket = new DatagramSocket(7);
             System.out.println("Bound to local port " +socket.getLocalPort());
             while(true){
                  //Create packet of 512 byte length
                  DatagramPacket packet = new DatagramPacket(new byte[512], 512);
                  socket.receive(packet);
                  System.out.println("Packet received at " +new Date());
                  //Display packet information
                  InetAddress remote_addr = packet.getAddress();
                  System.out.println("Sender: " +remote_addr.getHostAddress());
                  System.out.println("from Port: " +packet.getPort());
                  //Display packet contents, by reading from byte array
                  ByteArrayInputStream bin = new ByteArrayInputStream(packet.getData());
                  //Display only up to the length of the original UDP packet
                     for(int i=0; i<packet.getLength(); i++){
                       int data = bin.read();
                       if(data==-1)
                            break;
                       else
                            System.out.println((char)data);
        catch (IOException e) {
               System.out.println ("Error - " + e);
}====================================================================================================================
====================================================================================================================
This code is for UDPSender.java
====================================================================================================================
====================================================================================================================
* @(#)UDPSender.java
* @author
* @version 1.00 2008/10/19
import java.net.*;
import java.util.*;
import java.io.*;
public class UDPSender {
     * Creates a new instance of <code>UDPSender</code>.
    public UDPSender() {   
     * @param args the command line arguments
     public static void main(String args[]){
         //Set hostname and message
        String hostname = "localhost";
        String message = "Hello";
        try{
             //Create a datagram socket and look for the first available port
             DatagramSocket socket = new DatagramSocket();
             System.out.println("Using local port: " +socket.getLocalPort());
             ByteArrayOutputStream bOut = new ByteArrayOutputStream();
             PrintStream pOut = new PrintStream(bOut);
             pOut.print(message);
             //Convert printstream to byte array
             byte[] bArray = bOut.toByteArray();
             //Create a datagram packet containing a maximum buffer of 512 bytes
             DatagramPacket packet = new DatagramPacket(bArray, bArray.length);
             System.out.println("Looking for hostname " +hostname);
             //Get the InetAddress object
             InetAddress remote_addr = InetAddress.getByName(hostname);
             //Check host IP
             System.out.println("Hostname has IP address = " +remote_addr.getHostAddress());
             //Configure DatagramPacket
             packet.setAddress(remote_addr);
             packet.setPort(7);
             //Send packet
             socket.send(packet);
             System.out.println("Packet sent at " +new Date());
             //Display packet information
             System.out.println("Sent by: " +remote_addr.getHostAddress());
             System.out.println("Send from: " +packet.getPort());      
         catch (UnknownHostException ue){
               System.out.println("Unknown host "+hostname);
          catch (IOException e) {
               System.out.println ("Error - " + e);
}====================================================================================================================
====================================================================================================================
This is supposedly my main class file:
====================================================================================================================
====================================================================================================================
* @(#)Button.java
* @author
* @version 1.00 2008/10/16
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.Applet.*;
public class Button extends JApplet implements ActionListener{
     public static void main(String[] args){
     JFrame frame = new JFrame();
     frame.setVisible(true);
     JPanel panel = new JPanel();
     JButton button = new JButton("send text");
     panel.add(button);
     frame.add(panel);
     frame.pack();
     public void actionPerformed(ActionEvent evt) {
          //Button.EchoClient();
}Edited by: Eastsheen on Oct 20, 2008 12:33 AM

You could call UDPSender.main(new String[0])

Similar Messages

  • UDP Send and Receive with Remote Host Only Issue

    I am seeing an issue using the UDP Sender and UDP Receiver example VIs that ship with LabVIEW. If I open the VIs and do not change any of the settings and run the UDP Receiver VI and then the UDP Sender VI the Receiver VI never reads anything. However if I change the boolean on the UDP Sender VI to broadcast it works fine.  
    The example program by default uses localhost so I have also tried to use the UDP Receiver on my Real Time controller and the UDP Sender on my laptop with the boolean set to remote host only and the remote host string set to the ip address of my real time controller and this did not work either. But if I change the boolean to broadcast it works.
    I would like to be able to send to a remote host only and not have to broadcast my UDP message to everyone.
    Please let me know if you have any suggestions.
    Thanks,
    Russell 
    Engineering Team Leader
    G Systems, www.gsystems.com
    Certified LabVIEW Architect
    Certified Professional Instructor

    Elizabeth,
    Thank you for the response. I am using LV 8.2.1 and wasn't seeing any errors. 
    However I am not seeing the issue today, I must have been an issue with our network yesterday.
    Thank you,
    Russell 
    Engineering Team Leader
    G Systems, www.gsystems.com
    Certified LabVIEW Architect
    Certified Professional Instructor

  • Send and receive UDP data package based on siemens TC65 module

    Everyone:
    I am newer for J2ME. I have a TC65 module, I want to get a sending and receiving UDP data package exeample codes running on TC65. who can help me? thanks!

    Hi deepspace,
    I programmed a demo codes and run it on TC65T, debug trace like :
    at^sjra=a:/NetDemo.jar
    OK
    NetDemo: Constructor
    NetDemo: startApp
    NetDemo: Profile could not be activated
    NetDemo: destroyApp(true)
    // below is demo codes, can you help me where error is?
    package example.netdemo;
    import javax.microedition.midlet.*;
    import java.io.*;
    import javax.microedition.io.*;
    import javax.microedition.io.Datagram;
    import javax.microedition.io.DatagramConnection;
    public class NetDemo extends MIDlet {
    public NetDemo()
    System.out.println("NetDemo: Constructor");
    public void startApp() throws MIDletStateChangeException
    System.out.println("NetDemo: startApp");
    try
    DatagramConnection conn = (DatagramConnection) Connector.open("datagram://58.185.157.91:12003");
    byte[] buffer = new byte[32];
    Datagram dgram = conn.newDatagram(buffer, buffer.length);
    for (int i = 0; i < 30; i++) {
    buffer[i] = (byte)('0' + (i % 10));
    conn.send(dgram);
    catch (Exception e)
    System.out.println("NetDemo: " + e.getMessage());
    destroyApp(true);
    public void pauseApp() {
    System.out.println("NetDemo: pauseApp()");
    public void destroyApp(boolean cond) {
    System.out.println("NetDemo: destroyApp(" + cond + ")");
    notifyDestroyed();
    }

  • Node failed to join the cluster because it ould not send and receive failure detection network messages

    One of my customers has a Windows Server 2008 R2 cluster for an Exchange 2010 Mailbox Database Availability Group.  Lately, they've been having problems with one of their nodes (the one node that is on a different subnet in a different datacenter) where
    their Exchange databases aren't replicating.  While looking into this issue it seems that the problem is the Network Manager isn't started because the cluster service is failing.  Since the issue seems to be with the cluster service, and not Exchange,
    I'm asking here. 
    When the cluster service starts, it appears to start working, but within a few minutes the following is logged in the system event log.
    FailoverClustering
    1572
    Critical
    Cluster Virtual Adapter
    Node 'nodename' failed to join the cluster because it could not send and receive failure detection network messages with other cluster nodes. ...
    It seems that the problem is with the 169.254 address on the cluster virtual adapter.  An entry in the cluster.log file says: Aborting connection because NetFT route to node nodename on virtual IP 169.254.1.44:~3343~ has failed to come up. 
    In my experience, you never have to mess with the cluster virtual adapter.  I'm not sure what happened here, but I doubt it has been modified.  I need the cluster to communicate with its other nodes on our routed 10. network.  I've never experienced
    this before and found little in my searches on the subject.  Any idea how I can fix this?
    Thanks,
    Joe
    Joseph M. Durnal MCM: Exchange 2010 MCITP: Enterprise Messaging Administrator, Exchange 2010 MCITP: Enterprise Messaging Administrator, MCITP: Enterprise Administrator

    Hi,
    I suspected an issue with communication on UDP port 3343. Please confirm the set rules for port 3343 on all the nodes in firewall and enabled all connections for all the profiles
    in firewall on all the nodes are opened, or confirm the connectivity of all the node.
    Use ipconfig /flushdns to update all the node DNS register, then confirm the DNS in your DNS server entry is correct.
    The similar issue article:
    Exchange 2010 DAG - NetworkManager has not yet been initialized
    https://blogs.technet.com/b/dblanch/archive/2012/03/05/exchange-2010-dag-networkmanager-has-not-yet-been-initialized.aspx?Redirected=true
    Hope this helps.
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • Cannot send or receive email from the cloud. all updates are competed and everything else is working fine on MAC. iPad sends and receives fine. any ideas.

    On Imac I am not able to send or receive messages. All software is updated. My iPad that uses the same email address and the Cloud, sends and receives just fine. It is not "the colored" thing that is spinning but the little black and white circular icn that is spinning away. My other email address is functioning fine. It is merely the ICLOUD based email that is acting up. Any ideas?

    First try deleting the account and reinstall it.

  • Trouble send and receiving messages and trouble calling people or receiving phone calls

    Hello everyone, I bought a Blackberry Q5 one year ago and has worked perfectly since but on christmas day I had was struggling to send message to people I thought nothing of it since it was christmas and people would be wishing there families and friends a merry christmas. So i just carried on as usual not aware that the problem was much worse then i thought, since then I have tried time and time again to try text people and call them but nothing would happen.
    The Problems I am experiencing,
    Everytime I try sending a message it fails and times out after a while doesn't matter whom they are being sent to it's the same story no matter who I send them to, and then of course when i try calling someone the phone goes to the calling screen but doesn't make a sound for atleast 10 seconds then a message pops up saying "Call Failure, The call could not be connected. Please try again later". This message appears even when I ring '789' which is the number to find out what my balance is on my contract.
    At first I thought it was the Sim what was cauing the problems but when i swapped it into another Virgin phone i received quite an alarming amount of messages what would not come through on my phone, this is when i realised I am not just struggling to send messages but to receive them as well. I have scoured the internet for possible answers but nothing has worked, so far I have tried manually scanning for available networks and selecting the correct one which did not change the problem this didn't make things better nor did it make things worse.
    I have also tried changing the data services while roaming settings which again did not make any differences, I have tried changing network mode no changes again, turning the mobile network off all together and then turning it back on after 5 minutes no success there either. I have even reset the phone back to factory setting to try and fix the problem, but no, the problem still will not go away.
    Please if there is anyone out there who has any ideas on how to fix what is happening to my phone please do give me your advice, at this moment I really need a miracle to come around at the next corner.

    Hi rhupa!
    Here is an article that will help you troubleshoot this issue:
    OS X Mail: Troubleshooting sending and receiving email messages
    http://support.apple.com/kb/ts3276
    Mail Connection Doctor shows one or more red dots in the account Status column
    Check your Incoming IMAP or POP and Outgoing SMTP email account settings
    Use Apple's online Mail Setup Assistant to discover what the correct settings should be for both your Incoming (IMAP or POP) and Outgoing SMTP email servers. If your email service provider is not listed in the Mail Setup Assistant, visit your email service provider's website or contact their support staff to get the correct settings. You can use this "cheat sheet" when asking your email service provider about the settings you need.
    After you have the correct email service provider settings, make sure Mail is configured properly.
    Click here if your Incoming and Outgoing email account settings are correct, but the issue persists
    Thanks for coming to the Apple Support Communities!
    Regards,
    Braden

  • Not receiving texts from iPhone contacts when I'm not connected to wifi or cell data. I can't send and receive regular SMS texts with non iMessage users but iMessage users message are not being converted to text when I don't have internet connect

    I can send and receive to any non iPhone user. I can send a message as a text to an iPhone user but if I'm not connected to cellular data or wifi I do not receive messages from iPhone contacts. From what I understand these message should automatically send to me as texts instead of iMessages but since the update it's not functioning properly. Please help. I've tried turning iMessage off and I still don't receive the messages until after I reconnect to wifi.

    I have the same problem! Before the upgrade, if I wasn't connected to the internet, any messages sent to me from an iphone would convert automatically to a text message. I have payg tarriff, so I turn cell data off, as it costs too much to use it. I have wifi at home and work, but if I'm out and about, I don't receive texts from iphone users until I'm on wifi. I get them ok from non iphone users. There was never any problem until ios7

  • TS2755 I have 3 phones on one Icloud account. It has been this way for over a year with no issues. After and update on of the lines started getting text messages from all 3 phones. We fixed the send and receive and it was fixed. It is doing it again.

    I have 3 phones on one Icloud account. They have been this way for over a year. After an update last week one of the phones started getting messages for all of the other lines. We fixed this under the send and receive under settings. It was fine for a few days. Suddenly it started happening again. Yesterday after two hours on the phone I changed my apple id and it is still happening. Before that Verizon had told me to turn off my imessage when that happened I could not get any texts at all from other Iphone users.

    Make 3 different iCloud accounts and use ONLY for iMessage.   That will permanently fix your issue.

  • Problem with Send and Receive Emal In SAP System

    Hi gurus!
    I have a following quote:
    Dear !
    I have a problem with send and receive email in SAP system following :
    I want to test send and receive email in local network at my company. I
    had two server
    Server 1 : I setup Exchange Mail Server 2007 with domain controller is
    fes.com
    Server 2 : I setup SAP ERP ECC 6.0
    On Server 1 : I created 2 account ( u1Afes.com and u2Afes.com ) and then I tested send and receive email between u1 and u2 in local network through Microsoft Outlook 2007 -> OK
    and then
    On Server 2: I had configured send and receive email on SAP system
    through tcode SBWP, SCOT and SOST as Note 455140 - "Configuration of
    e-mail, fax, paging or SMS using SMTP"
    for example :
    I logged in SAP system with user Basis01 (with email u1Afes.com ) -> then,using tcode SBWP -> new message -> send to u2Afes.com with Internet Mail type and then status message with green light -> sending ok
    and then I have used Microsoft Outlook 2007, I logged with account u2 ->check email -> Ok. I saw message which send from u1
    Finally, My problem is how can receive mail in SAP system without using Microsoft Outlook
    For example:
    Login system SAP with Basis01 account (with  u1Afes.com ) -> tcode SBWP ->New Message -> send to u2Afes.com
    and then
    Login system SAP with Basis02 account (with u2Afes.com ) -> tcode ??? ->
    To receive email from Basis01 (with u1Afes.com )
    Please help me now
    Thanks
    I replace "@" with "A" because of banning email of this forum.
    This quote is about sending email in local network. And we can't receive any email from the outside email address. Addition if I wanna send email to internal email in Internet (we've just tried with email address in local network) What should I config in SAP and Exchange ?
    By the way, Is SAP Server IP added to Relay Agent for sending or receiving mail ?
    Regards
    An NLP
    Edited by: An NLP on Apr 6, 2010 7:03 PM

    Hi,
    This problem is a classic problem of mail routing via Exchange. Exchange like most mail servers use the domain part of the email address as a means to route mails. So I will make an assumption that your main company mail addrss is "User @ fes.com".
    So when you send a mail to the "User @ fes.com mail" address the mail is delivered to your Outlook mail address as this is the default route for company.
    (Q) So how do you get your Exchange server to relay the mail into the sending SAP system?
    (A) The easiest way would be to setup and unique mail domain for your SAP system. I always recommend "user @ client.sid.company.com" which in your case would be "u1 @ 100.PRD.fes.com". You can then instruct Exchange to send any emails addressed to 100.PRD.fes.com domain to your SAP system. Also using this format of address you can configure multiple mail connections into multiple SAP systems.
    (A) Another answer would be to enter the "Full" email address (LOcal and Domain part of address) into the routing rule for Exchange e.g. "U1 @ fes.com" so that all emails addressed to this user will be delivered into SAP. However this method requires a lot of Admin as you will have to update Exchange with ALL email address that need to receive emails. Also if your corporate mail address is "U1 @ fes.com" then all mails will be forwarded to SAP.
    I would definitely NOT recommend this method but the decision is up to you.
    P.S. The IP address of the SAP system is entered into the mail header of the email. This is standard practice in SMTP relay. You can suppress this header in Exchange
    Hope this helps
    Michael

  • Problem with sending and receiving e-mail through exchange [GMail]

    Hello I have problem with sending and receiving e-mail.
    all is well set, username and password are correct, the server set m.google.com. verification of data is about like stepping into a post and want to check the post office gives me an error message: Can not Get Mail. The connection to the server has failed
    I have this problem on my two iPhone

    http://www.zdnet.com/google-drops-exchange-activesync-support-for-free-email-acc ounts-7000008836/

  • 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.

  • I am having trouble with iMessage being activated. It has worked up until yesterday and now won't activate and is saying no address in the send and receive section. My number is there but not ticked. Any suggestions on how to fix this?

    I am having trouble with iMessage being activated. It has worked up until yesterday and now won't activate and is saying no address in the send and receive section. My number is there but not ticked. Any suggestions on how to fix this? I have shut down my phone, but still no luck!

    iMessage and FaceTime went down yesterday for some people. Mine is still down. My iMessage is saying the same thing about being activated. Sounds like you are still down too. Ignore the status page that says everything is fine - it lies.

  • Need to use only one sender and receiver communication channel.

    Hello Experts.
    I have a scenario where in I have to use only one sender and receiver communication channel to push files from different source directories to different receiver directories.
    For Eg;
    Sender                              
    D://dir1/file1 --->                  E://dir1/File1
    F://dir2/file2 ---->                 G://dir2/file2
    H://dir3/file3----->                 I://dir3/file3.
    Can this be achieved by using pass through scenario?
    Please let me know if the requirement is not clear.     
    Thanks in advance.
    Advit Ramesh

    Hi Advit,
    I think it is possible. You have to use the Advanced Selection for Source file in the sender channel to define multiple files to be picked up. Also, the Dynamic configuration must also be enabled and used in the mapping so you can manipulate the target directory and target file name based on your source files.
    For Polling from multiple directories:
    http://wiki.scn.sap.com/wiki/display/XI/File+Sender+Adapter+-+Polling+Multiple+Directories
    Dynamic Configuration:
    Dynamic file name and directory in Receiver File Adapter - summary of possibilities - Process Integration - SCN Wiki

  • HT4628 I am able to download updates and send and receive email so I know I have connection to my wireless router. However, when I click on Safari, I get the message "Safari quit unexpectedly." What is my problem and how do I solve?

    When I click on Safari, I get the message "Safari quit unexpectedly." I know I have access to my wireless net work because I just found and downloaded updates and can send and receive mail. What is my problem and hoe is it solved?

    As Outlook is not an Apple product, you will find more helpers familiar with Outlook here:
    Office for Mac forums

  • Can 2 people in different locations at the same time import, access, send, and receive the same messages from the same email account

    I import messages into Thunderbird. I send and receive emails. One of the things I like about Thunderbird is that I can insert (image, link, etc) right where I want to, and I can Attach. But not just a simple attach file. No, I can also click Attach and choose Webpage. A lot of web-based emails are plain, simple, no frills - Attach file and that's it.
    So I need to have my client be able to do the same thing I do when sending out emails, Namely sending out emails with an Electronic Press Kit (EPK) attached - which is to say, a webpage (not a pdf in our case). So, I need her to download, install, and use Thunderbird.
    Here's the problem and my question. She needs to access, send, and receive from my email account. That would be easy if it was simple attach files - she could just login on the web, go to squirrel mail and bang it out.. Here it is: She needs to be able to import the messages to be able to reply to some messages - she needs access to what I have access to. She needs to use Thunderbird so she can take advantage of the features like insert image with link or attaching a webpage. My question is how will this affect my use? Can 2 people simultaneously and from different locations access and use the same email account or is it a case where her importing the emails would cut me off..Is it an either or thing? Basically, can her and I both import the emails or can they only be imported to one location at a time. Because every time someone sends me an email i get it right there on my Thunderbird application..it's imported to my Thunderbird..I want her and I to be able to do that without affecting each other. I don't want her to start importing to her desktop and then I can no longer import. If she says "point those messages to my computer what will happen to my ability to access them on my computer in the same manner I am currently?

    I think there is a contradiction in your requirements. You want two people to share an account and you don't want either to interfere with the other.
    The short and simple answer is to use IMAP to connect to the mail server. If your current email provider doesn't offer IMAP, find another that does. This is old technology already and it's disgraceful that some email providers haven't yet put it in place.
    IMAP means that your messages are stored on the server and both of you will see exactly the same set of messages. And therein lies the contradiction; you will both see changes made by the other so you are inherently interfering with one another.
    Caveats: some providers may not permit you both to access the account concurrently, and even if they do, things may become interesting if you both choose to work on the same message simultaneously.
    Note that all of this is about email servers and protocols; your choice of Thunderbird as your email client has little bearing on the situation.

Maybe you are looking for

  • Foreign Trade Data Incompletion Log

    If a billing document is missing foreign trade data required for the incompletion procedure should this prevent the posting to accounting? Or is the incompleted data only required for intrastat reporting? Thanks Caroline Tubby

  • Change in Scheduling Agreement

    Hi Experts Scheduling agreement is released through release indicator 1(No change possible) and also outputted. Now user wants to cancel the release but its throwing error as: "Document already outputted". Is there any wayout to cancell / change/rele

  • "Info" Sharp, "Edit" blurry on iPhoto'11. Why?

    I uploaded photos taken yesterday with my new Nikon D600. Images were around 9 mb jpeg, some more and some less. I noted that when I was in the "Info" mode, the images were perfectly crispy from one to the next. Upon switching from the Info to Edit,

  • Undo tablespace issue

    Hello, I have a question regarding undo tablespace utilization. Currently there are no active transactions, all previous transactions have been commited, there is only one user session on my test database, undo retention is set to 900. I am trying to

  • My videos in my iweb after i uploaded it doesn't work

    hi. anyone can help me what to do about mt iweb prob.. i upload my site already but unfortunately all my videos in my website doesn't work at all, when i clicked the movie it only shows quicktime logo and a ? mark.. what can i do to play my movies?