www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - reading and writing from a socket simo at once

reply "Ameer Armaly" <ameer_armaly hotmail.com> writes:
Hi.
How would I be able to read from a socket, but still take in info from the 
keyboard and send it out;kind of like telnet?

-- 
---
Life is either tragedy or comedy.
 Usually it's your choice. You can whine or you can laugh.
--Animorphs 
Jul 06 2005
next sibling parent "Regan Heath" <regan netwin.co.nz> writes:
On Wed, 6 Jul 2005 17:31:56 -0400, Ameer Armaly <ameer_armaly hotmail.com>  
wrote:
 How would I be able to read from a socket, but still take in info from  
 the keyboard and send it out;kind of like telnet?

Start a thread, in that thread read data from the socket into a buffer. The main thread then loops checking for data in the buffer and checking for keystrokes. You need a non blocking keystroke checking function, some functions block until a complete line has been entered. You'll need to synchronise access to the socket and the buffer, probably best to place both of these in a class dedicated to this purpose. Regan
Jul 06 2005
prev sibling parent "Regan Heath" <regan netwin.co.nz> writes:
------------AMaTACAczYCsVaYq3NU9sc
Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-15
Content-Transfer-Encoding: 8bit

On Wed, 6 Jul 2005 17:31:56 -0400, Ameer Armaly <ameer_armaly hotmail.com>  
wrote:
 How would I be able to read from a socket, but still take in info from  
 the keyboard and send it out;kind of like telnet?

Here is an example telnet program I just wrote in D. I don't guarantee it works at all, especially on anything other than windows, or for the most basic things. Regan ------------AMaTACAczYCsVaYq3NU9sc Content-Disposition: attachment; filename=telnet.zip Content-Type: application/zip; name=telnet.zip Content-Transfer-Encoding: Base64 UEsDBBQAAAAIACK05zIpWrHcmAMAAOIJAAANAHoAYXN5bmNzb2NrZXQuZFNEZQC8 AAAAAAgAWYJSwmNkYGkQYWBgMGCAAB8gZmQFM1lFgcRr1UqdyY+TPJTjk7NfM+OW Y2RiYGBiKGBgAUtLMPxnlGcAiYHUKgAJBTBbBCLOCBEXAlMqEDE8doLMW8kghGKe IpANAFVUDQAH3wTNQt8EzUKd7cxClVZdb9s2FH1WgPyH25dCWlPV6V66ChmQdsEw LEAGu0U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