Help: send unicode text using sockets

Hi,
I am trying to send unicode text to a native app using sockets. My test code looks like this
Socket socket = new Socket(m_serverHost, m_hostPort);
OutputStreamWriter out = new OutputStreamWriter(socket.getOutputStream(), "UTF-8");
InputStreamReader reader = new InputStreamReader(socket.getInputStream(), "UTF-8");
BufferedReader in = new BufferedReader(reader);
// receive response to connect
byte[] rc = new byte[4];
int i = 0;
while (i < 4)
rc[i++] = (byte) in.read();
String text = new String("Hello");
out.write(text);
// receive response to "hello"
i = 0;
while (i < 4)
rc[i++] = (byte) in.read();
My test program is connecting to the server socket but the server does not seem to understand the text that I send.
Please comment if I am doing anything wrong or advice if you have any different ideas.
Thanks,
nallamos

Try using the following output and input streams.
out = new DataOutputStream(
new BufferedOutputStream(
s.getOutputStream()));
in = new DataInputStream(
new BufferedInputStream(
s.getInputStream()));
When you send the data send it using
out.WriteBytes(message)

Similar Messages

  • When I send a text using siri the recipient shows that the text came from my email. How do I fix that so it show that the text came from my phone number and not my email address?

    When I send a text using siri the recipient shows that the text came from my email. How do I fix that so it show that the text came from my phone number and not my email address?

    Settings > Messages > Send & Receive > Start new conversations from:
    Only your phone number is selected.

  • HT4993 How do you turn the weird sound off when sending a text using the iPhone 4S

    How do you turn the weird sound off when sending a text using the iPhone 4S?

    Go to Settings-Sounds-Text Tone and change to None.  You're referring to the sound when posting a message to someone else, correct?  The only issue is if you set to none, you will not hear the incoming either.

  • Sending an image using sockets

    can anybody give an idea about how to send an image using sockets.....
    what i want to do is a client that connects to a server this server has the images...so the client request any image that the server has and display it int the client's frame

    Very good point! The problem ( I told you it was untested!) with the above is that the Image class isn't actually serialisable.
    The solution depends on how you're storing your images and how you're managing them within your server. It also depends on your proposed client. For example, if your client was a browser and your images files on a disk, then you might use:
                        Socket s;
                        // Write out header
                        PrintWriter pw = new PrintWriter(s.getOutputStream());
                        pw.println("Content-Type: image/gif");
                        // And send out data.
                        byte[] buffer = new byte[2048];
                        int count;
                        while((count = fis.read(buffer))>0) {
                             s.getOutputStream().write(buffer, 0, count);
                        s.getOutputStream().close();
                   }although you'd probably be better off using a proper webserver. If you're using a proprietry client, then you can either use Swing's JEditorPane to act like browser and display the image as the server above presents it.
    Otherwise, your client could use the incoming byte stream to create a BufferedImage instance.
    How are you storing your images and how are you presenting them?

  • How do I send a text using messages from my macbook to an iPhone phone?

    How do I send a text using messages from my macbook to an iPhone ?

    I tried to send it to their phone number, but it said they were offline.  And they downloaded iMessage for the iPhone but it still wasn't sending from my computer.  Is there some kind of trick?

  • Urgent - Sending Secret Text from Socket

    First of all, this is my finishing project. My project has a client and server parts. Server sends the DES key and client initializes it . It is working fine when I check. But the problem is I'm sending encrypted text to the server. And it is stored in SQL DB. then I retrieve the text and decrypt it. And here the problem starts . It throws some exceptions. They are
    DES Bad Padding Exception2 !
       DES Illegal Block Size2 !I looked the text that is stored in db. The encrypted text is sent to Server and DB is in server's computer. The encrypted text and the text in DB are same.
    Then I again get the encrypted text from the server and I compare the texts all are the same. Wht is my problem? Is it because of the sending error of sockets (I use TCP Socket) . And when I don't use encryption the data are sent very perfectly.
    Please Help. I cannot find my problem. And if there are someone doing similar projects please contact me.. msn: [email protected]

    I bet you are converting the encrypted bytes to a String using
    String toStoreInDB = new String(encryptedBytes);
    Your encrypted bytes will look very random and using your default encoding system will probably not convert properly using this approach. Centainly the transform bytes -> String -> bytes will probably not get back your original bytes.
    You have two possible approaches.
    1) Define your DB column to hold bytes (not CHAR or VARCHAR).
    2) Encode the encrypted bytes. I would use Base64 encoding but HEX and many other encoding systems are just as good.

  • Has anyone else had the problem where Siri on iOS 6 locks the phone after sending a text using a Bluetooth headset.   I have the auto lock turned off but I have had it happen many times.

    Siri is locking  my iPhone 5 running ios6 after sending a text message using my Jawbone icon HD Bluetooth earpiece.  Sometimes it will lock before the text is even sent. I have the auto lock turned off.

    I have this problem too. Auto lock is off and Siri can be used from the lock screen but this defeats the purpose of hands free usage for example when you are on a bicycle and can't use the phone normally. After sending a message or a reply to one Siri locks the phone and you cannot hear new messages until you unlock the phone which can be potentially dangerous!
    I'd love to see if there is a solution as I can't see any option in settings (either Siri settings or pass lock settings) to fix this.

  • I can't send a text using imessage from my iphone to an ipad

    I can't send or receive a text using imessage from my iphone to an ipad

    The Ipdas are using IOS 6 and can text to other iphones by phone number or apple id. I have tried hard resets and did a full restore and still no success. I am using IOS 6.0.1 and have had the phone checked at our local Apple dealer and I took it to the local ATT store to be sure my phone plan was not an issue.

  • Transfer Style Text Using Socket

    Anyone have any idea how to get a style text from JTextPane to be send through Socket connection.
    Anyone? Please Help. Thank You.

    Here's a small example for StyledDocument -> html:import javax.swing.text.html.*;
    import javax.swing.text.*;
    import java.io.*;
    public class Styled2Html {
        public static void main(String[] args) {
         try {
         // create an empty doc
         StyledDocument sd = new DefaultStyledDocument();
         // this would dump the doc to a file:
         // FileWriter fw = new FileWriter("sample.html");
         // Need I say that System.out can be replaced with socket.getOutputStream()?
         // You could use also a BufferedWriter to increase performance.
         OutputStreamWriter fw = new OutputStreamWriter(System.out);
         MinimalHTMLWriter out = new MinimalHTMLWriter(fw, sd);
         // Write it out...
         out.write();
         // ... and close the stream. You have now outputted valid 3.2 HTML
         // code to a stream with only 4 lines!
         fw.close();
         } catch (Exception e) {
         e.printStackTrace();
    }

  • Sending a text using the Spanish Keyboard

    When I send a message to some one in Spanish using the Spanish keyboard, they cannot read it because it shows as a bunch of squares and symbols. They are using an Envy touch to see my messages. Can some one help me? Is anyone having the same problem? Thank you!

    Jeperez wrote:
    When I send a message to some one in Spanish using the Spanish keyboard, they cannot read it because it shows as a bunch of squares and symbols. They are using an Envy touch to see my messages. Can some one help me? Is anyone having the same problem? Thank you!
    There have been several threads here about this, see, for example:
    http://community.vzw.com/t5/iPhone-4/iPhone-no-foreign-characters-in-SMS/m-p/440504#M20544
    Known issue, no fix yet.

  • When I send a text using iMessage from my mini iPad, it selects a photo that I deleted from my MacBookPro (in Users

    When sending iMessages using iPad mini an old photo that I've deleted from my MacBookPro in 'System Preferences/User&Groups' pops up with each iMessage I send. Genius Bar said iMessage was pulling this from iCloud and they recommended I change the photo inmy iCloud account, which I did. This did not help. Where could iMessage be gathering an old photo that's been deleted? Has anyone experienced this? and if so, is there a solution/fix?

    I don't follow where this picture is appearing.  You have to go to some trouble to add a picture to an iMessage.  Might it be popping up from a contact name you are using that happens to have a picture associated with it in your contacts list?

  • Send String failed using socket

    Hi all,
    I have just finished a program which send a string client to the host server using simple socket. The program is developed using JBuilder9 and run well in winxp pro. When the same program run in linux (red hat), the host server can only see the connection and close. The string never receive in the server side. The problem is worked out like the following
    -create socket
    -create output stream using "PrintWriter"
    -send string
    -close socket
    Pls. comment on what I should do to debug this problem.
    Thanks,
    Peter

    Hi all,
    Thanks for your assistance. I have log down the following from linux using "tcpdump"
    13:16:48.218624 128.128.2.161.33083 > pmon-srv0.999: P 1:42(41) ack 1 win 5840 <nop,nop,timestamp 158365 0> (DF)
    13:16:48.219105 128.128.2.161.33083 > pmon-srv0.999: F 42:42(0) ack 1 win 5840 <nop,nop,timestamp 158365 0> (DF)
    13:16:48.219742 pmon-srv0.999 > 128.128.2.161.33083: . ack 43 win 64199 <nop,nop,timestamp 2471694 158365> (DF)
    13:16:48.219876 pmon-srv0.999 > 128.128.2.161.33083: F 1:1(0) ack 43 win 64199 <nop,nop,timestamp 2471694 158365> (DF)
    13:16:48.219894 128.128.2.161.33083 > pmon-srv0.999: . ack 2 win 5840 <nop,nop,timestamp 158365 2471694> (DF)
    13:17:59.746088 128.128.2.211.1633 > pmon-srv0.999: P 1:43(42) ack 1 win 17520 (DF)
    13:17:59.756047 128.128.2.211.1633 > pmon-srv0.999: F 43:43(0) ack 1 win 17520 (DF)
    13:17:59.756493 pmon-srv0.999 > 128.128.2.211.1633: . ack 44 win 64198 (DF)
    13:17:59.756989 pmon-srv0.999 > 128.128.2.211.1633: F 1:1(0) ack 44 win 64198 (DF)
    13:17:59.757103 128.128.2.211.1633 > pmon-srv0.999: . ack 2 win 17520 (DF)
    128.128.2.211 is the client in winxp pro
    128.128.2.161 is the client in linux
    pmon-srv is the server
    In the first line of each section, it shows that number of bytes have push to the server. I don't know what should I do next to solve the problem.
    Here is the source code
    public class pconnect {
    String ip_addr;
    String fromServer, toServer;
    int i,port;
    Socket pmSocket;
    BufferedReader pm_in;
    PrintWriter pm_out;
    public pconnect(String ip, int portno) {
    ip_addr=ip;
    port=portno;
    try {
    pmSocket = new Socket(ip_addr, port);
    pm_out = new PrintWriter( pmSocket.getOutputStream(), true );
    pm_in = new BufferedReader( new InputStreamReader( pmSocket.getInputStream() ) );
    } catch (Exception err) {
    System.err.println(err);
    System.exit(0);
    public void sendMsg(String msg) {
    try {
    Thread.sleep(5000);
    } catch (InterruptedException e){}
    if (pmSocket.isConnected()) {
    try {
    System.out.println("Stream Status: " + pmSocket.isOutputShutdown());
    System.out.println("Bound Status: " + pmSocket.isBound());
    pm_out.println(msg);
    if (pm_out.checkError()) {
    System.out.println("Socket error");
    }catch (Exception e){System.out.println("Exception: " + e);}
    try {
    pmSocket.close();
    } catch (Exception err) {
    System.err.println("Closed Error: "+err);
    public static void main(String[] args) {
    System.out.println(args.length);
    System.out.println(args[0]);
    pconnect pconnect1 = new pconnect(args[0],Integer.parseInt(args[1]));
    pconnect1.sendMsg("SET00000000N|ALARM:MBX TEST|c29K1920755D");
    Thanks,
    Peter

  • Help with Oracle text using CTX_DOC.SNIPPET

    I used to find the code as follows:
         SELECT ROWIDS,ID,NGAYTAO,NGAYXUATBAN,CHUYENMUC,FULLPATH,NGONNGU,NOIDUNG,TIEUDE
                                       ,(SELECT CTX_DOC.SNIPPET('SEARCH_DNICT_MOTA_IDX',ROWIDS,:tukhoa) FROM DUAL) || '..' ||
                                        (SELECT CTX_DOC.SNIPPET('SEARCH_DNICT_NOIDUNG_IDX',ROWIDS,:tukhoa) FROM DUAL) || '..' ||
                                        (SELECT CTX_DOC.SNIPPET('SEARCH_DNICT_TTHC1_IDX',ROWIDS,:tukhoa) FROM DUAL) || '..' ||
                                        (SELECT CTX_DOC.SNIPPET('SEARCH_DNICT_TTHC2_IDX',ROWIDS,:tukhoa) FROM DUAL) || '..' ||
                                        (SELECT CTX_DOC.SNIPPET('SEARCH_DNICT_TTHC3_IDX',ROWIDS,:tukhoa) FROM DUAL) || '..' ||
                                        (SELECT CTX_DOC.SNIPPET('SEARCH_DNICT_TTHC4_IDX',ROWIDS,:tukhoa) FROM DUAL) || '..' MOTA
                                        FROM SEARCH_DNICT
                                        WHERE (CONTAINS(SEARCH_DNICT.TIEUDE,:tukhoa,1)>0
                                        OR CONTAINS(SEARCH_DNICT.MOTA,:tukhoa,2)>0
                                        OR CONTAINS(SEARCH_DNICT.NOIDUNG,:tukhoa,3)>0
                                        OR CONTAINS(SEARCH_DNICT.TTHC1,:tukhoa,4)>0
                                        OR CONTAINS(SEARCH_DNICT.TTHC2,:tukhoa,5)>0
                                        OR CONTAINS(SEARCH_DNICT.TTHC3,:tukhoa,6)>0
                                        OR CONTAINS(SEARCH_DNICT.TTHC4,:tukhoa,7)>0)- when I following query return 50 documents it takes 10.969 seconds load just for one use. Now my database is not only very little data
    - I find if such search is too slow, I have studied but have not found a way to accelerate your returns faster results like?
    - I want to improve performance query is how?
    - I hope people will help me solve
    Thanks every body!

    Hi,
    what is the plan for this query? I think it is maybe a full scan on the table and it uses not even the indexes. Is it possible to rewrite the query to use union?
    SELECT ROWIDS,ID,NGAYTAO,NGAYXUATBAN,CHUYENMUC,FULLPATH,NGONNGU,NOIDUNG,TIEUDE ,
    (SELECT CTX_DOC.SNIPPET('SEARCH_DNICT_MOTA_IDX',ROWIDS,:tukhoa) FROM DUAL) || '..' ||
    (SELECT CTX_DOC.SNIPPET('SEARCH_DNICT_NOIDUNG_IDX',ROWIDS,:tukhoa) FROM DUAL) || '..' ||
    (SELECT CTX_DOC.SNIPPET('SEARCH_DNICT_TTHC1_IDX',ROWIDS,:tukhoa) FROM DUAL) || '..' ||
    (SELECT CTX_DOC.SNIPPET('SEARCH_DNICT_TTHC2_IDX',ROWIDS,:tukhoa) FROM DUAL) || '..' ||
    (SELECT CTX_DOC.SNIPPET('SEARCH_DNICT_TTHC3_IDX',ROWIDS,:tukhoa) FROM DUAL) || '..' ||
    (SELECT CTX_DOC.SNIPPET('SEARCH_DNICT_TTHC4_IDX',ROWIDS,:tukhoa) FROM DUAL) || '..' MOTA
    FROM
      SELECT ROWIDS,ID,NGAYTAO,NGAYXUATBAN,CHUYENMUC,FULLPATH,NGONNGU,NOIDUNG,TIEUDE
      FROM SEARCH_DNICT
      WHERE CONTAINS(SEARCH_DNICT.TIEUDE,:tukhoa,1)>0
      UNION
      SELECT ROWIDS,ID,NGAYTAO,NGAYXUATBAN,CHUYENMUC,FULLPATH,NGONNGU,NOIDUNG,TIEUDE
      FROM SEARCH_DNICT
      WHERE CONTAINS(SEARCH_DNICT.MOTA,:tukhoa,2)>0
      UNION
      SELECT ROWIDS,ID,NGAYTAO,NGAYXUATBAN,CHUYENMUC,FULLPATH,NGONNGU,NOIDUNG,TIEUDE
      FROM SEARCH_DNICT
      WHERE CONTAINS(SEARCH_DNICT.NOIDUNG,:tukhoa,3)>0
      UNION
      SELECT ROWIDS,ID,NGAYTAO,NGAYXUATBAN,CHUYENMUC,FULLPATH,NGONNGU,NOIDUNG,TIEUDE
      FROM SEARCH_DNICT
      WHERE CONTAINS(SEARCH_DNICT.TTHC1,:tukhoa,4)>0
      UNION
      SELECT ROWIDS,ID,NGAYTAO,NGAYXUATBAN,CHUYENMUC,FULLPATH,NGONNGU,NOIDUNG,TIEUDE
      FROM SEARCH_DNICT
      WHERE CONTAINS(SEARCH_DNICT.TTHC2,:tukhoa,5)>0
      UNION
      SELECT ROWIDS,ID,NGAYTAO,NGAYXUATBAN,CHUYENMUC,FULLPATH,NGONNGU,NOIDUNG,TIEUDE
      FROM SEARCH_DNICT
      WHERE CONTAINS(SEARCH_DNICT.TTHC3,:tukhoa,6)>0
      UNION
      SELECT ROWIDS,ID,NGAYTAO,NGAYXUATBAN,CHUYENMUC,FULLPATH,NGONNGU,NOIDUNG,TIEUDE
      FROM SEARCH_DNICT
      WHERE CONTAINS(SEARCH_DNICT.TTHC4,:tukhoa,7)>0
    ) If above doesn't help, then maybe a combined index on the fields will help. Examples are given in this forum if you search for multi colum index.
    Herald ten Dam
    http://htendam.wordpress.com

  • Help: Sending HTTPService request using POST to a php script

    Hello all,
    I need help in learning the proper method of communicating to php scripts from flex 3. I am very new to flex 3, php and web development. Thanks!
    What I am trying to do is as follows:
    1. User drags and drops a few items in a list control
    2. user clicks a button to send these keywords to server php script
    3. server will form a query based on the words sent and retrieve records and send them back
    Here is what I have done so far:
    1. When I send a request to server without any parameters, I amable to receive the request and query the database and send results in xml format
    current issues I am facing:
    1. I am gathering the list of entries in list control as follows:
    <*** this function is callled when user decides to send request to server ***>private function startsearch():void {
       var i:int;
       var myAC:ArrayCollection = ArrayCollection(SelCtypes_id.dataProvider);
       var nct:XML = new XML("<contenttypes></contenttypes>");
       // add contenttype child now
       for (i = 0; i<myAC.length; i++) {
        nct.appendChild(XML(<contenttype>{myAC[i].toString()}</contenttype>));
       var params:Object = new Object();
       params.contenttypes = nct.toXMLString();
       getsearchresults.send(params);
    <*** my http service entry****>
      <mx:HTTPService id="getsearchresults"
       method="post"
      url="http://localhost/search_xml.php"
      result="handlesearchresultsXml(event)"
      contentType="application/xml" />
    This is what I see in flex debugger just when the request is sent out:
    -> just before gersearchresults.send(params) call:
    params.contenttypes = "<contenttypes>
      <contenttype>AVI</contenttype>
      <contenttype>SWF</contenttype>
    </contenttypes>"
    <*** within the HTTPrequest send function, I see th following in debugger ***>
    message.contentType="application/xml"
    message.body = paramsToSend shows "<contenttypes>&lt;contenttypes&gt;
    &lt;contenttype&gt;AVI&lt;/contenttype&gt;
    &lt;contenttype&gt;SWF&lt;/contenttype&gt;
    &lt;/contenttypes&gt;</contenttypes>"
    This looks like my XML object is again formatted by an out <contenttypes> tag and the string is converted to be HTML safe (i.e. &lt, &gt notation).
    It looks like I am not doing something right with my params formation to XML and HTTPservice is reformatting it to be some form of XML (I do not know XML well either :-)
    My questions:
    1. What am I doing wrong?
    2. If there is a good example where I can send multiple parameters from flex client to php server and get data back where the request parameters will beof the form...
    <query>
    <type1>
         <type1val>value1</type1val>
         <type1val>value2</type1val>
    </type1>
    <type2>
         <type2val>value3</type2val>
         <type2val>value4</type2val>
    </type2>
    </query>
    Thanks for your help!

    Hi, I'm having a problem with a similiar issue :/
    I'm getting the error #1010 (A term is undefined and has no properties):
    at flexGraph/httpResultHandlerUserInfo()
    at flexGraph/__userInfoXML_result()
    etc.
    I removed some parts of the code so it's easier to read, if you can help me. I'm trying to populate a datagrid with info from a database, according to the alias I choose in the ComboBox. I get the error when I pick an alias from the ComboBox.
    <mx:Script>
         <![CDATA[
         import mx.collections.ArrayCollection;
         import mx.rpc.events.FaultEvent;
         import mx.rpc.events.ResultEvent;
         import mx.events.DropdownEvent;
         [Bindable] private var usersInfo:ArrayCollection;
         private function httpResultHandlerUserInfo(event:ResultEvent):void{
              usersInfo = event.result.users.user;
         private function chooseUserCB(event:DropdownEvent):void{
              userInfoXML.send();
    ]]>
    <mx:HTTPService id="userInfoXML" url="http://www.mysecondplace.org/flex/userInfo.php"
    result="httpResultHandlerUserInfo(event)"
    useProxy="false" method="POST">
    <mx:request xmlns=""><alias>{usersAliasCB.selectedItem.alias}</alias></mx:request>
    </mx:HTTPService>
    <mx:ComboBox id="usersAliasCB"
    x="10" y="10"
    labelField="alias"
    close="chooseUserCB(event)"/>
    <mx:DataGrid id="testing"
    x="10" y="100"
    dataProvider="{usersInfo}"/>
    Here's an example from the PHP file:
    $query_user = "SELECT * FROM users WHERE alias='.$_POST["alias"].'";
    Help me please

  • Help : Sending Jar file using bluetooth.

    Hi
    I have done till below...
    Midlet will search available bluetooth device in range.
    I want to do below.
    1. Search available bluetooth device in range
    2. User will see list of devices.
    3. when user will select a device, i want to send the jar file itself ( i have stored jar file inside resources)
    4. on file sent to bluetooth devices, it should tell file sent successfully.
    More :
    I am confused with Bluetooth server and client terminology.
    Here my program is client or server ? Infact the whole pupose is we have made some Java program and we want to make it viral, easy for our users to send it to their friends via bluetooth
    Any pointers ?
    Raxit
    www.m4mum.com

    Hi,
    You might wanna look take a look in the JSR 82 Specifications. There is a method like agent.startInquiry(); that starts a search for nearby BT devices. All you have to do is place each found device in an array of type Vector.
    It would have been easier if your code or a snippet of it was available to see what the problem was.
    Rambo.
    PS: A client application application starts a connection on a server application. Where you put them is up to you.

Maybe you are looking for

  • Outlook 2010 Contact Card (View more options to interact with this person)

    When I double click on a contact, and hover over their email address to "View more ways to interact with this person" - the box shows nothing. This is consistent with all of my contacts, and this is happening to every user at our site - I think it mi

  • Error while calling the BPEL from java program

    Hello All, I am tring to call the Synchronous BPEL process from the following code: package callbpelfromjava; import com.oracle.bpel.client.Locator; import com.oracle.bpel.client.NormalizedMessage; import com.oracle.bpel.client.delivery.IDeliveryServ

  • How to compile and deploy an ejb into Sun ONE app.server 7.0

    I am new to Sun ONE application server. I Have .java files and deployment descriptor files with me. How should proceed. When i tried to use asant it is saying that build.xml not found. I copied build.xml from some other directory to the current direc

  • Java me for windows mobile 5.0

    I am trying to download java ME to my motorola Q but I don't know exactly how to do it and what links to pick. I want to ensure that I don't load the wrong one to my phone

  • FXO test in Remote Location.

    Hi... I have four routers in a remote location used as an FXO gatway, and its communicating with CM6.1 using MGCP. Is there a way to check whether the FXO line is connected, and that there is a dial tone available on this port or not? Thanks