Putting a ( String into a byte[] to send through a datagram)

I am making a program in java to send email in the form of an applet. I am not sure it is going to work but this is what I have so far:
import java.awt.*;
import java.io.*;
import java.net.*;
import javax.swing.event.*;
public class EmailSender extends JFrame
public void init()
//user types in email address
String recieveaddr = "";
JTextField emailaddr = new JTextField(15, recieveaddr);
//user types in his body of the email
String message = "";
JTextArea body = new JTextArea(50,50, body);
//user presses submit button to send email
JButton submit = new JButton("submit", emailaddr, body);
public void run()
  try{
/*I chose to use Datagram for my method to send the email.  I thought about Tcp.  I might change my mind.  I am not going to write down the source of what is supposed to go here.  What I just want to do here is take the message and the email address and send it.  I must know if there is a way to make a byte[] and write a String to it.  If I know this I would be able to send the message with Datagram.*/
     }catch(IOException e){
     e.printStackTrace();
    }I chose to use Datagram for my method to send the email. I thought about Tcp. I might change my mind. I am not going to write down the source of what is supposed to go here. What I just want to do here is take the message and the email address and send it. I must know if there is a way to make a byte[] and write a String to it. If I know this I would be able to send the message with Datagram. But even if I do get the datagram to work I wonder if the program will work.
Thanks,
George

Never mind the previous post before this one that said about:
::So all I need to do is to use it in my public void run() method?
I will figure it out with the api after I download the seperate javamail package and the JAF. I was looking through the api for Java 2 Platform, Standard Edition (J2SE). Thanks for telling me about the javax.mail api. If you didnt tell me i'd keep looking through the wrong api and not being aware that I have to download a seperate package.
George

