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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:48:04+00:00 2026-05-18T00:48:04+00:00

How Does a TCP client receive binary data it requests from a TCP server?

  • 0

How Does a TCP client receive binary data it requests from a TCP server?

If the server sends the requested data (some binary data at a certain position of file) how is this received and saved to a file.

  • 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-18T00:48:05+00:00Added an answer on May 18, 2026 at 12:48 am

    Here is an example of connecting to a remote server, receiving data, and writing it to a file:

    -module(recv).
    
    -export([example/1]).
    
    recv_data(IoDevice, Sock) ->
      case gen_tcp:recv(Sock, 0) of
        {ok, B} -> 
          ok = file:write(IoDevice, B),
          recv_data(IoDevice, Sock);
        {error, Reason} ->
          error_logger:info_msg("Done receiving data: ~p~n", [Reason]),
          file:close(IoDevice),
          gen_tcp:close(Sock)
      end.
    
    example(FileName) ->
      {ok, IoDevice} = file:open(FileName, [write, binary]),
      {ok, Sock} = gen_tcp:connect("www.google.com", 80, [binary, {packet, raw}, {active, false}]),
      ok = gen_tcp:send(Sock, "GET / HTTP/1.0\r\n\r\n"),
      recv_data(IoDevice, Sock).
    

    This will connect to google and write the response to a file:

    Erlang R14A (erts-5.8) [source] [smp:2:2] [rq:2] [async-threads:0] [hipe] [kernel-poll:false]
    
    Eshell V5.8  (abort with ^G)
    1> c(recv).
    {ok,recv}
    2> recv:example("/tmp/test.bin").
    
    =INFO REPORT==== 4-Nov-2010::08:52:59 ===
    Done receiving data: closed
    ok
    3> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The requirement of the TCP server: receive from each client and send result back
I have a TCP server that listens for an incoming client, then sends it
I am going to write a TCP server, the client sends me XML message,
I have a basic client server in erlang which uses tcp. How does one
Does TCP/IP prevent multiple copies of the same packet from reaching the destination? Or
I'm trying to write a TCP client that does the following things: 1. Establish
I am attempting to pull some information from my tnsnames file using regex. I
I have TCP client application and trying to connect with Server located at remote
How does TCP/IP report errors when packet delivery fails permanently? All Socket.write() APIs I've
Does Google force employees who have offers from Facebook to leave immediately?

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.