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

  • SEARCH
  • Home
  • 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 6655393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:30:52+00:00 2026-05-26T01:30:52+00:00

I am trying to send a string through sockets but I just have some

  • 0

I am trying to send a string through sockets but I just have some problems. the string that I am trying to send is ; (ATTENTION : It is a string NOT XML )

<message>
<header>
<messageType>snmp</messageType>
<sendFrom>192.168.0.16</sendFrom>
<hostName>oghmasysMehmet</hostName>
<sendTo>192.168.0.12</sendTo>
<receiverName>Mehmet</receiverName>
<date>03/10/2011</date>
</header>
<body>
<snmpType>getbulk</snmpType>
<ip>127.0.0.1</ip>
<port>161</port>
<oids>
  <oid>1.3.6.1.2.1.1.3.0</oid>
</oids>
<community>community</community>
<nR>0</nR>
<mR>5</mR>
</body>
</message>

But when I look what I get from server it is just ;

<?xml version="1.0" encoding="UTF-8"?>

I dont know what is the problem:

I am using ,

socket = new Socket(localIP, Integer.parseInt(localPort));
out = new PrintWriter(socket.getOutputStream(), true);

to send the string from client and use,

in = new BufferedReader(new InputStreamReader(client.getInputStream()));
line = in.readLine();

to read the string on server.

Can you please help me how I can solve it ?

Thank you all

  • 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-26T01:30:53+00:00Added an answer on May 26, 2026 at 1:30 am

    Lucas has the answer, I believe. Personally, I don’t trust readLine() as in doing so is making the assumption that you are recv-ing valid String data on the socket…. which is a very poor assumption!

    Try reading into a byte buffer first, then try to make it into a string:

    byte[] buf = new byte[4096];
    
    int actualNumberOfBytesRead = socket.getInputStream().read(buf);
    
    String dataString = new String(buf, 0, actualNumberOfBytesRead);
    

    …Now, my example has a few issues to it, but the point (should) be made =D

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

Sidebar

Related Questions

I'm trying to implement basic communication through sockets, what I have now is: server
I'm going through my app, trying to clean up some code that sends e-mails.
I am trying to send an email (through gmail) using python script that someone
Hello all my friends, I am trying to send a long string through socket
I am trying to send some very large files (>200MB) through an Http output
im trying to send a file in android through sockets. i want to add
I'm using Linux and trying to send a long message through send(). The message
I'm trying to send a long string by WCF, around 64k chars long. When
Trying to send some email in my C# app. I am behind a proxy
im trying to send rest api Users.getLoggedInUser i have all the secret session and

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.