          (deactivate-mark nil) ; Prevents json-encode from interfering with shift-selection-mode
          (url-request-data (json-encode doc))
          (url-show-status nil)
-         (url (url-parse-make-urlobj "http" nil nil "127.0.0.1" port "/" nil nil nil)))
+         (url (url-parse-make-urlobj "http" nil nil tern-server port "/" nil nil nil)))
     (url-http url #'tern-req-finished (list c))))
 
 (defun tern-req-finished (c)

                            (setf retrying t)
                            (let ((old-port tern-known-port))
                              (setf tern-known-port nil)
                              (tern-find-server callback old-port)))
                           (t (funcall f err data))))))
    (tern-find-server callback)))


                    (with-current-buffer (find-file-noselect (expand-file-name (cdr (assq 'name file)) tern-project-dir))
                      (setf tern-buffer-is-dirty nil))))
                (funcall f data))
               ((not (eq mode :silent)) (tern-message "Request failed: %s" err)))))
     doc)))

(defun tern-send-buffer-to-server ()
