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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:38:33+00:00 2026-05-17T21:38:33+00:00

I have a basic client server in erlang which uses tcp. How does one

  • 0

I have a basic client server in erlang which uses tcp.

How does one send the actual binary data from a file to the client who requested it?

How is the file sent in pieces?

I have this code

{ok, Socket} =
gen_tcp:connect({Ip}, 2345,
[binary, {packet, 4}]),

Does this {packet, 4} handle the data size that is send both ways?

Also, how does the client receive data and then do something with it? Like save it to a file?

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-05-17T21:38:33+00:00Added an answer on May 17, 2026 at 9:38 pm

    Yes – {packet, 4} will cause erlang to require a packet frame of a 4 byte unsigned big endian integer length value on receive, and will emit one before each packet of data sent.

    You can send data on the socket by calling gen_tcp:send(Socket, Data). This will do something like:

    RawData = iolist_to_binary(Data),
    Length = byte_size(RawData),
    Packet = <<Length:32/big-unsigned-integer, RawData/binary>>,
    send(Socket, Packet).
    

    So provided your file is less than 4Gb, you could send it by doing

    {ok, File} = file:read_file(FileName),
    gen_tcp:send(Socket, File).
    

    On the receiving end:

    File = gen_tcp:recv(Socket, 0).
    

    You’ll get the complete file because of the {packet, 4} framing.

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

Sidebar

Related Questions

I have setup a basic WCF client/server which are communicating via Named pipes. It
I have created a basic Client Server that will send image files in a
hello i have a basic client-server system running using java sockets. my problem is,
I'm currently in the process of performance profiling. We have a basic client/server application.
i want to develop a pretty basic client-server program. one software reads xml (or
I have build a basic .NET server-client infrastructure using TcpListener and SocketClient. It is
I have created a pretty basic Flash website for a client and am having
I have a basic CRUD form that uses PageMethods to update the user details,
I have a basic model in which i have specified some of the fields
I have a basic ActiveRecord model in which i have two fields that i

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.