cat /usr/share/dict/words | more
ps
cat ...
実行ターミナルで qcat /usr/share/dict/words | more
は2つのプロセスが実行されているmkfifo /tmp/mypipe
で FIFO (名前付きパイプ) を作成cat /usr/share/dict/words > /tmp/mypipe
more -f /tmp/mypipe
$ cd $ mkdir net $ cd net
#!/usr/bin/env python # UNIX domain Echo server import socket import os PIPE = '/tmp/socket54321' s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) s.bind(PIPE) s.listen(1) conn, addr = s.accept() print 'Connected.' while True: data = conn.recv(1024) if not data: break print 'Echoing:', data conn.send(data) print 'Closing.' conn.close() os.unlink(PIPE)
#!/usr/bin/env python # UNIX domain Echo client import socket PIPE = '/tmp/socket54321' s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) print 'Connecting %s.' % repr(PIPE) s.connect(PIPE) try: while True: t = raw_input('> ') s.send(t) data = s.recv(1024) print 'Received:', data except (EOFError, KeyboardInterrupt): pass print 'Closing.' s.close()
$ chmod +x unixSocketServer.py $ chmod +x unixSocketClient.py
#!/usr/bin/env python # INET domain Echo server import socket HOST = '0.0.0.0' PORT = 54321 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((HOST, PORT)) s.listen(1) conn, addr = s.accept() print 'Connected by', addr while True: data = conn.recv(1024) if not data: break print 'Echoing:', data conn.send(data) print 'Closing.' conn.close()
#!/usr/bin/env python # INET domain Echo client import socket HOST = '127.0.0.1' PORT = 54321 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) print 'Connecting %s.' % repr((HOST, PORT)) s.connect((HOST, PORT)) try: while True: t = raw_input('> ') s.send(t) data = s.recv(1024) print 'Received:', data except (EOFError, KeyboardInterrupt): pass print 'Closing.' s.close()
telnet 127.0.0.1 54321
を実行してみよう。telnet>
プロンプトを出し、quit
を入れる。netstat -a | grep 54321
と入れてみると、54321 番ポートの状態がわかる。