anchor.diff:  			{ok, Header} ->
   			    handle_payload(Socket, KeepAlive, Timeout, Header);
   			{error, Reason} when KeepAlive == false ->
  -			    gen_tcp:close(Socket),
  +			    close(Socket),
   			    {error, Reason};
   			{error, Reason} -> {error, Socket, Reason}
   		    end;
   		{error, Reason} when KeepAlive == false ->
  -		    gen_tcp:close(Socket),
  +		    close(Socket),
   		    {error, Reason};
  -		{error, Reason} -> {error, Socket, Reason}
  +		{error, Reason} ->
  +		    {error, Socket, Reason}
   	    end;
   	{error, Reason} when KeepAlive == false ->
  -	    gen_tcp:close(Socket),
  +	    close(Socket),
   	    {error, Reason};
   	{error, Reason} -> {error, Socket, Reason}
       end.
   
   send(Socket, URI, false, Payload) ->
       send(Socket, URI, "Connection: close\r\n", Payload);
  -send(Socket, URI, true, Payload) -> send(Socket, URI, "Connection: keep-alive\r\n", Payload);
  +send(Socket, URI, true, Payload) -> send(Socket, URI, "", Payload);
  +send(Socket, {Host,URI}, Header, Payload) ->
  +    Request =
  +	["POST ", URI, " HTTP/1.1\r\n",
  +	 "Content-Length: ", integer_to_list(lists:flatlength(Payload)),
  +	 "\r\n",
  +	 "User-Agent: Erlang XML-RPC Client 1.13\r\n",
  +	 "Content-Type: text/xml\r\n",
  +	 "Host: ", Host, "\r\n",
  +	 Header, "\r\n",
  +	 Payload],
  +    send(Socket, Request);
   send(Socket, URI, Header, Payload) ->
       Request =
   	["POST ", URI, " HTTP/1.1\r\n",
   	 "Content-Length: ", integer_to_list(lists:flatlength(Payload)),
   	 "\r\n",
   	 "User-Agent: Erlang XML-RPC Client 1.13\r\n",
  -	 "Content-Type: text/xml\r\n",
  +	 "Content-Type: text/XML\r\n",
   	 Header, "\r\n",
   	 Payload],
  -    gen_tcp:send(Socket, Request).
  +    send(Socket, Request).
   
   parse_response(Socket, Timeout) ->
  -    inet:setopts(Socket, [{packet, line}]),
  -    case gen_tcp:recv(Socket, 0, Timeout) of
  -	{ok, "HTTP/1.0 200 OK\r\n"} -> parse_header(Socket, Timeout);
  +    setopts(Socket, [{packet, line}]),
  +    case recv(Socket, 0, Timeout) of
   	{ok, "HTTP/1.1 200 OK\r\n"} -> parse_header(Socket, Timeout);
   	{ok, StatusLine} -> {error, StatusLine};
   	{error, Reason} -> {error, Reason}
  
positive.code: parse_header(Socket, Timeout) -> parse_header(Socket, Timeout, #header{}).
  
  parse_header(Socket, Timeout, Header) ->
  	case gen_tcp:recv(Socket, 0, Timeout) of
  	{ok, "\r\n"} when Header#header.content_length == undefined ->
  	    {error, missing_content_length};
  	{ok, "\r\n"} -> {ok, Header};
  	{ok, HeaderField} ->
  	    case string:tokens(string:to_lower(HeaderField), " \r\n") of
  		["content-length:", ContentLength] ->
  			try
  				Value = list_to_integer(ContentLength),
  			    parse_header(Socket, Timeout,
  					 Header#header{content_length = Value})
  		    catch
  				_ -> {error, {invalid_content_length, ContentLength}}
  		    end;
  		["connection:", "close"] ->
  		    parse_header(Socket, Timeout,
  				 Header#header{connection = close});
  		_ ->
  
negative.code: 	    case xmlrpc_decode:payload(Payload) of
  		{ok, DecodedPayload} when KeepAlive == false ->
  		    ?DEBUG_LOG({decoded_response, DecodedPayload}),
  		    close(Socket),
  		    {ok, DecodedPayload};
  		{ok, DecodedPayload} when KeepAlive == true,
  					  Header#header.connection == close ->
  		    ?DEBUG_LOG({decoded_response, DecodedPayload}),
  		    close(Socket),
  		    {ok, Socket, DecodedPayload};
  		{ok, DecodedPayload} ->
  		    ?DEBUG_LOG({decoded_response, DecodedPayload}),
  		    {ok, Socket, DecodedPayload};
  		{error, Reason} when KeepAlive == false ->
  		    close(Socket),
  		    {error, Reason};
  		{error, Reason} when KeepAlive == true,
  				     Header#header.connection == close ->
  		    close(Socket),
  		    {error, Socket, Reason};
  		{error, Reason} ->
  		    {error, Socket, Reason}
  	    end;
  	{error, Reason} when KeepAlive == false ->
  	    close(Socket),
  	    {error, Reason};
  	{error, Reason} when KeepAlive == true,
  			     Header#header.connection == close ->
  	    close(Socket),
  	    {error, Socket, Reason};
  	{error, Reason} -> {error, Socket, Reason}
      end.
  
  get_payload(Socket, Timeout, ContentLength) ->
      setopts(Socket, [{packet, raw}]),
      recv(Socket, ContentLength, Timeout).
  
  %% Exported: start_link/{1,5,6}
  
  start_link(Handler) ->
      start_link(4567, 1000, 60000, Handler, undefined).
  
  start_link(Port, MaxSessions, Timeout, Handler, State) ->
      start_link(all, Port, MaxSessions, Timeout, Handler, State).
  
  start_link(IP, Port, MaxSessions, Timeout, Handler, State) ->
      OptionList = [{active, false}, {reuseaddr, true}|ip(IP)],
      SessionHandler = {xmlrpc_http, handler, [Timeout, Handler, State]},
      tcp_serv:start_link([Port, MaxSessions, OptionList, SessionHandler]).
  
  ip(all) -> [];
  ip(IP) when is_tuple(IP) -> {ip, IP}.
  