Similar Messages

  • How to put a String into a byte array

    How can i put a String into a byte array byte[]. So that i can send it to the serial port for output to an LCD display. Cheers David

    javadocs for String
    getBytes
    public byte[] getBytes()
    Encodes this String into a sequence of bytes using the platform's default charset, storing the result into a new byte array.
    Returns:
    The resultant byte arraySince:
    JDK1.1

  • How to put SSML string into a seperate file

    string Ssml =
    @"<speak version='1.0' " +
    "xmlns='http://www.w3.org/2001/10/synthesis' xml:lang='en-US'>" +
    "Hello <prosody contour='(0%,+80Hz) (10%,+80%) (40%,+80Hz)'>World</prosody> " +
    "<break time='500ms' />" +
    "Goodbye <prosody rate='slow' contour='(0%,+20Hz) (10%,+30%) (40%,+10Hz)'>World</prosody>" +
    "</speak>";
    how to reference it in c# if is in different file, i can do it in xaml but the syntax for  "<" is  different.
    the above code is just inside  c#. a simple string literal assigned to string variable, is there any other way to do this.
    I'm trying to learn speech synthesis for windows runtime but the is little to nothing documentation on the web. I alreaady tried that mva course. 

    Put it in a text file and load it up into a string.
    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.
    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined
    objects and unknown namespaces.

  • Putting a string into a stream

    I'm trying to tokenize a string from within the program, but it seems like all input streams read from files. what should i do?

    use StringTokenizer

  • Image sending through a datagram packet

    Hi All
    I am new at java programming.
    I am trying to develop a multicast chat program. I am looking for java code to send an image through datagram socket. as I am using UDP protocol for the multicasting.
    It will be very very appritiable if some one could help me to find the exact code.
    thank you.

    The whole concept of chatting over multicast may be flawed. Think about this: People may receive chat messages out of order, or even miss some of the messages. Do you think it's okay for some of the things people type to not be readable by others?
    Generally, a chat program should work on a client-server basis. You have one computer acting as the "chat room", and everyone else connect to that computer as chatters via TCP. The "chat room" maintains which messages were sent, as well as their order, and broadcasts the log to all connected chatters. Pretty much like it's done with IRC.
    That way, all the chatters see the same messages, and also see them in the same order, so they are all seeing the same conversation. It's rather vital for them to have a common reference point, so they don't get confused about what each other is talking about.

  • Process variable string into filename at Save service

    Hello,
    Does anyone know how to put a string into the Pathname Pattern (Template) property of a Save service (FileUtilsService - Write Document) ?
    What I'm trying to do is strip the /'s out of a date string and put that date into a filename. For example, 042208_Greg.pdf
    Instead I get d:\WMS\C0419\04\22\08\_Greg.pdf
    I want: d:\WMS\C0419\042208_Greg.pdf
    I have a Set Value service putting a form submit date (MM/DD/YY format) into a process variable called @stringDate. I am stripping /'s out of the date and setting @stringDate like so: /process_data/@stringDate <--- concat(substring(/process_data/xfaform/object/data/xdp/datasets/data/C0419/Approvers/Init iator/Date,1,2),substring(/process_data/xfaform/object/data/xdp/datasets/data/C0419/Approv ers/Initiator/Date,4,5),substring(/process_data/xfaform/object/data/xdp/datasets/data/C041 9/Approvers/Initiator/Date,7,8))
    At the Save file service, I am using @stringDate in my Pathname Pattern (Template) to create the filename: d:\WMS\C0419\{/process_data/@stringDate}_{$/process_data/xfaform/object/data/xdp/datasets /data/C0419/Approvers/Initiator/CompletedBy/Name$}.pdf
    Thanks,
    Greg
    Needham, MA

    Hi Greg
    You've done a great job getting this done with xpath.
    It looks to me like you've done everything right - what's not working - are you getting an exception, or is the file being saved with the wrong name?
    There is a nice little DateFormatter component here, that might make things a little easier/flexible.
    http://avoka.dnsalias.com/confluence/display/Public/Formatter+DSC
    Howard

  • How to read an inputStream in UTF-8 into a byte array.

    Hi, Java version is 1.4.2. If inputStream.read() is used to read the bytes into a byte array, is it guarenteed that UTF-8 chars are correctly transferred into byte array? Or should we use InputStreamReader? An example would be a great help.
    Thanks in advance.

    I would like to send a byte array read from InputStream to another app where they are converted to UTF-8. In brief
    -Read input stream which comes in UTF-8 into a byte array
    -Send byte array to another app which will convert it into UTF-8 characters

  • String[] cant put a string in it

    I got a problem i dont know how to put a string in the array
    i thought i chould write
    String[] lol;
    lol[0] = "Hello";
    thats only an example but it dosent work. so tell me how to put a string into a string array.

    I got a problem i dont know how to put a string in
    the array
    i thought i chould write
    String[] lol;
    lol[0] = "Hello";
    thats only an example but it dosent work. so tell me
    how to put a string into a string array.In general it will help if you give more detail than "doesn't work".
    Here it's easy to see. lol has not been initialized. You need lol = <something>;Usually <something> wil be new String[<some number>]but it could be a reference to an array you created elsewhere.

  • How to put file from a legacy system to SAP through FTP

    Hi
    I want to put one file which will be comming from legacy system to a folder of application server of the SAP system through xi.The protocol i want to use is FTP.
    But im not sure about the configuration to be done for putting the file directly to SAP app server.
    Anybody having idea what configuration i need to do in the SAP side to put the file into the app server directly through FTP.
    Thanks
    Debraj

    Hi Debraj,
    Try if these links help you solve your problem:
    http://help.sap.com/saphelp_bw31/helpdata/en/4e/2ba038b81e897ce10000009b38f8cf/content.htm
    http://www.sapfans.com/sapfans/saptips.htm#prog
    http://help.sap.com/saphelp_nw04/helpdata/en/a4/db833d4c47ea4ea1a9b7af3c535ff2/content.htm
    Cheers,
    Chandra

  • How can I put a stl::vector string into the DB and then get it out?

    Hello,
    As the title, here's a test case with problems,but anyway you can still run it. ( VC6/XP-32/BDB 4.7 )
    I know this may be wrong,and I'd like to know how can I do this.
    Can someone help me please? I would appreciate it very much.
    ************ Copy,Compile and Run ***************
    #include <iostream>
    #include <vector>
    #include "db_cxx.h"
    int main()
         std::string dbName("database.db");
         u_int32_t db_flags=DB_CREATE;
         Db* db=NULL;
         // Prepare key(int)/data(vector<string>) pair.
         int int_key=2;
         std::vector<std::string> rec_data;
         rec_data.push_back("apple");
         rec_data.push_back("Bob");
         rec_data.push_back("Me");
         // Prepare Dbt for receiving.
         std::vector<std::string> rec_readData;
         Dbt readData;
         readData.set_data(&rec_readData);
         readData.set_ulen(sizeof(rec_readData));
         readData.set_flags(DB_DBT_USERMEM);
         try
              // Open database.
              db = new Db(NULL,0);
              db->open(NULL,dbName.c_str(),NULL,DB_BTREE,db_flags,0);
              // Put
              int ret;
              if(ret=db->put(NULL,new Dbt(&int_key,sizeof(int_key)),new Dbt(&rec_data,sizeof(rec_data)),DB_NOOVERWRITE)==0)
                   std::cout<<"put successful!"<<std::endl;
              else { db->err(ret,"Db->put"); }
              // Get
              if(ret=db->get(NULL,new Dbt(&int_key,sizeof(int_key)),&readData,0)==0)
                   std::cout<<"get successful!"<<std::endl;
              else { db->err(ret,"Db->get"); }
         catch(DbException &e)
              std::cerr<<"Error: ";
              std::cerr<<e.what()<<std::endl;
         // Close the database
         try
              if(db!=NULL)
                   db->close(0);
         catch(DbException &e)
              std::cerr<<"Error closing database: ";
              std::cerr<<e.what()<<std::endl;
         // Display the results.
         // Index out of bounds. <-----
         std::cout << rec_readData[0].c_str();
         std::cout << rec_readData[1].c_str();
         std::cout << rec_readData[2].c_str();
         system("pause");
         // Press any key to go wrong. :(
         return 0;
    Regards,
    legendsino

    You need to convert the std::vector<std::string> into a sequence of bytes. For example, if all strings are shorter than 256 characters, you could create a fresh output string, iterator through the vector, and for each element, append the string length to the output string, followed by the string contents.
    Note that ordering in the database will be different from lexicographic order, and you have to keep that in mind when performing range queries.

  • How to put a String(date) into Date (java.util.date)??

    hi there
    I got a GUI here and I need to read some JMaskedTextFields from it. I put them all into Strings. Now I need to pass them to the search-function, but one of the search arguments is not string. Its Date. I tried to initialize Date with Date(String s) but he doesnt take it. Now Im asking how can I do this the easiest way?
    The String has only digits and a . betwenn them, like this: 12.02.1978 and I want to pass this into the Date.
    thx for helping :-)

    thx
    Now I got it so far, it looks like this:
    String datumVon = suchen_kriterien_datVon_JMaTextFeld.getText();
    String datumBis = suchen_kriterien_datBis_JMaTextFeld.getText();
    SimpleDateFormat formatter = new SimpleDateFormat ("dd.MM.yyyy");
    ParsePosition pos = new ParsePosition(0);
    Date datVon = formatter.parse(datumVon, pos);
    Date datBis = formatter.parse(datumBis, pos);
    System.out.println(datVon);
    System.out.println(datBis);
    The Problem is that he only makes the first print when both dates are given. If I only give him the first, so he prints the first. If I give him only the scond, so he prints the second. But when I give him both, he only prints the first!!! why?

  • I put an email into draft.When I opened it and tried to send the screen froze.

    I put an email into draft and when I reopened the draft and tried to send it,the screen froze

    Try a reset. Hold the Sleep and Home button down for about 10 seconds until you see the Apple logo. Ignore the red slider.

  • I want to convert a String into an array of bytes

    I am working with telnet programming with java, where I want to convert login name and password of an online user in 'String' format to 'Bytes', plz help me. Which Input or Output Stream I can use

    Assuming you've got the username / password into a String object, you can convert it to a byte[] array using this method.
    String.getBytes();
    Look at the String API
    http://java.sun.com/j2se/1.3/docs/api/java/lang/String.html
    Hope that helps.

  • Converting a byte array or hex string  into DES key

    i required to covert a hex represented of DES key into key object for cryptography operation to performed ...
    can you help me to find out how to convert a hex representaion of key int DES key object

    hi friend,
    I think the key size is more than the required size. For DES algorithm, the key size is 64 bit long.But the code u have given has more than 64 bit, because of which this exception has been raised.
    Reduce the key value to 64bit and try. If it doesnt work,try the code given below .I think it might be helpful for u
    import javax.crypto.*;
    import javax.crypto.spec.*;
    public class Cryption
         public byte[] encrypt(byte[] keyData,byte[] clearMessage)
              try
                   SecretKeySpec sks = new SecretKeySpec(keyData,"DES");
                   Cipher c = Cipher.getInstance ("DES");
                   c.init(Cipher.ENCRYPT_MODE,sks);
                   byte[] encryptedMessage = c.doFinal(clearMessage);
                   return encryptedMessage;
              catch(Exception e)
                   e.printStackTrace();
              return null;
         public byte[] decrypt(byte[] keyData,byte[] cipherMessage)
              try
                   SecretKeySpec sks = new SecretKeySpec(keyData,"DES");
                   Cipher c = Cipher.getInstance ("DES");
                   c.init(Cipher.DECRYPT_MODE,sks);
                   byte[] decryptedMessage = c.doFinal(cipherMessage);
                   return decryptedMessage;
              catch(Exception e)
                   e.printStackTrace();
              return null;
         public static void main(String[] args)
              String keyString = "ABCDEF12";
              byte keyValue[] = keyString.getBytes();
              Cryption encryption = new Cryption();
              String Message = "Hello Welcome to world of Cryptography";
              System.out.println("Key Value (represented in HEX form): "+keyString);
              System.out.println("Key Value (represented in byte array form): "+keyValue);
              System.out.println("Original Message : "+Message);
              byte[] encryptedMessage = encryption.encrypt(keyValue,Message.getBytes());
              System.out.println("Encrypted Message : "+new String(encryptedMessage));
              Cryption decryption = new Cryption();
              byte[] decryptedMessage = decryption.decrypt(keyValue,encryptedMessage);
              System.out.println("Decrypted Message : "+new String(decryptedMessage));
    output :
    Key Value (represented in HEX form): ABCDEF12
    Key Value (represented in byte array form): [B@43c749
    Original Message : Hello Welcome to world of Cryptography
    Encrypted Message : "O3�?�M�,����������,�]�3�����R�?>C$
    Decrypted Message : Hello Welcome to world of Cryptography
    whenever u use any algorithm, first findout the key size or range that algorithm supports. It is very important
    regards,
    Deepa Raghuraman

  • Put strings into a Vector

    Does anyone know how to put strings into a vector here is my code to put some names of files into one.
    Vector machines = new Vector();
    String dir = "F:\\APPS\\SPCII\\DATA\\";
    File directory = new File(dir);
    machines.addElement (directory.list());
    But when I print the vector, it only prints the address.
    Thanks

    list() returns a String[] array. if you store it in an array, say
    String[] dirlist=directory.list(); you can use dirlist.length and a for loop to enter the elements of the array one by one into the vector

Maybe you are looking for