{"node_id": "f3b9a5c5-2f95-11f1-beb3-e86a64d24d78", "revisions": [{"id": "f3ba84cd-2f95-11f1-9ee8-e86a64d24d78", "node_id": "f3b9a5c5-2f95-11f1-beb3-e86a64d24d78", "user_id": "edc3f576-2f95-11f1-900f-e86a64d24d78", "author": "foxhop", "data": "linux-nc-and-python-sockets\r\n==============================\r\n\r\nnc or netcat lets you create socket servers or connect to services via sockets.\r\n\r\nThe nc man page is excellent.  This first thing I tried was creating a simple-chat like program between two terminals.\r\n\r\nSimple nc chat application\r\n=================================\r\n\r\nStart listening (nc -l) for a connection on a port (31337).\r\n\r\n**On terminal A**\r\n\r\n.. code-block:: bash\r\n\r\n nc -l 31337\r\n \r\nConnect to (127.0.0.1) on a port (31337).\r\n\r\n**On terminal B**\r\n\r\n.. code-block:: bash\r\n\r\n nc 127.0.0.1 31337\r\n \r\nLike the man page suggests all text submitted on either terminal A or B will appear on both terminals.\r\nConventionally the server \"listening\" for connections is typically labeled the server.  In this case neither terminal is a server because if either closes, both close...\r\n\r\n\r\nUse python to interact with nc\r\n=================================== \r\n\r\nOn terminal A\r\n\r\n.. code-block:: bash\r\n\r\n nc -l 31337\r\n\r\nOn terminal b\r\n\r\n.. code-block:: python\r\n\r\n python\r\n\r\n >>> import socket\r\n >>> s = socket.socket( socket.AF_INET, socket.SOCK_STREAM )\r\n >>> s.connect( ( 'localhost', 31337 ) )\r\n >>> s.send( 'python says hello nc' )\r\n 20\r\n >>> s.recv( 30 )\r\n 'nc says hello python\\n'\r\n >>> # To learn more about sockets do:\r\n >>> help( s )\r\n >>> # when you are finished run s.close()\r\n\r\nThe constant socket.AF_INET creates a socket which allows us to connect to an ip/name and port.  The constant socket.AF_UNIX  creates a socket which allows us to connect via files?  socket.SOCK_STREAM is the type of socket (tcp/ip).  socket.SOCK_DGRAM (data-gram)\r\n\r\n\r\n", "source_format": "rst", "revision_number": 5, "created": 1347744223000}, {"id": "f3ba80a7-2f95-11f1-bd19-e86a64d24d78", "node_id": "f3b9a5c5-2f95-11f1-beb3-e86a64d24d78", "user_id": "edc3f576-2f95-11f1-900f-e86a64d24d78", "author": "foxhop", "data": "linux-nc-and-python-sockets\r\n==============================\r\n\r\nnc or netcat lets you create socket servers or connect to services via sockets.\r\n\r\nThe nc man page is excellent.  This first thing I tried was creating a simple-chat like program between two terminals.\r\n\r\nSimple nc chat application\r\n=================================\r\n\r\nStart listening (nc -l) for a connection on a port (31337).\r\n\r\n**On terminal A**\r\n\r\n.. code-block:: bash\r\n\r\n nc -l 31337\r\n \r\nConnect to (127.0.0.1) on a port (31337).\r\n\r\n**On terminal B**\r\n\r\n.. code-block:: bash\r\n\r\n nc 127.0.0.1 31337\r\n \r\nLike the man page suggests all text submitted on either terminal A or B will appear on both terminals.\r\nConventionally the server \"listening\" for connections is typically labeled the server.  In this case neither terminal is a server because if either closes, both close...\r\n\r\n\r\nUse python to interact with nc\r\n=================================== \r\n\r\nOn terminal A\r\n\r\n.. code-block:: bash\r\n\r\n nc -l 31337\r\n\r\nOn terminal b\r\n\r\n.. code-block:: python\r\n\r\n python\r\n\r\n >>> import socket\r\n >>> s = socket.socket( socket.AF_INET, socket.SOCK_STREAM )\r\n >>> s.connect( ( 'localhost', 31337 ) )\r\n >>> s.send( 'python says hello nc' )\r\n 20\r\n >>> s.recv( 30 )\r\n 'nc says hello python\\n'\r\n >>> # To learn more about sockets do:\r\n >>> help( s )\r\n >>> # when you are finished run s.close()\r\n\r\n \r\n\r\n\r\n", "source_format": "rst", "revision_number": 4, "created": 1347743435000}, {"id": "f3ba7c25-2f95-11f1-85f5-e86a64d24d78", "node_id": "f3b9a5c5-2f95-11f1-beb3-e86a64d24d78", "user_id": "edc3f576-2f95-11f1-900f-e86a64d24d78", "author": "foxhop", "data": "linux-nc-and-python-sockets\r\n==============================\r\n\r\nnc or netcat lets you create socket servers or connect to services via sockets.\r\n\r\nThe nc man page is excellent.  This first thing I tried was creating a simple-chat like program between two terminals.\r\n\r\nSimple nc chat application\r\n=================================\r\n\r\nStart listening (nc -l) for a connection on a port (31337).\r\n\r\n**On terminal A**\r\n\r\n.. code-block:: bash\r\n\r\n nc -l 31337\r\n \r\nConnect to (127.0.0.1) on a port (31337).\r\n\r\n**On terminal B**\r\n\r\n.. code-block:: bash\r\n\r\n nc 127.0.0.1 31337\r\n \r\nLike the man page suggests all text submitted on either terminal A or B will appear on both terminals.\r\nConventionally the server \"listening\" for connections is typically labeled the server.  In this case neither terminal is a server because if either closes, both close...\r\n\r\n\r\nUse python to interact with nc\r\n=================================== \r\n\r\nOn terminal A\r\n\r\n.. code-block:: bash\r\n\r\n nc -l 31337\r\n\r\nOn terminal b\r\n\r\n.. code-block:: python\r\n\r\n python\r\n\r\n >>> import socket\r\n >>> s = socket.socket( socket.AF_INET, socket.SOCK_STREAM )\r\n >>> s.connect( ( 'localhost', 31337 ) )\r\n >>> s.send( 'python says hello nc' )\r\n 20\r\n >>> s.recv( 30 )\r\n 'nc says hello python\\n'\r\n >>> # To learn more about sockets do:\r\n >>> help( s )\r\n\r\n \r\n\r\n\r\n", "source_format": "rst", "revision_number": 3, "created": 1347742593000}, {"id": "f3ba7700-2f95-11f1-b3d3-e86a64d24d78", "node_id": "f3b9a5c5-2f95-11f1-beb3-e86a64d24d78", "user_id": "edc3f576-2f95-11f1-900f-e86a64d24d78", "author": "foxhop", "data": "linux-nc-and-python-sockets\r\n==============================\r\n\r\nnc or netcat lets you create socket servers or connect to services via sockets.\r\n\r\nThe nc man page is excellent.  This first thing I tried was creating a simple-chat like program between two terminals.\r\n\r\nSimple nc chat application\r\n=================================\r\n\r\nStart listening (nc -l) for a connection on a port (31337).\r\n\r\n**On terminal A**\r\n\r\n.. code-block:: bash\r\n\r\n nc -l 31337\r\n \r\nConnect to (127.0.0.1) on a port (31337).\r\n\r\n**On terminal B**\r\n\r\n.. code-block:: bash\r\n\r\n nc 127.0.0.1 31337\r\n \r\nLike the man page suggests all text submitted on either terminal A or B will appear on both terminals.\r\nConventionally the server \"listening\" for connections is typically labeled the server.\r\n\r\n\r\nUse python to interact with nc\r\n=================================== \r\n\r\nOn terminal A\r\n\r\n.. code-block:: bash\r\n\r\n nc -l 31337\r\n\r\nOn terminal b\r\n\r\n.. code-block:: python\r\n\r\n python\r\n\r\n >>> import socket\r\n >>> s = socket.socket( socket.AF_INET, socket.SOCK_STREAM )\r\n >>> s.connect( ( 'localhost', 31337 ) )\r\n >>> s.send( 'python says hello nc' )\r\n 20\r\n >>> s.recv( 30 )\r\n 'nc says hello python\\n'\r\n >>> # To learn more about sockets do:\r\n >>> help( s )\r\n\r\n \r\n\r\n\r\n", "source_format": "rst", "revision_number": 2, "created": 1347742562000}, {"id": "f3ba6f2a-2f95-11f1-bbbe-e86a64d24d78", "node_id": "f3b9a5c5-2f95-11f1-beb3-e86a64d24d78", "user_id": "edc3f576-2f95-11f1-900f-e86a64d24d78", "author": "foxhop", "data": "linux-nc-and-python-sockets\r\n==============================\r\n\r\nnc or netcat lets you create socket servers or connect to services via sockets.\r\n\r\nThe nc man page is excellent.  This first thing I tried was creating a simple-chat like program between two terminals.\r\n\r\nSimple nc chat application\r\n=================================\r\n\r\nStart listening (nc -l) for a connection on a port (31337).\r\n\r\nOn terminal A\r\n\r\n.. code-block:: bash\r\n\r\n nc -l 31337\r\n \r\nConnect to (127.0.0.1) on a port (31337).\r\n\r\nOn terminal B\r\n\r\n.. code-block:: bash\r\n\r\n nc 127.0.0.1 31337\r\n \r\nLike the man page suggests all text submitted on either terminal A or B will appear on both terminals.\r\nConventionally the server \"listening\" for connections is typically labeled the server.\r\n\r\n\r\nUse python to interact with nc\r\n=================================== \r\n\r\nOn terminal A\r\n\r\n.. code-block:: bash\r\n\r\n nc -l 31337\r\n\r\nOn terminal b\r\n\r\n.. code-block:: python\r\n\r\n python\r\n\r\n >>> import socket\r\n >>> s = socket.socket( socket.AF_INET, socket.SOCK_STREAM )\r\n >>> s.connect( ( 'localhost', 31337 ) )\r\n >>> s.send( 'python says hello nc' )\r\n 20\r\n >>> s.recv( 30 )\r\n 'nc says hello python\\n'\r\n >>> # To learn more about sockets do:\r\n >>> help( s )\r\n\r\n \r\n\r\n\r\n", "source_format": "rst", "revision_number": 1, "created": 1347742503000}], "count": 5}