How to send text with telnet in Terminal? I would like to send some text to a port on my machine using telnet in the Mac OS X Terminal.

I start telnet using:

telnet localhost 8080


Then I type some text. Is that text send automatically or do I have to do something to send the text?
Here's a simple Python server:

#!/usr/bin/env python

import socket


TCP_IP = '127.0.0.1'
TCP_PORT = 5005
BUFFER_SIZE = 10  # Normally 1024, but we want fast response

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((TCP_IP, TCP_PORT))
s.listen(1)

conn, addr = s.accept()
print 'Connection address:', addr
while 1:
    data = conn.recv(BUFFER_SIZE)
    if not data: break
    print "received data:", data
    conn.send(data)  # echo
conn.close()


Source

Save it as server.py, and run it python server.py.

Then try to connect using the terminal

telnet 127.0.0.1 5005


Then just type anything and press return

The server print the data in the console and send it back to you.

That way, you'll know what you have to do to send data via telnet.