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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:26:06+00:00 2026-05-26T22:26:06+00:00

I want my app to be able to talk to the pc client through

  • 0

I want my app to be able to talk to the pc client through sockets.
I already know how to do that for strings.

My question here, I want to be able to send audio files and pictures, how can I convert the iamge/audio file to a string/bit stream and send it?

Here’s my class for the socket:

public class SocketClient
{
    Socket socket = null;
    static ManualResetEvent clientDone = new ManualResetEvent(false);
    const int TIMEOUT_MILLISECONDS = 5000;
    const int MAX_BUFFER_SIZE = 2048;

    public SocketClient()
    {
        socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
    }

    public string Send(string serverName, int portNumber, string data)
    {
        string response = "Timeout";

        if (socket != null)
        {
            SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();
            socketEventArg.RemoteEndPoint = new DnsEndPoint(serverName, portNumber);

            socketEventArg.Completed += new EventHandler<SocketAsyncEventArgs>(delegate(object s, SocketAsyncEventArgs e)
            {
                response = e.SocketError.ToString();
                clientDone.Set();
            });

            byte[] payload = Encoding.UTF8.GetBytes(data);
            socketEventArg.SetBuffer(payload, 0, payload.Length);
            clientDone.Reset();
            socket.SendToAsync(socketEventArg);

            clientDone.WaitOne(TIMEOUT_MILLISECONDS);
        }
        else
        {
            response = "not initialized";
        }
        return response;
    }

    public string Recieve(int portNumber)
    {
        string response = "Timeout";

        if (socket != null)
        {
            SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();
            socketEventArg.SetBuffer(new Byte[MAX_BUFFER_SIZE], 0, MAX_BUFFER_SIZE);

            socketEventArg.Completed += new EventHandler<SocketAsyncEventArgs>(delegate(object s, SocketAsyncEventArgs e)
            {
                if (e.SocketError == SocketError.Success)
                {
                    response = Encoding.UTF8.GetString(e.Buffer, e.Offset, e.BytesTransferred);
                    response.Trim('\0');
                }
                else
                {
                    response = e.SocketError.ToString();
                }

                clientDone.Set();
            });

            socketEventArg.RemoteEndPoint = new IPEndPoint(IPAddress.Any, portNumber);

            clientDone.Reset();
            socket.ReceiveFromAsync(socketEventArg);
            clientDone.WaitOne(TIMEOUT_MILLISECONDS);
        }

        return response;
    }

    public void Close()
    {
        socket.Close();
    }
}

I want to modify it to be able to send pictures and audio files.

  • 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-26T22:26:06+00:00Added an answer on May 26, 2026 at 10:26 pm

    Your current Send method uses a string property for data. You could rebuild this using a byte array or stream containing the data.

    You can use this example to see how to get from an image to stream and back although this doesn’t use sockets but the local storage. The principle about how to do it stays the same:
    http://blogs.microsoft.co.il/blogs/tomershamam/archive/2010/10/12/saving-and-loading-captured-image-to-and-from-wp7-isolated-storage.aspx

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

Sidebar

Related Questions

In recent talk with client, we got an interesting question, if we are able
I want my server app to be able to send data to be processed
I want my app to be able to send an email with attachment to
I want that my app will be able to take images automatically from the
I want my android app to be able to share files through bluetooth, e-mail,
I want my app to be able to tell whether a call was missed,
I want my app (AIR app ported on iOS) to be able to show
I want to stop outgoing call and open the application. The app is able
In my app I want users to be able to associate a file(s) they
In my Rails app I want users to be able to input video links

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.