Jump to content

Limitations in TCPsend?


ParoXsitiC
 Share

Recommended Posts

I am trying to make a client gather up all their processes and windows in a variable called $List. As you can guess the list will be very long. The I send the whole list to my computer using TCPSend.

;CHECK FOR PROCESSES AND WINDOWS
;-----------------------------------
    If StringLeft($CMD, 7) = "//CHECK" Then 
        $Process = ProcessList()
        $Windows = WinList()
        $List = ""
        
        For $i = 1 to $Process[0][0]
         $List = $List & $i & ". " & "Process = " & $Process[$i][0] & @LF
        Next
     
        $List = $List & "*"
        
        For $i = 1 to $Windows[0][0]
          If $Windows[$i][0] <> "" Then
              $List = $List & $i & ". " &  "Window =   " & $Windows[$i][0] & @LF
          EndIf
        Next
      TCPSend($socket, "//PROCESS" & $List)
    EndIf

On the server end I have a type of "Process" Function which checks to see if what they are sending me starts with a // or not. If it does start with a // then the server knows its a command and its not suppose to echo anything as chat.

Func Process($Data, $Author)
    If StringLeft($Data, 2) = "//" Then
        UserCmd($Data, $Author)
    Else
        Message($Data, $Author)
    EndIf
EndFunc

Then according to rather what they are sending is a command or not goes into different functions. For this example they are sending me something that starts with //PROCESS which tells the server its the list of their processes and windows. So it should theretically all goto the UserCMD Function.

Func Message($MSG, $Author)
        For $num = 1 to $ConnectedSocket[0][0]
            TCPSend($ConnectedSocket[0][$num], $ConnectedSocket[1][$Author] & ": "& $MSG)
        Next
EndFunc
    
    
Func UserCmd($CMD, $Author)
    If StringLeft($CMD, 9) = "//PROCESS" Then 
        $CMD = StringTrimLeft($CMD, 9)
        $CMDArray = StringSplit($CMD,"*")
        MsgBox(0,"Processes",$CMDArray[1])
        MsgBox(0,"Windows",$CMDArray[2])
    EndIf
EndFunc

What ends up happening is that everything works good for a amount of data. I dont know what the cut apparentlly is. But when echoing all data that gets that goes through the Process function. What happens is that the client sends X amount of data. This data starts with //PROCESS so everythign works out good and i gets the MSGBOXes of the proccess and windows. It appears the data gets cut off however, and then ANOTHER TCPSend function is activated from the user to send the rest of the data was cut off. This data however doess not contain a //PROCESS so gets processed as CHat, and not a command.

What appears to be the problem is that I am trying to send too much data through TCPSend function and it is cutting the data up into two sends. Is there a better way around this or a more efficent way to send the and display the wanted info?

UPDATE:

After more testing I figured out that the cut if is exactly after 4KB or 4096 bytes. Then it sends the remaining data as another TCPsend.

Is there a way to get around this or should I just do a TCPSend command for process and windows seperately?

Edited by ParoXsitiC
Link to comment
Share on other sites

Okay. I tried chaning my Recv to alot of diff. things and I seem to be getting wierd results. It seems to skip from 4KB cut off limit to 8KB cut off limit, and im using this for recv:

$ret = TCPRecv($ConnectedSocket[0][$n], 5000000)

There shouldnt even be a limit for the recieving in. I also just tested it seeing if I just put it at 10. It doesnt make the client send alot of TCPsend's...Instead it just only accepts the first 10 things of data. Thus problem I am having has nothing to do with recieveing but sending.

Link to comment
Share on other sites

So i have been messing around with TCPsend and I realized if you call alot of TCPsend right after eachother they clump together and send as one big one. For example when sending around 10KB of data, around 250 TCPSends it ended up clumping them to about 3 big TCPsends.

Anyways, So I thought I fixed the problem. Instead of displaying them in a msgbox I was going to write each TCPsend clump to a file. The file will be in the script directory and have the users name on it followed by data.

When testing it on myself it worked like a charm. (Probably because its super fast/easy to send packets to myself) When I invited a friend in and I ran everything it did something I didnt think it was doing. At first i thought it ran out of room to send the rest so it would just send the remainer, but in the script now I named eached of them 1, 2, 3...etc. What seem to happen was that I receieved 1-200 on the list...200-230 got sent to the chat and 230-250 went to the list.

My first guess was that when you send alot of TCP packets right after another they get pushed together untill a certain size, then they send...then it takes it where it left to work on another clump. I got this conclusion because all my TCPsend commands started with "//PROCESS" but i was getting cut off inbetween messages.

I decided to put sleeps in so that every TCP packet was sent one by one but I still came up with the same error.

An example of what the data should look like:

//PROCESS 1. Some data here
//PROCESS 2. Some data here
//PROCESS 3. Some data here
//PROCESS 4. Some data here
...

Here is how it came out:

//PROCESS 1. Some data here
//PROCESS 2. So
//PROCESS 4. Some data here

The "missing" part was still sent, but since it didnt start with //, it was read into chat:

me data here
//PROCESS 3. Some data here

I am not sure what is going on, infact I am not sure if I even did a good job of explaining what was happening. Therefore I am attaching all 3 AU3 scripts: the server, the client and the adminclient.

Link to comment
Share on other sites

For those who want what I did:

If StringLeft($CMD, 14) = "//STARTPROCESS" Then
            $filename = @ScriptDir&"\Data.txt"
            $file = FileOpen($filename, 1)
            While 1
                $P = TCPRecv($Socket[0][$Author], 512)
                If $P <> "" Then
                    FileWrite($file, $P)
                    If StringInStr($P,"//ENDPROCESS") Then ExitLoop
                EndIf
            Wend
            FileClose($file)
            MsgBox(0,"Done.","Recieved Data")
EndIf
Edited by ParoXsitiC
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...