Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3485430
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:54:24+00:00 2026-05-18T10:54:24+00:00

I want to send a message to my computer from my phone using TCP..My

  • 0

I want to send a message to my computer from my phone using TCP..My computer is the server and my phone is the client. I am able to send a message from my phone to my computer but in the output, I get null characters ..

I paste my codes below;;

Client ::

public void startApp() {
try {
// establish a socket connection with remote server
streamConnection =
(StreamConnection) Connector.open(connectString);

  // create DataOuputStream on top of the socket connection
  outputStream = streamConnection.openOutputStream();
  dataOutputStream = new DataOutputStream(outputStream);

  // send the HTTP request
  dataOutputStream.writeChars("Hello");
  dataOutputStream.flush();

  // create DataInputStream on top of the socket connection
  inputStream = streamConnection.openInputStream();
  dataInputStream = new DataInputStream(inputStream);

  // retrieve the contents of the requested page from Web server
  String test="";
  int inputChar;
  System.out.println("Entering read...........");
  while ( (inputChar = dataInputStream.read()) != -1) {
     // test=test+((char)inputShar);
    results.append((char) inputChar);
  }
  System.out.println("Leaving read...........");
  // display the page contents on the phone screen
  //System.out.println(" Result are "+results.toString());
  System.out.println("   ");
  resultField = new StringItem(null, results.toString());
  System.out.println("Client says "+resultField);
  resultScreen.append(resultField);
  myDisplay.setCurrent(resultScreen);

} catch (IOException e) {
  System.err.println("Exception caught:" + e);
} finally {
  // free up I/O streams and close the socket connection
  try {
    if (dataInputStream != null)
      dataInputStream.close();
  } catch (Exception ignored) {}
  try {
    if (dataOutputStream != null)
      dataOutputStream.close();
  } catch (Exception ignored) {}
  try {
    if (outputStream != null)
      outputStream.close();
  } catch (Exception ignored) {}
  try {
    if (inputStream != null)
      inputStream.close();
  } catch (Exception ignored) {}
  try {
    if (streamConnection != null)
      streamConnection.close();
  } catch (Exception ignored) {}
}

}

My server :

public class Main {

/**
 * @param args the command line arguments
 */
public static void main(String[] args)  {
    // TODO code application logic here
  try{
      ServerSocket sck=new ServerSocket(880);
      Socket client=sck.accept();
      InputStream inp= client.getInputStream();
      int  i;
      OutputStream out=client.getOutputStream();
      out.write("Testing ".getBytes());
      System.out.println("Server has responded          ");
      String str="";
      while((i=inp.read())!=-1){

          str=str+((char) i);
           System.out.println("USer says "+ str);
      }

  }
  catch(Exception e){
      System.out.println("Error "+e);
  }

}

}

My output for the server ;;

Server has responded
USer says null H
User says null H null
User says null H null e
etc etc

I am not supposed to get this null character,why I am getting it??
Another thing, my server is writing to the stream but the client is not able to receive that,why is that?Do I need to use a separate thread for that?

Thanks in adv

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T10:54:25+00:00Added an answer on May 18, 2026 at 10:54 am

    I would guess that isn’t your real code, and that your real code initialized str to null.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I want to send a message from one client to another. How
I want to use my computer's IP address to send a message using socket
I want to send messages from a client computer to a consumer on a
Hi I want to send message from one application (which will be installed on
I want to send an SMS message from my facebook application so that the
I want to send messages to mobile phones using wamp server in php.I need
I want to be able to send files from an iPhone app to a
I want to send message/notification to friends with customized subject with a link in
I want to send a message whenever RabbitMQ creates or deletes a queue, exchange
How to trap signal on ruby running on windows? I want to send signal/message

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.