Nick Ing-Simmons wrote:
Martin J. Evans <[EMAIL PROTECTED]> writes:

I have a module based on IO::Socket::INET which has a method which should be able to send UTF-8 across the socket. When I call the method with a UTF-8 string it does a:

print $sock $string

where $sock was returned by IO::Socket::INET and $string contains UTF-8 characters. I get a warning:

Wide character in print at ESXMLODBC/XMLREQUEST.pm line 254.

How do I make the default encoding on the socket UTF-8 in the same way as you do with file handles (e.g. open(my $fh,'>:utf8', 'anything') or binmode (FH, ":utf8"))?


A socket is a file handle so :

binmode($sock,":utf8");

should work.


This does not seem to work. My code looks like this:


    $self->{_socket} =
        IO::Socket::INET->new(
                              PeerAddr => $self->{Server},
                              PeerPort => $self->{Port},
                              Proto => "tcp",
                              Timeout => 20,
                              Type => SOCK_STREAM);
    if (!$self->{_socket}) {
        $self->{ErrorState} = "HY000";
        $self->{ErrorText} =
            "Failed to connect to server $self->{Server} on port $self->{Port}";
        return undef;
    }
    $self->{_Connected} = 1;

and later I do a:

print $self->{_socket} $string

where $string in this instance is:

my $euro = "\x{20ac}";
my $string = "insert into mjeunicode values ($euro)";

adding

binmode($self->{_socket}, ":utf8");

after the IO::Socket::INET->new does not seem to help. Forget that this looks like it is an insert statement into a database; Perl is whinging at the point of the print to the socket.

I'm obviously missing something rather fundamental here. Any clues?

Martin



Reply via email to