Sockets and File Descriptors

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












As far as I have seen, a socket creates 3 file descriptors in the /proc//fd folder, STDIN, STDOUT and STDERR.



When I input in one socket, it should out the other socket, in a raw-TCP connection, but the thing is, when I echothe STDIN it doesn't output the string.



I attach a photo:



enter image description here



I expect to see the output in the listenning socket, but I don't. Thank you







share|improve this question
























    up vote
    0
    down vote

    favorite












    As far as I have seen, a socket creates 3 file descriptors in the /proc//fd folder, STDIN, STDOUT and STDERR.



    When I input in one socket, it should out the other socket, in a raw-TCP connection, but the thing is, when I echothe STDIN it doesn't output the string.



    I attach a photo:



    enter image description here



    I expect to see the output in the listenning socket, but I don't. Thank you







    share|improve this question






















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      As far as I have seen, a socket creates 3 file descriptors in the /proc//fd folder, STDIN, STDOUT and STDERR.



      When I input in one socket, it should out the other socket, in a raw-TCP connection, but the thing is, when I echothe STDIN it doesn't output the string.



      I attach a photo:



      enter image description here



      I expect to see the output in the listenning socket, but I don't. Thank you







      share|improve this question












      As far as I have seen, a socket creates 3 file descriptors in the /proc//fd folder, STDIN, STDOUT and STDERR.



      When I input in one socket, it should out the other socket, in a raw-TCP connection, but the thing is, when I echothe STDIN it doesn't output the string.



      I attach a photo:



      enter image description here



      I expect to see the output in the listenning socket, but I don't. Thank you









      share|improve this question











      share|improve this question




      share|improve this question










      asked Apr 11 at 8:10









      aDoN

      2862515




      2862515




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote













          Opening a socket opens a socket, which is what you see listed as file descriptor 3 in your output (socket:[5474494]). The other three file descriptors are the standard input, output and error descriptors, which are opened by default for any process. In your case, these point to the terminal where the program is running, which is why “surni” shows up there when you write to the file descriptor.



          To write to the socket, you need to use appropriate mechanisms, such as netcat in the other direction:



          echo Hello | nc localhost 9999


          or, if you’re using Bash:



          echo Hello > /dev/tcp/localhost/9999


          However it appears you already have a connection established to port 9999 using another netcat, so that won’t actually work in your case. You need to use the established connection...



          If you’re expecting a long-running nc to provide a way for other processes to feed into the socket, you need to set that up e.g. using a FIFO:



          mkfifo socket-input
          nc localhost 9999 < socket-input
          echo Hello > socket-input





          share|improve this answer






















          • Hello, good answer, I send data in a TCP socket via /dev/tcp/ but this abstracts the layers I want to interact with which are the file descriptors of a socket. Another question, do you know how to bind a process to a socket so that I can send data via the socket? I want to use this since I can't send data to the STDIN of a process (for Linux /proc/<pid>/fd/ descriptors are just symlinks to a terminal)
            – aDoN
            Apr 11 at 13:19










          • Why do you want to interact with the file descriptors? Those are effectively meaningless outside their owning process. I explained how to make a socket available externally, see the last part of my answer.
            – Stephen Kitt
            Apr 11 at 13:32










          • But once the connection is established, you can't feed into the socket with another process, can you? I don't know exacly what is the difference of what you achieve when creating a file with mkfifo
            – aDoN
            Apr 11 at 14:23










          • what you said is a big thing "file descriptors are meaningless outside their owning process" And you seem to be right, but how can you explain this command: strace -p<pid> -s9999 -e write that spy other processes and see the input and output of a process? (nano, vi, python interctive shell...., every process)
            – aDoN
            Apr 11 at 14:28











          • strace uses ptrace to spy on other processes, it gets help from the kernel to view things from inside the target process.
            – Stephen Kitt
            Apr 11 at 14:44










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f436945%2fsockets-and-file-descriptors%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          3
          down vote













          Opening a socket opens a socket, which is what you see listed as file descriptor 3 in your output (socket:[5474494]). The other three file descriptors are the standard input, output and error descriptors, which are opened by default for any process. In your case, these point to the terminal where the program is running, which is why “surni” shows up there when you write to the file descriptor.



          To write to the socket, you need to use appropriate mechanisms, such as netcat in the other direction:



          echo Hello | nc localhost 9999


          or, if you’re using Bash:



          echo Hello > /dev/tcp/localhost/9999


          However it appears you already have a connection established to port 9999 using another netcat, so that won’t actually work in your case. You need to use the established connection...



          If you’re expecting a long-running nc to provide a way for other processes to feed into the socket, you need to set that up e.g. using a FIFO:



          mkfifo socket-input
          nc localhost 9999 < socket-input
          echo Hello > socket-input





          share|improve this answer






















          • Hello, good answer, I send data in a TCP socket via /dev/tcp/ but this abstracts the layers I want to interact with which are the file descriptors of a socket. Another question, do you know how to bind a process to a socket so that I can send data via the socket? I want to use this since I can't send data to the STDIN of a process (for Linux /proc/<pid>/fd/ descriptors are just symlinks to a terminal)
            – aDoN
            Apr 11 at 13:19










          • Why do you want to interact with the file descriptors? Those are effectively meaningless outside their owning process. I explained how to make a socket available externally, see the last part of my answer.
            – Stephen Kitt
            Apr 11 at 13:32










          • But once the connection is established, you can't feed into the socket with another process, can you? I don't know exacly what is the difference of what you achieve when creating a file with mkfifo
            – aDoN
            Apr 11 at 14:23










          • what you said is a big thing "file descriptors are meaningless outside their owning process" And you seem to be right, but how can you explain this command: strace -p<pid> -s9999 -e write that spy other processes and see the input and output of a process? (nano, vi, python interctive shell...., every process)
            – aDoN
            Apr 11 at 14:28











          • strace uses ptrace to spy on other processes, it gets help from the kernel to view things from inside the target process.
            – Stephen Kitt
            Apr 11 at 14:44














          up vote
          3
          down vote













          Opening a socket opens a socket, which is what you see listed as file descriptor 3 in your output (socket:[5474494]). The other three file descriptors are the standard input, output and error descriptors, which are opened by default for any process. In your case, these point to the terminal where the program is running, which is why “surni” shows up there when you write to the file descriptor.



          To write to the socket, you need to use appropriate mechanisms, such as netcat in the other direction:



          echo Hello | nc localhost 9999


          or, if you’re using Bash:



          echo Hello > /dev/tcp/localhost/9999


          However it appears you already have a connection established to port 9999 using another netcat, so that won’t actually work in your case. You need to use the established connection...



          If you’re expecting a long-running nc to provide a way for other processes to feed into the socket, you need to set that up e.g. using a FIFO:



          mkfifo socket-input
          nc localhost 9999 < socket-input
          echo Hello > socket-input





          share|improve this answer






















          • Hello, good answer, I send data in a TCP socket via /dev/tcp/ but this abstracts the layers I want to interact with which are the file descriptors of a socket. Another question, do you know how to bind a process to a socket so that I can send data via the socket? I want to use this since I can't send data to the STDIN of a process (for Linux /proc/<pid>/fd/ descriptors are just symlinks to a terminal)
            – aDoN
            Apr 11 at 13:19










          • Why do you want to interact with the file descriptors? Those are effectively meaningless outside their owning process. I explained how to make a socket available externally, see the last part of my answer.
            – Stephen Kitt
            Apr 11 at 13:32










          • But once the connection is established, you can't feed into the socket with another process, can you? I don't know exacly what is the difference of what you achieve when creating a file with mkfifo
            – aDoN
            Apr 11 at 14:23










          • what you said is a big thing "file descriptors are meaningless outside their owning process" And you seem to be right, but how can you explain this command: strace -p<pid> -s9999 -e write that spy other processes and see the input and output of a process? (nano, vi, python interctive shell...., every process)
            – aDoN
            Apr 11 at 14:28











          • strace uses ptrace to spy on other processes, it gets help from the kernel to view things from inside the target process.
            – Stephen Kitt
            Apr 11 at 14:44












          up vote
          3
          down vote










          up vote
          3
          down vote









          Opening a socket opens a socket, which is what you see listed as file descriptor 3 in your output (socket:[5474494]). The other three file descriptors are the standard input, output and error descriptors, which are opened by default for any process. In your case, these point to the terminal where the program is running, which is why “surni” shows up there when you write to the file descriptor.



          To write to the socket, you need to use appropriate mechanisms, such as netcat in the other direction:



          echo Hello | nc localhost 9999


          or, if you’re using Bash:



          echo Hello > /dev/tcp/localhost/9999


          However it appears you already have a connection established to port 9999 using another netcat, so that won’t actually work in your case. You need to use the established connection...



          If you’re expecting a long-running nc to provide a way for other processes to feed into the socket, you need to set that up e.g. using a FIFO:



          mkfifo socket-input
          nc localhost 9999 < socket-input
          echo Hello > socket-input





          share|improve this answer














          Opening a socket opens a socket, which is what you see listed as file descriptor 3 in your output (socket:[5474494]). The other three file descriptors are the standard input, output and error descriptors, which are opened by default for any process. In your case, these point to the terminal where the program is running, which is why “surni” shows up there when you write to the file descriptor.



          To write to the socket, you need to use appropriate mechanisms, such as netcat in the other direction:



          echo Hello | nc localhost 9999


          or, if you’re using Bash:



          echo Hello > /dev/tcp/localhost/9999


          However it appears you already have a connection established to port 9999 using another netcat, so that won’t actually work in your case. You need to use the established connection...



          If you’re expecting a long-running nc to provide a way for other processes to feed into the socket, you need to set that up e.g. using a FIFO:



          mkfifo socket-input
          nc localhost 9999 < socket-input
          echo Hello > socket-input






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Apr 11 at 8:34

























          answered Apr 11 at 8:22









          Stephen Kitt

          140k22305365




          140k22305365











          • Hello, good answer, I send data in a TCP socket via /dev/tcp/ but this abstracts the layers I want to interact with which are the file descriptors of a socket. Another question, do you know how to bind a process to a socket so that I can send data via the socket? I want to use this since I can't send data to the STDIN of a process (for Linux /proc/<pid>/fd/ descriptors are just symlinks to a terminal)
            – aDoN
            Apr 11 at 13:19










          • Why do you want to interact with the file descriptors? Those are effectively meaningless outside their owning process. I explained how to make a socket available externally, see the last part of my answer.
            – Stephen Kitt
            Apr 11 at 13:32










          • But once the connection is established, you can't feed into the socket with another process, can you? I don't know exacly what is the difference of what you achieve when creating a file with mkfifo
            – aDoN
            Apr 11 at 14:23










          • what you said is a big thing "file descriptors are meaningless outside their owning process" And you seem to be right, but how can you explain this command: strace -p<pid> -s9999 -e write that spy other processes and see the input and output of a process? (nano, vi, python interctive shell...., every process)
            – aDoN
            Apr 11 at 14:28











          • strace uses ptrace to spy on other processes, it gets help from the kernel to view things from inside the target process.
            – Stephen Kitt
            Apr 11 at 14:44
















          • Hello, good answer, I send data in a TCP socket via /dev/tcp/ but this abstracts the layers I want to interact with which are the file descriptors of a socket. Another question, do you know how to bind a process to a socket so that I can send data via the socket? I want to use this since I can't send data to the STDIN of a process (for Linux /proc/<pid>/fd/ descriptors are just symlinks to a terminal)
            – aDoN
            Apr 11 at 13:19










          • Why do you want to interact with the file descriptors? Those are effectively meaningless outside their owning process. I explained how to make a socket available externally, see the last part of my answer.
            – Stephen Kitt
            Apr 11 at 13:32










          • But once the connection is established, you can't feed into the socket with another process, can you? I don't know exacly what is the difference of what you achieve when creating a file with mkfifo
            – aDoN
            Apr 11 at 14:23










          • what you said is a big thing "file descriptors are meaningless outside their owning process" And you seem to be right, but how can you explain this command: strace -p<pid> -s9999 -e write that spy other processes and see the input and output of a process? (nano, vi, python interctive shell...., every process)
            – aDoN
            Apr 11 at 14:28











          • strace uses ptrace to spy on other processes, it gets help from the kernel to view things from inside the target process.
            – Stephen Kitt
            Apr 11 at 14:44















          Hello, good answer, I send data in a TCP socket via /dev/tcp/ but this abstracts the layers I want to interact with which are the file descriptors of a socket. Another question, do you know how to bind a process to a socket so that I can send data via the socket? I want to use this since I can't send data to the STDIN of a process (for Linux /proc/<pid>/fd/ descriptors are just symlinks to a terminal)
          – aDoN
          Apr 11 at 13:19




          Hello, good answer, I send data in a TCP socket via /dev/tcp/ but this abstracts the layers I want to interact with which are the file descriptors of a socket. Another question, do you know how to bind a process to a socket so that I can send data via the socket? I want to use this since I can't send data to the STDIN of a process (for Linux /proc/<pid>/fd/ descriptors are just symlinks to a terminal)
          – aDoN
          Apr 11 at 13:19












          Why do you want to interact with the file descriptors? Those are effectively meaningless outside their owning process. I explained how to make a socket available externally, see the last part of my answer.
          – Stephen Kitt
          Apr 11 at 13:32




          Why do you want to interact with the file descriptors? Those are effectively meaningless outside their owning process. I explained how to make a socket available externally, see the last part of my answer.
          – Stephen Kitt
          Apr 11 at 13:32












          But once the connection is established, you can't feed into the socket with another process, can you? I don't know exacly what is the difference of what you achieve when creating a file with mkfifo
          – aDoN
          Apr 11 at 14:23




          But once the connection is established, you can't feed into the socket with another process, can you? I don't know exacly what is the difference of what you achieve when creating a file with mkfifo
          – aDoN
          Apr 11 at 14:23












          what you said is a big thing "file descriptors are meaningless outside their owning process" And you seem to be right, but how can you explain this command: strace -p<pid> -s9999 -e write that spy other processes and see the input and output of a process? (nano, vi, python interctive shell...., every process)
          – aDoN
          Apr 11 at 14:28





          what you said is a big thing "file descriptors are meaningless outside their owning process" And you seem to be right, but how can you explain this command: strace -p<pid> -s9999 -e write that spy other processes and see the input and output of a process? (nano, vi, python interctive shell...., every process)
          – aDoN
          Apr 11 at 14:28













          strace uses ptrace to spy on other processes, it gets help from the kernel to view things from inside the target process.
          – Stephen Kitt
          Apr 11 at 14:44




          strace uses ptrace to spy on other processes, it gets help from the kernel to view things from inside the target process.
          – Stephen Kitt
          Apr 11 at 14:44












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f436945%2fsockets-and-file-descriptors%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Bahrain

          Postfix configuration issue with fips on centos 7; mailgun relay