I have a small, probably poorly coded telnet server. You connect, it shows some ansci art and then you just type to chat and it displays your ip address following your message. The problem I'm having is implementing a backspace. When you use backspace in command prompt it simply just moves the cursor back without deleting the character.

I'm using network stream streamreader and streamwriter for the streams. Is there something better than that I should be aware of?

I've pulled some code from a visual basic 6 telnet application and its for a backspace key. My vb is poor now having swapped over to c#.net a long time ago so I don't understand it. Maybe someone just translating it might help me:

DataVal = Asc(DataChar)
DataValSet = ""
For t% = 1 To Len(DataChar)
    DataValSet = DataValSet + Str$(Asc(Mid$(DataChar, t%, 1)))
Next t%
If (DataVal = 8 Or DataVal = 127) Then
    If Len(LineBuffer(ConnID)) > 0 Then
        'echo it back
        If UserData(ConnID, 7) <> "1" Then SocketPlayerEcho ConnID, DataChar
        LineBuffer(ConnID) = Left$(LineBuffer(ConnID), Len(LineBuffer(ConnID)) - 1)
       If UserData(ConnID, 7) <> "1" Then SocketPlayerEcho ConnID, " "
      If UserData(ConnID, 7) <> "1" Then SocketPlayerEcho ConnID, DataChar
    End If

I no the Dataval = 8 is refering to the backspace key but thats it. Can someone please help me ouT!

I dont think that vb would compile. Each if is lacking an endif, which makes reading it pretty difficult. Also, i have no idea what linebuffer is or ConnID - I'm assuming ConnID is a reference to the connection socket, and that linebuffer is a buffer that is added to each time a key is pressed, so LineBuffer(ConnID) = Left$(LineBuffer(ConnID), Len(LineBuffer(ConnID)) - 1) would mean: set the line buffer to whatever it was minus one character from the right (due to a backspace).

I would I make a connection like that with c#. Using stream reader the line isn't read until you push enter.

This article has been dead for over six months. Start a new discussion instead.