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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T21:21:37+00:00 2026-06-18T21:21:37+00:00

So I have found here in stackoverflow One code for sending through sockets a

  • 0

So I have found here in stackoverflow One code for sending through sockets a binary file, an image.. So i used it for test to my Project

private void send_ss()
    {
        byte[] data = new byte[1024];
        int sent;
        IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 306);

        Socket server = new Socket(AddressFamily.InterNetwork,
                        SocketType.Stream, ProtocolType.Tcp);

        try
        {
            server.Connect(ipep);
        }
        catch (SocketException e)
        {
            //Console.WriteLine("Unable to connect to server.");
            //Console.WriteLine(e.ToString());
            //Console.ReadLine();
        }


        Bitmap bmp = new Bitmap("C:\\Windows\\Web\\Wallpaper\\Theme2\\img7.jpg");

        MemoryStream ms = new MemoryStream();
        // Save to memory using the Jpeg format
        bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);

        // read to end
        byte[] bmpBytes = ms.ToArray();
        bmp.Dispose();
        ms.Close();

        sent = SendVarData(server, bmpBytes);

        //Console.WriteLine("Disconnecting from server...");
        server.Shutdown(SocketShutdown.Both);
        server.Close();
    }
    private static int SendVarData(Socket s, byte[] data)
    {
        int total = 0;
        int size = data.Length;
        int dataleft = size;
        int sent;

        byte[] datasize = new byte[4];
        datasize = BitConverter.GetBytes(size);
        sent = s.Send(datasize);

        while (total < size)
        {
            sent = s.Send(data, total, dataleft, SocketFlags.None);
            total += sent;
            dataleft -= sent;
        }
        return total;
    }

so i tried to send this picture on one of my Listening Sockets in Port 306 (listened with m IRC)

on *:socklisten:ac_img:{
  var %p = $ticks $+ $time(hhnnss) $+ $ctime
  sockaccept ac_img_ $+ %p
  echo -s [] Image Connection Established On -> ac_img_ $+ %p
}
on *:sockread:ac_img_*:{
  sockread &picture 
  bwrite $qt($mIRCdir $+ $sockname $+ .jpg) -1 -1 &picture 
}

So i’m getting files like ac_img_2920385501147471360792067.jpg and so on. Same size with the original BUT the images just not appearing , so i opened Both files with word pad and they were a bit different… dunno why…ScreenShot

So any ideas why i’m facing this issue? i mean… I’m taking every single data from my socket and saving them to the file? Maybe a corrupt on file read through c#?

  • 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-18T21:21:38+00:00Added an answer on June 18, 2026 at 9:21 pm

    The image is different because you read it, parse it into a Bitmap and reencode it. The wordpad screenshot shows that both are JPEG’s but with different metadata (for example “adobe” missing”).

    Just use File.ReadAllBytes or other lossless methods to read the image.

    The sending code looks sound. Not sure why you’re looping. Sending never does partial IOs AFAIK on blocking sockets.

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

Sidebar

Related Questions

I have found some code on measuring execution time here http://www.dreamincode.net/forums/index.php?showtopic=24685 However, it does
I have made a image gallery with jQuery found here: http://sarfraznawaz2005.kodingen.com/demos/jquery/image_gallery/ I just wanted
I have been playing with image flood fill that I found here on Stack
i have the following LINQ code which i found in a question on stackoverflow,
I have tried the code examples that I found here on the stackoverfllow site,
I have found a Tutorial here on how to implement drag and drop in
I found here that to restore brightness on app exit you have to use
I have found several other questions here on S.O. (and the web in general)
I have a chart generated from Google Charts that can be found here: Chart
like in this post here by exemple I have found this blog but in

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.