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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:02:47+00:00 2026-06-14T20:02:47+00:00

In a nutshell: I am trying to make a socket server to which clients

  • 0

In a nutshell:
I am trying to make a socket server to which clients connect and send/receive messages (based on the sockserv code in Learn you some erlang tutorial http://learnyousomeerlang.com/buckets-of-sockets)
Server side components:
supervisor – unique, started at the very beginning, spawns processes with gen_server behaviour
gen_server behaviour processes – each one deals with a connection.

Client side:
client which connects to the socket and sends a few bytes of data and then disconnects.

Code details
My code is pretty much the same as in the presented tutorial. The supervisor is identical. The gen_server component is simplified so that it has only one handle_info case which is supposed to catch everything and just print it.

Problem
The connection succeeds, but when the client sends data, the server behaves as though no data is received (I am expecting that handle_info is called when that happens).

handle_info does get called but only when the client disconnects and this event is reported with a message.

My attempts
I have played around with different clients written in Erlang or Java, I have tried setting the active/passive state of the socket. The author of the tutorial sets {active, once} after sending a message. I ended up just setting {active, true} after the AcceptSocket is created as such: (the gen_server proc is initialized with a state which contains the original ListenSocket created by the supervisor)

handle_cast(accept, S = #state{socket=ListenSocket}) ->

     {ok, AcceptSocket} = gen_tcp:accept(ListenSocket),
     io:format("accepted connection ~n", []),

      sockserv_sup:start_socket(), % a new acceptor is born, praise the lord
      inet:setopts(AcceptSocket, [{active, true}]),
      send(AcceptSocket, "Yellow", []),
      {noreply, S#state{socket=AcceptSocket, next=name}}.

send(Socket, Str, Args) ->
    ok = gen_tcp:send(Socket, io_lib:format(Str++"~n", Args)),
    ok.

   handle_info(E, S) ->
       io:format("mothereffing unexpected: ~p~n", [E]),
       {noreply, S}.

It has aboslutely no effect. handle_info only gets called when the connection is lost because the client disconnects. whenever the client sends data nothing happens.

What could be the problem? I have spend quite some time on this, I really have no idea.
Many 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-14T20:02:51+00:00Added an answer on June 14, 2026 at 8:02 pm

    To conclude, watch out for the options. I was indeed not paying attention to the implications of the set of options. I tried with a more narrowed down situation and worked it out. My problem was the {packet, line} option which implies that \n is considered a message delimiter.

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

Sidebar

Related Questions

I'm trying to make the following SQL server statement to work, but I get
In a nutshell, what I'm trying to do is create a new user, which
I'm trying to use the PredicateBuilder, as described here - http://www.albahari.com/nutshell/predicatebuilder.aspx The following code
In a nutshell, I'm trying to display an animated GIF in a webview. This
Here's what I've been trying to do, in a nutshell: class example <T extends
I'm trying to send XML in following format from C# (DataType string) to SQL
I am having this odd error with my code. I am trying to troubleshoot
In a nutshell, I'm trying to figure out how to programmatically enable and disable
What I'm trying todo in a nutshell is I am using a background queue
I am trying some tutorials on bioconductor; but I get error messages, 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.