<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:12pt"><div>It works! thank you!</div><div class="yahoo_quoted" style="display: block;"> <br> <br> <div style="font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 12pt;"> <div style="font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 12pt;"> <div dir="ltr"> <font size="2" face="Arial"> On Wednesday, March 26, 2014 7:00 PM, Fred Hebert <mononcqc@ferd.ca> wrote:<br> </font> </div>  <div class="y_msg_container">Hi, I have a solution.<br clear="none"><br clear="none">As part of recon (which allows to use strings and whatnot as ports) to<br clear="none">diagnose issues, I have developed a term_to_port function that uses the<br clear="none">serialized binary form of a port and uses binary_to_term/1
 to make it<br clear="none">into a real Erlang term:<br clear="none"><br clear="none"><a shape="rect" href="https://github.com/ferd/recon/blob/master/src/recon_lib.erl#L157-177" target="_blank">https://github.com/ferd/recon/blob/master/src/recon_lib.erl#L157-177</a><br clear="none"><br clear="none">    %% @doc Transforms a given term to a port<br clear="none">    -spec term_to_port(recon:port_term()) -> port().<br clear="none">    term_to_port(Port) when is_port(Port) -> Port;<br clear="none">    term_to_port(Name) when is_atom(Name) -> whereis(Name);<br clear="none">    term_to_port("#Port<0."++Id) -><br clear="none">        N = list_to_integer(lists:sublist(Id, length(Id)-1)), % drop trailing '>'<br clear="none">        term_to_port(N);<br clear="none">    term_to_port(N) when is_integer(N) -><br clear="none">     
   %% We rebuild the term from the int received:<br clear="none">        %% <a shape="rect" href="http://www.erlang.org/doc/apps/erts/erl_ext_dist.html#id86892" target="_blank">http://www.erlang.org/doc/apps/erts/erl_ext_dist.html#id86892</a><br clear="none">        Name = iolist_to_binary(atom_to_list(node())),<br clear="none">        NameLen = iolist_size(Name),<br clear="none">        Vsn = binary:last(term_to_binary(self())),<br clear="none">        Bin = <<131, % term encoding value<br clear="none">                102, % port tag<br clear="none">                100, % atom ext tag, used for node name<br clear="none">                NameLen:2/unit:8,<br clear="none">               
 Name:NameLen/binary,<br clear="none">                N:4/unit:8, % actual counter value<br clear="none">                Vsn:8>>, % version<br clear="none">        binary_to_term(Bin).<br clear="none"><br clear="none">I'm guessing this could be useful in your case here, if gen_tcp:listen<br clear="none">doesn't work (and it should totally work)<br clear="none"><br clear="none">Regards,<br clear="none">Fred.<br clear="none"><div class="yqt5046125432" id="yqtfd05335"><br clear="none">On 03/26, Dror Mein wrote:<br clear="none">> Hey all,<br clear="none">> <br clear="none">> I want to eunit+meck test a simple telnet client which uses the guard is_port(Port).<br clear="none">> how can I pass something in meck:expect/4 that will pass the guard?<br clear="none">> <br clear="none">> is it a record/reference that I can make up?<br
 clear="none">> can I use hd(erlang:ports()) -> #Port<0.0> without blowing up?<br clear="none">> Thanks</div><br clear="none"><br clear="none">> _______________________________________________<br clear="none">> erlang-questions mailing list<br clear="none">> <a shape="rect" ymailto="mailto:erlang-questions@erlang.org" href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br clear="none">> <a shape="rect" href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><div class="yqt5046125432" id="yqtfd49669"><br clear="none"><br clear="none"></div><br><br></div>  </div> </div>  </div> </div></body></html>