How do I make a Datagram Packet from a String?

I am looking to make a Datagram Packet from a string. If I send a command to a server that allows remote connections via UDP, such as "restart" it will restart the server. I can accomplish this easily through the fput() method of PHP.
I want a Java version of my utility, and am using the DatagramSocket and DatagramPacket classes. I see that I need to make a byte array and put it inside a DatagramPacket. How would I go about putting the string "restart" into a byte array?
Thanks,

Use the following code to send a Datagram:-
import java.io.*;
import java.net.*;
// This class sends the specified text as a datagram to port 6010 of the
// specified host.
public class UDPSend {
    static final int port = 6010;
    public static void main(String args[]) throws Exception {
        if (args.length != 2) {
            System.out.println("Usage: java UDPSend <hostname> <message>");
            System.exit(0);
        // Get the internet address of the specified host
        InetAddress address = InetAddress.getByName(args[0]);
        // Convert the message to an array of bytes
        int msglen = args[1].length();
        byte[] message = new byte[msglen];
        args[1].getBytes(0, msglen, message, 0);
        // Initilize the packet with data and address
        DatagramPacket packet = new DatagramPacket(message, msglen,
                               address, port);
        // Create a socket, and send the packet through it.
        DatagramSocket socket = new DatagramSocket();
        socket.send(packet);
}This uses argments, if you want a string change the code accordingly.

Similar Messages

  • How do I make a phone call from my mac with yosemite?

    How do I make a phone call from my MacBook Pro on the Yosemite operating system?

    The following quotation is from Connect your iPhone, iPad, iPod touch, and Mac using Continuity
    There is more information in the link, including supported hardware and that you must have Settings > FaceTime > iPhone Cellular Calls set to on on the iPhone.
    Phone calls
    With Continuity, you can make and receive cellular phone calls from your iPad, iPod touch, or Mac when your iPhone is on the same Wi-Fi network.
    To make and receive phone calls, here's what you need:
    Sign in to the same iCloud account on all your devices, including your Mac.
    Your iPhone and your iPad or iPod touch need to use iOS 8 or later. Your Mac needs to use OS X Yosemite.
    All devices must be on the same Wi-Fi network.
    All devices must be signed in to FaceTime using the same iCloud account. This means any device that shares your Apple ID will get your phone calls. Look below for instructions on how to turn off iPhone cellular calls.
    Wi-Fi Calling needs to be off. Go to Settings > Phone. If you see Wi-Fi Calling, turn it off.
    Make a call
    To make a phone call on your Mac, iPad or iPod touch tap or click a phone number in Contacts, Calendar, or Safari.

  • How can I make a still photo from imovie

    How can I make a still photo from imovie?

    Let's assume you have iMovie 11 (Version 9). (If you have a different version, let me know. The instructions will be different.)
    First, get an app called MPEG Streamclip, which is free. (google MPEG Streamclip from Squared 5)
    Open MPEG Streamclip.
    In iMovie, select the clip you need. Then, right-click/Reveal in Finder.
    Drag this clip into MPEG Streamclip
    In MPEG Streamclip, move the playhead to the frame you want.
    In MPEG Streamclip, click FILE/EXPORT FRAME.
    Choose JPEG, TIFF, or PNG and give it a name.
    You can then drag this photo into iPhoto.
    I have created a short video Tutorial on how to do this. There is one error in the Tutorial, where it says that Command-click is the same as right-click. I should have said Control-click instead.

  • How can I make an audiobook purchased from another source show up in iTunes as an audiobook and not as music?

    How can I make an audiobook purchased from another source show up in iTunes as an audiobook and not as music?
    They chapters are mp3 files. Changing the genre to "audiobook" or "audiobooks" does help.
    I am sure this question will come up a lot, since the book in question is "Harry Potter and the Deathly Hallows," purchased from Pottermore.com.

    The one thing I would add to the instructions above is that the "Media Kind" menu is on the "Option" pane in the "Get Info" Window. This procedure has allowed me not only to make imported audiobooks show up as audiobooks, but imported podcasts show up as podcasts.

  • How can i make a still frame from imovie 11 using mpeg streamline clip

    How can I make a still frame from iMovie using mpeg stream clip?

    See my User Tip here.
    https://discussions.apple.com/docs/DOC-3231

  • How can I make a PDF file from each folders with layers, where each page is a each folder?

    How can I make a PDF file from each folders with layers, where each page is a each folder?

    I found an answer to my own question. A work around of sorts.
    Download Photoshop Elements 6 for Macintosh. With PSE6 I made a slide show with 550 images 1920x1200, without thumbs. I ran into one problem making the slide show. My images contained 4 images which had not ben created by Photoshop and could not be included in the slide show. Opening the images in Photoshop CS4 and re-saving them still did not make then acceptable. Not a big deal. I probably could have fixed the four images by stripping all EXIF data before opening them in Photoshop. BTW, PSE6 made the slide show in demo mode.
    I hope the bug in Photoshop CS4 will be fixed in Photoshop CS5.

  • How Do I Make My Name Disappear From Menu Bar?

    I use Mavericks OS X 10.9.3.  How do I make my name disappear from the Menu Bar?

    Or select to show the icon instead of your name in case you want to keep the ability to use FUS while gaining precious menu bar space.

  • How to get the Values i need from a String???

    hi i need some help on my program,
    I have a Server that actually sent some data to my Client.
    The data consist of some messages and intergers . The whole piece of data is stores as a String message.
    ARRAY 'Monitor Chart' 2 5
    'Total OverFlow' 'Queued' 'Completed' 'Host Resets' 'Errors'''
    0.0 1.0 2.0 3.0 4.0
    'Series1' 11.0 0.6 8.6 11.5 6.6
    'Series2' 12.8 6.7 21.6 11.1 30.0Inside the Client i need to get the values out to showed on my textfields
    Example :
    Tf1 = 11.0
    Tf2 = 0.6
    Tf3 = 8.6
    Tf4 = 11.5
    Tf5 = 6.6
    Question: How to i get the values out from the String???

    using the split() method. i am able to split everything now
    so it appear somthing like this :
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    public class testing{
         String d1 =     "ARRAY 'Monitor Chart' 1 5";
         String d2 = "'Total OverFlow' 'Queued' 'Completed' 'Host Resets' 'Errors'";
         String d3 = "'' 0.0 1.0 2.0 3.0 4.0 ";
         String d4 = "'Series1' 11.0 0.6 8.6 11.5 6.6 ";
         String d5 = "'Series2' 12.8 6.7 21.6 11.1 30.0 ";
         String data = d1 + d2 + d3 + d4 + d5;     
         public testing(){
              System.out.println(data);
              String[] result = data.split("\\s");
              for(int x=0;x<result.length;x++)
              System.out.println(result[x]);
         public static void main (String args[])throws IOException{
            testing Application = new testing();
    }ARRAY
    'Monitor
    Chart'
    2
    5
    'Total OverFlow'
    'Queued'
    'Completed'
    'Host Resets'
    'Errors'''
    0.0
    1.0
    2.0
    3.0
    4.0
    'Series1'
    11.0
    0.6
    8.6
    11.5
    6.6
    'Series2'
    12.8
    6.7
    21.6
    11.1
    30.0
    but how do i get the values out ??how do i noe it is which index or wad?
    11.0
    0.6
    8.6
    11.5
    6.6

  • How to create a node-typed XmlValue from a String with Java?

    Hi all,
    It's already been a while since I'm trying to get how to construct a node-typed XmlValue from a String value but I keep getting different exceptions no matter what method I try.
    I started with the first way that came to my mind:
    XmlValue value = new XmlValue("<element/>"); //Even though the String represents a valid xml node, calling value.isString() returns true.
    then I thought ok, so I should maybe use the typed constructor:
    XmlValue value = new XmlValue(XmlValue.NODE, "<element/>"); //_It does not work either, calling value.isNull() returns true.
    I also tried with the rest of types (XmlValue.DOCUMENT, XmlValue.DOCUMENT_NODE, XmlValue.ELEMENT_NODE.....) and it did not work either with any of these.
    Fiinally I saw that you can construct a new XmlValue from a XmlDocument but I cannot get a XmlDocument unless I phisically create one, which obviously wont be a very good idea.
    So I'm definitely stuck with these, I would really appreciate if someone could tell me how to do this...
    Thanks in advance,
    Pablo Pareja
    PS: I'm using Berkeley dbxml 2.5.13

    Hi Pablo,
            XmlDocument doc = manager.createDocument();
            doc.setContent("<bla/>");
            XmlValue val = new XmlValue(doc);
            System.out.println(val.getType() == XmlValue.NODE);
            System.out.println(val.asString());Try this. It doesn't create physically (that is in the container) a document. The output of this piece of program:
    true
    <bla/>Hope it helps
    Vyacheslav

  • I just synced my iPhone and lost all the info in notes from my phone. It was replaced with whT was on my iMac how do you make the sync go from phone to desktop and not the other way around

    I Just synced my iPhone and lost all the info in notes I had on the phone. How do you have the info sync from phone to desktop and not the other way around as I usually make contact changes etc on my phone. I would then like to be able to sync that info from desktop to ipad thanks

    It does make sense.  The iPhone is a one-person device and just syncs to one computer.
    The way it should work is as follows:
    Old computer content ---> New computer
    New computer <---> syncs to iPhone
    But the way you are trying to operate sounds like:
    Old computer content ---> iPhone
    ... and ...
    New computer content <---> iPhone
    So simply move your old stuff (either directly from iTunes, or from a computer backup) to the new computer, have it all there, then sync your iPhone to the new machine.

  • How do I make a bootable cd from the windows .iso file

    I am trying to install windows xp on my iMac. My univeristy gives me free copy of XP but I have to download the .iso file. I tried burning the .iso file to a cd but bootcamp says it can not recognize the cd for installation. How can a make a bootable copy of the windows xp .iso file so that I can install it on my iMac.

    You used Disk Utility I take it?
    http://en.wikipedia.org/wiki/ISO-9660
    http://www.ezbsystems.com/ultraiso/
    This is for creating a custom Vista SP1 EFI-enabled DVD:
    http://www.jowie.com/post/2008/02/Select-CD-ROM-Boot-Type--prompt-while-trying-t o-boot-from-Vista-x64-DVD-burnt-from-iso-file.aspx

  • How do I make DVD with clips from 2 different iMovie files?

    For some reason, my movie clips got imported into 2 different files. And now I can't make a DVD using clips from both. Should I reimport the movies? And if so, how can I make sure they all get imported into the same file?
    Thanks!

    I apologize, but I am still unsure of what you mean...
    "When I open iMovie, at the top of the screen, it says: iMovie: 4-22-2005. But there is also another file with another date."
    There is another file where? What kind of file? Is this a clip you are talking about or another project? Another file within the project? On the clip shelf? A completely separate project folder?
    "How do I ensure that it just goes into the same file/folder?"
    When you open a project and then import clips they all go into the same folder of that project by default and by design. iMovie is not designed to allow you to import some stuff here and some stuff there. When you create a project, a folder system is setup and in that main project folder is a media folder. All your work files (video footage, audio files, etc.) get put into that folder and no others.
    Patrick

  • How can I make mac except capture from my canon xlh1?

    How can I make my imac recognize my canon XL1 Camcorder in Final Cut Express

    Assume you are connected by Firewire, and that FCE has Import in some menu? Also check FCE Forum https://discussions.apple.com/community/professional_applications/final_cut_expr ess_hd?view=discussions.

  • How do i make a phone call from my mac

    i can't make a phone call from my mac nor receive phone calls

    NO my mac is on a different wi-fi than my phone

  • How to make a class object  from a string representation of the same

    i have the name of a class whose object i want to make in the form of a string i.e. String s="S1"; i get this name after some prosessing. so what i want to do is to create an object of S1 which is actually one class that i have implemented.plz hlp. it is urgent.thnx in advance.

    reflection api...
    see java.lang.Class. Read the api docs.
    mostly, u need to do the following:
    Class myClass = Class.forName(s1);
    Object x = myClass.newInstance();
    reg
    s giri

Maybe you are looking for

  • How do you retrieve iTunes media from many locations to one file

    I have all Mac devices. The particular item I have a question about is my itunes media file.  Since I have a very large collection, I was advised by apple support to move my Itunes Media folder to the 1.5T wireless WD hard drive I have. All was going

  • Time machine started over after a complete restore, how to get to older?

    Yesterday, photoshop and parrallels started crashing and I could not get them working, So I decided to do a complete system restore from install disk time machine from the day before when everything was working fine. so it restored the system to its

  • Firefox crashes when opening and will not open in safe mode

    Recently FF3 started crashing when opening. It will not open in safe mode as well. I have uninstalled it including deleting the install folder and profile folders as well as registry entries. Upon reinstallation is will still not launch in any mode.

  • WRT300N signal needs to be extended without wires.

    I am approximately 80 feet from our WRT300N router and receive a 40% signal on my desktop PC using the WUSB300N network adapter.  That is the highest I have ever connected at.  It usually works fine unless someone else is using the wireless network,

  • Zoom in Survey Mode

    It would be quite useful to be able to zoom the image reslolution in survey mode the same way we can in compare mode. This would speed, among other things, the ability to scan a group of images at the same time at 1:1 resolution to eliminate those th