Compact iff all continuous functions are uniformly cont. I wonder if someone can help me with this problem:

Let $(X,d)$ be a connected metric space such that all continuous functions $f:(X,d) \to \mathbb{R}$ are uniformly continuous. Show that $(X,d)$ is compact.

A hint is to work with the counter positive and assume that $(X,d)$ is not totally bounded and to use Urysohn functions.
I've been trying to tackle it from different directions and one idea I had was to pick  a sequence $\{x_n\}_{n\in \mathbb{N}}$ such that $x_n \in X \backslash \cup_{k=1}^{n-1} B(x_k,\epsilon)$ and define $f_n(x)=\frac{d(x,X \backslash \mathcal{U}_n )}{d(x,X \backslash \mathcal{U}_n )+ d(x,\overline{B(x_n,\epsilon)} }$ where $\mathcal{U}_n$ is an open set containing $\overline{B(x_n,\epsilon)}$ s.t 
$d( \overline{B(x_n, \epsilon)} , X \backslash \mathcal{U}_n ) <\frac{1}{n}$ and put $f(x)=\sum_{n=1}^{\infty} f_n(x)$.
Would this work, is there any better way to do it?
EDIT
I found the following results that I think might help solving the case:
Def. A space $X$ is said to be compactly generated if it satisfies: A set $A$ is open in $X$ if $A\cap C$ is open in $C$ for each compact subspace $C$ of $X$.
Lemma: A space $X$ is compactly generated if it satisfies the first axiom of countability.
So in particular a metric space is compactly generated(if I'm not mistaken).
Lemma: If $X$ is compactly generated, then a function $f: X \to Y$ is continuous if for each compact subspace $C$ of $X$ the restricted function $\left.f\right|_C$ is continuous.
So if I get this right it boils down to showing that $f(x)= \sum_{n=1}^{\infty} \frac{d(x,X \backslash \mathcal{U}_n )}{d(x,X \backslash \mathcal{U}_n )+ d(x,\overline{B(x_n,\epsilon)} }$ is continuous for each compact subset $C$.
Take an arbitrary compact set $C \subset X$. Since $C$ is compact and $\{x_n \}_{n\in \mathbb{N}}$ is a diverging sequence $C$ can contain at most finitely many elements of $\{x_n \}_{n\in \mathbb{N}}$. Then 
$\left.f\right|_C(x) \sum_{i=1}^{m} \frac{d(x,X \backslash \mathcal{U}_{n_i} )}{d(x,X \backslash \mathcal{U}_{n_i} )+ d(x,\overline{B(x_{n_i},\epsilon)} }$ which is continuous since it's a finite combination of continuous functions.
This implies that $f(x)$ is continuous.
However for any $\delta >0$ one can find an $n \geq 1 : \frac{1}{n} < \delta$.
Then since $d(X \backslash \mathcal{U}_{n},\overline{B(x_{n},\epsilon)})< \frac{1}{n}$ one can pick $x_0 \in X \backslash \mathcal{U}_{n}$ and $x_1 \in 
\overline{B(x_{n},\epsilon)}$ such that $d(x_0,x_1)<\frac{1}{n} < \delta$.
But since $x_0\in X \backslash \mathcal{U}_{n}, f(x_0)=0$ while $x_1 \in \overline{B(x_{n},\epsilon)}$ so $f(x_1)=1$.
I haven't used the fact that $X$ is connected, and that makes me a little uneasy. If someone could check if this looks correct I would be very grateful!
 A: If a metric space $X$ is non-compact then $X$ has a countably infinite closed discrete subspace Y. Because if $(p_n)_{n\in \mathbb N}$  is a Cauchy sequence in $X$ with no convergent subsequence,  let $Y=\{p_n:n\in \mathbb N\}.$
We show that if $(X,d)$ is connected and non-compact then there is a continuous $g:X\to \mathbb R$ that is not uniformly continuous.
Let $Y=\{y_n:n\in \mathbb N\}$ be a closed discrete subspace of $X$ such that  $m\ne n\implies y_m\ne y_n.$ For each $n$ let $r_n=\inf \{d(y_n,y_m):m\ne n\}.$ We have $r_n>0.$  Let $s_n=\min (1/n, r_n/6).$
Let $f_n:X\to [0,1]$ be continuous with $f(y_n)=1,$ and $f(x)=0$ for all $x\in X$ \ $B_d(y_n,s_n).$ 
The triangle inequality and the def'n of $r_n$ imply that for any $x\in X$ there exists $t_x>0$ such that there is at most one $n$ such that $B_d(x,t_x)\cap B_d(y_n,s_n)\ne \phi.$ So $f_n(x)\ne 0$ for at most one $n.$ So $g(x)=\sum_{n=1}^{\infty}f_n(x)$ is defined. 
For brevity (of subscripts) let $U_x=B_d(x,t_x).$ Now $g(x)$ is locally continuous: For each $x\in X$  the function $g|_{U_x}$  is either constantly $0$ or is $f_n|_{U_x}$ for some (unique) $n.$ Local continuity everywhere is equivalent to continuity. So $g$ is continuous. 
Now $X$ is connected so each non-empty open set $B_d(y_n,s_n)$ is not closed. (Its complement is not empty as it contains $y_{n+1}).$ So let $z_n$ belong to the boundary of $B_d(y_n,s_n).$ We have $g(y_n)=f_n(y_n)=1$ and $g(z_n)=f_n(z_n)=0$ but $d(y_n,z_n)=s_n\leq 1/n.$ So $g$ cannot be uniformly continuous. QED.
APPENDIX: To prove that for $x\in X$ there exists $t_x>0$ such that there is at most one $n$ such that $B_d(x,t_x)\cap B_d(y_n,s_n)\ne \phi:$
Note that for $n\ne n'$ we have $r_n\leq d(y_n,y'_n)\geq r_{n'}$ so $d(y_n,y_{n'})\geq \max(r_n,r'_n).$ 
(1). If $n\ne n'$ then  $B_d(y_n,s_n)$ and  $B_d(y_{n'},s_{n'})$ are disjoint, because if $z$ is in both of them then $$0<\max (r_n,r_{n'})\leq d(y_n,y_{n'})\leq d(y_n,z)+d(z,y_{n'})<s_n+s_{n'}\leq r_n/6+r_{n'}/6\leq$$ $$\leq \max (r_n,r_{n'})/3$$  a contradiction.
So if $x\in B_d(y_n,s_n)$ for some $n,$ we can take $t_x>0$ where $t_x$ is small enough that $B_d(x,t_x)\subset B_d(y_n,s_n).$
(2). If $x\not \in B_d(y_n,r_n)$ for any $n,$ let $t_x=(1/3)\inf \{d(x,y):y\in Y\}.$ We have $t_x>0$. Suppose by contradiction  that $n\ne n',$  with $a\in B_d(y_n,s_n)\cap B_d(x,t_x)$ and $b\in B_d(y_{n'},s_{n'})\cap B_d(x,t_x).$   Then $$d(y_n,y_n')\leq d(y_n,a)+d(a,x)+d(x,b)+d(b,y_{n'})<s_n+2t_x+s_{n'}\leq$$ $$\leq  r_n/6+2t_x+r_{n'}/6\leq 2t+d(y_n,y_{n'})/3$$ which implies $t_x\geq d(y_n,y_{n'})/3\geq r_n/3\geq 2s_n.$ This implies $$d(x,y_n)\leq d(x,a)+d(a,y_n)\leq t_x+s_n\leq t_x+(t_x/2)<2t_x.$$ So $y_n\in B_d(x,2t_x),$ contradicting the def'n of $t_x.$
A: this paper gives necessary and sufficient conditions for $(X,d)$ to have the property that all continuous functions on it (to the reals, fo example) are uniformly continuous. It's something close to, but not quite, compactness.
