# Socket Connection to Server and Response is in ISO 8859-1 charset

**URL:** <https://www.ruby-forum.com/t/socket-connection-to-server-and-response-is-in-iso-8859-1-charset/128340>\
**Category:** Rails\
**Created:** [February 6, 2008, 10:01pm UTC](https://www.ruby-forum.com/t/socket-connection-to-server-and-response-is-in-iso-8859-1-charset/128340 "2008-02-06T22:01:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 6, 2008, 10:01pm UTC](https://www.ruby-forum.com/t/socket-connection-to-server-and-response-is-in-iso-8859-1-charset/128340/1 "2008-02-06T22:01:04Z")

</div>

Hi,

in my little rail application I have to communicate with a server and  
everything works great. Except one issue:  
The server responses are in ISO 8859-1 charset and it seems that I am  
not able to convert that to utf-8 correctly, which leads to an  
exception in my mysql insert statement. (seems that one of our German  
extra characters)

Could please somebody help me and explain how to convert my server  
response correctly?

That s the code I am currently using:  
Timeout::timeout(2) do  
@client = TCPSocket.open(server[:name], server[:port])  
end

# get initial hello from server

server\_response = @client.gets

@client.send(command.get\_command(), 0)  
while ((command.response.nil? || !command.response.complete?) &&  
(response\_line = @client.gets()))  
command.set\_response(my\_parser.parse\_response(response\_line,  
command.retrieve\_command?))  
end

–  
Volker

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 8, 2008, 9:05pm UTC](https://www.ruby-forum.com/t/socket-connection-to-server-and-response-is-in-iso-8859-1-charset/128340/2 "2008-02-08T21:05:38Z")

</div>

Ok… do not trust your dos box…

A simple: response\_line = Iconv.conv(‘utf-8’, ‘ISO-8859-1’,  
response\_line)  
did the trick.

On 6 Feb., 21:59, “removed\_email\_address@domain.invalid”
