ECHO! Echo! echo. (echo)

Python, 299 295 265 263

from threading import*
from socket import*
a='',7;S=socket
u=S(2,2);u.bind(a)
def U():
 while 1:u.sendto(*u.recvfrom(4**8))
Thread(None,U).start()
def C(c,x):
 while c.send(c.recv(1)):1
s=S(2,1);s.bind(a);s.listen(1)
while 1:Thread(None,C,args=s.accept()).start()

handles both udp and tcp.

@MorganThrapp helped saving 33 (!) chars


Racket, 231

(thread(λ()(do([l(tcp-listen 7)])(#f)(let-values([(i o)(tcp-accept l)])(copy-port i o)))))((λ(s b)(udp-bind! s #f 7)(do()(#f)(let-values([(n h p)(udp-receive! s b)])(udp-send-to s h p b 0 n))))(udp-open-socket)(make-bytes 65535))

TCP and UDP.

The TCP echo server uses a handy Racket procedure named copy-port that copies ports in the background, managed by Racket, instead of by the programmer. That also means I don't have to spin off a thread for each client, only for the listener (so I can start the UDP listener on the main thread).


JavaScript (Node.js) 102 Bytes (51 * 2)

require("net").createServer(s=>s.pipe(s)).listen(7)

You can add UDP for a total of 132 bytes, as seen below:

require("net").createServer(s=>s.pipe(s)).listen(7),(u=require("dgram").createSocket("udp4")).on("message",msg=>u.send(msg)).bind(7)

Was tested on node.js v5.2.0

Make sure to run with sudo on Unix descendants (OS X, Linux, etc.)