[Erlang 0075] Bad value on output port 'tcp _ Inet'

Source: Internet
Author: User
Xiao Chao encountered a problem: gen_tcp: sending method error, bad value on output port 'tcp _ Inet '; literally, the data value sent to the port is bad value; open erl5.9 \ Lib \ kernel-2.15 \ SRC \ gen_tcp.erl to check the source code of gen_tcp:

% Send %-spec send (socket, packet)-> OK | {error, reason} When socket: socket (), packet: iodata (), % <-Note: reason: iNet: POSIX (). send (S, packet) When is_port (S)-> case inet_db: lookup_socket (s) of {OK, MOD}-> mod: Send (S, packet ); error-> error end.

 

From the description of the function interface, we can see that the data requirement is iodata. It is estimated that the 'bad value' data is probably not iodata. Let's take an experiment and see:

Eshell v5.9 (abort with ^ g) 1> {OK, S0} = gen_tcp: Listen (5678, []). {OK, # port <0.506 >}2> {OK, S1} = gen_tcp: connect ("localhost", 5678, []). {OK, # port <0.517 >}3> {OK, S2} = gen_tcp: accept (S0 ). {OK, # port <0.518 >}4> gen_tcp: Send (S1, "Message Text \ 0 "). ok5> gen_tcp: Send (S1, ["message text", 0]). ok6> gen_tcp: Send (S1, ["message text us", 0]). ok7> flush (). shell got {tcp, # port <0.518>, [109,101,115,115, 97,103,101, 32,116,101,120,116, 0]} shell got {tcp, # port <0.518>, [109,101,115,115, 97,103,101, 32,116,101,120,116, 0]} shell got {tcp, # port <0.518>, [109,101,115,115, 97,103,101, 32,116,101,120,116,206,210,195,199, 0]} ok8> gen_tcp: Send (S1, ["message text us ", MSG, 0]). {error, einval }= Error Report ==== 23-aug-2012: 11: 37: 23 === bad value on output port 'tcp _ Inet '9> gen_tcp: send (S1, ["message text us", 0]). ok10> gen_tcp: Send (S1, ["message text us", 12, 0]). ok11> gen_tcp: Send (S1, ["message text us", 1222,0]). {error, einval }= Error Report ==== 23-aug-2012: 11: 57: 24 === bad value on output port 'tcp _ Inet '12>

 

Reproduce the problem that Xiaochao encountered, as long as the data sent is notIodataThe error "bad value on output port 'tcp _ Inet '" will be reported. Based on this clue, Mr. Chao followed up and sent the data as an atom such as error_protocol due to protocol-Layer Code problems.

 

I have prepared an article [LINK] About iodata and iolist. Here I will only post the definition of iodata again:

Iodata () = iolist () | binary ()
Iolist () maybe_improper_list (char () | binary () | iolist (), binary () | [])
Maybe_improper_list () maybe_improper_list (any (), any ())
Byte () 0. 255
Char () 0 .. 16 # 10ffffmaybe_improper_list (t) maybe_improper_list (T, any ())

Or:

Iodata = UNICODE: chardata ()

Chardata () = charlist () | unicode_binary ()

Charlist () = [unicode_char () | unicode_binary () | charlist ()]

Unicode_binary () = binary ()

A binary () with characters encoded in the UTF-8 coding standard.

The following information is the same reason:

[1] http://www.trapexit.org/forum/viewtopic.php? P = 39602 & SID = ba065c1a5b0c789b4383501784d416ec

[2] http://erlang.org/pipermail/erlang-questions/2009-September/046396.html

 

Thumbnail

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.