Jump to content
Sign in to follow this  
mattmiester4

simple telnet server problem

Recommended Posts

mattmiester4

For the last couple days i have been working on a (so far) very basic telnet server. everything was going great until i ran into a little problem that has completly dumbfounded me. ok, so you can connect to the server, and the server can send data to the telnet window, but im not sure how to send data back to the server. as you can see in the src i wrote it so that when the server recieves data 'n' the comp beeps (an audible confirmation since i have no GUI yet). i was trying to write the code so that you type a command in telnet and press enter, then the server recieves the command. instead, for some reason it sends single keystrokes! how can i set this up so that i can for example, start it up and type "disconnect" & press enter and then the server recieve that cmd and does it. ive been looking in forums and at other example telnet servers but i just cannot seem to find the prob. much appreciated,

matthew

;----- 1/17/08 ----
;  Matthew Maughan
;  ssh server
;

#include <Array.au3>
#include <Color.au3>
#include <Constants.au3>
#include <Date.au3>
#include <File.au3>
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <IE.au3>
#include <Inet.au3>
#include <Math.au3>
#include <Memory.au3>
#include <Misc.au3>
#include <Process.au3>
#include <Sound.au3>
#include <Visa.au3>
#include <String.au3>

;----

HotKeySet("{End}", "Exxit")

;----

$PortMain = "225"
$MaxPConns = "100"
$CIP = "192.168.1.87"
$serverstatus = "0"; 1-connected 0-disconnected


;----

Dim $LSocket, $MSocket, $indatai

;----

service(1)
connlisten()

While 1
    
    $Msg = GUIGetMsg()
    
;conncheck()
;datarecv()
    
    if $serverstatus = 1 Then
        
        $indata = TCPRecv($MSocket, "2048")
            If $indata <> "" Then
                
                if $indata = "n" Then
                    Beep(1500, 50)
                ElseIf $indata = "m" Then
                ;...
                EndIf
            EndIf
    ElseIf $serverstatus = 0 Then
        connrecv()
    EndIf
        
    if $msg = $GUI_EVENT_CLOSE Then ExitLoop
    
WEnd


Func service($ss)    ; start/stop service
    if $ss = 1 Then
        TCPStartup()
        $ss = -1
    ElseIf $ss = 0 Then
        TCPShutdown()
        $ss = -1
    EndIf
EndFunc

Func exxit()     ; Hotkey close
    Exit
EndFunc

Func connlisten()    ; Listen for connections...
    $LSocket = TCPListen($CIP, $PortMain, $MaxPConns)
EndFunc

Func datarecv()  ; checks for recieved data
; currently placed into while statememt for debuging purposes...
EndFunc

Func dsend($outdata)                            ; datasend
    TCPSend($MSocket, $outdata & @CRLF)
    $outdata = -1
EndFunc 

Func connrecv()  ; checks for incomming connections
    $MSocket = TCPAccept($LSocket)
    if $MSocket >= 0  Then
        TCPSend($MSocket, "Connection Established; Connected to " & @IPAddress1 & @CRLF)
        dsend("" & @CRLF)
        
        $i = 1
        
        Do          
            dsend(FileReadLine("greeting.txt", $i))
            $i = $i + "1"
        Until $i = 12 + 1

        $serverstatus = "1"
    EndIf
EndFunc

func conntest()  ; for debugging
;
EndFunc

Func conncheck()     ; continuously checks connection for changes
    If $serverstatus = "1" Then
        if $MSocket = -1 Then
            MsgBox(0, "", "Connection to client lost. reseting connection...", "2")
            $serverstatus = "0"
            service(1)
        EndIf
    ElseIf $serverstatus = "0" Then
    ;
    EndIf
EndFunc

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×