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 8898811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:42:25+00:00 2026-06-15T00:42:25+00:00

I am trying to retrieve the byte that transferred by the server that has

  • 0

I am trying to retrieve the byte that transferred by the server that has been programmed in c# as follow:

static void Main(String[] args){
    Socket sListen = new Socket(AddressFamily.InterNetwork, SocketType.Stream,     ProtocolType.Tcp);
    IPAddress IP = IPAddress.Parse("10.0.0.92");
    IPEndPoint IPE = new IPEndPoint(IP, 4321);
    sListen.Bind(IPE);
    Console.WriteLine("Service is listening ...");
    sListen.Listen(2);
    while (true){
        Socket clientSocket;
        try{
            clientSocket = sListen.Accept();
        }
        catch{
            throw;
        }
        byte[] buffer = ReadImageFile("path to image");
        clientSocket.Send(buffer, buffer.Length, SocketFlags.None);
        Console.WriteLine("Send success!");
    }
}

private static byte[] ReadImageFile(String img){
    FileInfo fileinfo = new FileInfo(img);
    byte[] buf = new byte[fileinfo.Length];
    FileStream fs = new FileStream(img, FileMode.Open, FileAccess.Read);
    fs.Read(buf, 0, buf.Length);
    fs.Close();
    //fileInfo.Delete ();
    GC.ReRegisterForFinalize(fileinfo);
    GC.ReRegisterForFinalize(fs);
    return buf;
}

Above codes works fine when I write a client in the c# and run it in the pc. However I want to retrieve the bytes transferred by the server in the android device.

The android connected to the server successfully but it will not finish its job, basically it will not pass the ‘while loop in the bellow code’. I think there is something wrong with the byte length because it’s never get to ‘-1’.

Android java code (Client):

Socket socket = new Socket("ip", 4321);
InputStream is = socket.getInputStream();
byte[] buffer = new byte[1024];
int read = is.read(buffer);
while(read != -1){
    read = is.read(buffer);
}

is.close();
socket.close();

I do appreciate any help in advance,
Thanks,

  • 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-06-15T00:42:26+00:00Added an answer on June 15, 2026 at 12:42 am

    The client read() method will never return -1 until the server closes the connection. You’re not doing that so it never happens.

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

Sidebar

Related Questions

I am trying to retrieve RSS feed using php. The xml has many different
I am trying to retrieve a column from another related table, and display that
I'm trying to store a password in a file that I'd like to retrieve
I am trying to save a byte array (byte[]) in c# application settings that
I'm trying to create a route and then programatically retrieve the url of that
Im trying to retrieve a query as a byte array. Im stuck @ the
I have been trying to retrieve unicode user input in my Java application for
I am trying retrieve user name from the code through graph api, the below
I´m trying to retrieve the id of the object I've just introduced into the
Iam trying to retrieve data from mysql database into stylesheet.php but it is not

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.