Message passin in client-server architecture

Home Forums Basic Erlang Message passin in client-server architecture

This topic contains 1 reply, has 1 voice, and was last updated by  hamzi 1 week, 4 days ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #51778

    hamzi
    Member

    Hi

    I’m new to working in erlang, and I have a school lab about message passing, and now I’m trying to make a new channel process, so the user can join a chatroom. Why isn’t this working?
    The functions start, and request is defined in the GUI and the just start a new process or send a message.

    Thanks in advance.

    – SERVER CODE

    loop(St, {join, Client, Channel}) ->
    	case lists:member(Client, St#server_st.client) of 
    		false -> 
    			{{error, user_not_connected, "User is not connected"}, St};
    		true ->
    			case lists:member(list_to_atom(Channel), registered()) of
    				true ->  
    					helper:request(list_to_atom(Channel), {join, Client}),
    					{ok, St};
    				false ->
    					helper:start(list_to_atom(Channel), channels:initial_state(Channel), fun main/1),
    					helper:request(list_to_atom(Channel), {join, Client}),
    					NewState = St#server_st{channels = (lists:append(list_to_atom(Channel), St#server_st.channels))},
    						{ok, NewState}
    
    			end
    	end.
    
    -- client code 
     % Join channel
    loop(St, {join, _Channel}) ->
    	if length(St#cl_st.server) == 0 -> 
    		   {{error, user_not_connected, "User is not connected"}, St};
    	true ->
    	    case catch(helper:request(list_to_atom(St#cl_st.server), {join, St#cl_st.nick, St#cl_st.channels})) of
    			{{error, user_already_joined, _Message}} ->
    				{{error, user_not_connected, "User already joined"}, St};
    			{'EXIT', _Reason} ->
    					{{error, server_not_reached, "Timeout"}, St};
    			ok -> 
    				 {ok, St}
    		end
    	end;
    
    -- channels module code
    loop(St, {join, Client}) -> 
    	case lists:member(Client, St#channel_st.client) of
    		true -> 
    			{{error, user_already_joined,"User has already joined"}, St};
    		false ->
    			NewState = #channel_st{client = lists:append(Client,St#channel_st.client)},
    			{ok, NewState}
    	end;
    #51779

    hamzi
    Member

    Edit: I just get a timeout when I try to connect to the channel

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.