Jump to content

Help


Drew
 Share

Recommended Posts

How do you make it so that you can connect more than 1 client?

SERVER SIDE-

Dim $iMainSocket = 0
Dim $iConnectedSocket = -1
Dim $sData = ""
TCPStartup() 
$iMainSocket = TCPListen(@IPAddress1,7000)
$Log = FileExists( @DesktopDir&"\AntiHck\Log.ini")
;~ If $Log = 0 Then
;~  IniWrite( "Log.ini", "Logged-In Ip Addresses", ""&$Ip, "User")
;~ EndIf
    
While 1
    If $iConnectedSocket >= 0 Then 
        $sData = TCPRecv($iConnectedSocket,1024) 
        If @error Then 
            $iConnectedSocket = -1
            ConsoleWrite("Client has disconnected" & @CRLF)
        ElseIf $sData Then 
            MsgBox(0, "Message Received", $sData)
        EndIf
    Else 
        $iConnectedSocket = TCPAccept($iMainSocket) 
        If $iConnectedSocket >= 0 Then
            ConsoleWrite("Connection established" & @CRLF)
        EndIf
    EndIf
Wend

CLIENT CODE-

Dim $iMainSocket = 0
Dim $iConnectedSocket = -1
Dim $sData = ""
TCPStartup() 
$iMainSocket = TCPListen(@IPAddress1,7000)
$Log = FileExists( @DesktopDir&"\AntiHck\Log.ini")
;~ If $Log = 0 Then
;~  IniWrite( "Log.ini", "Logged-In Ip Addresses", ""&$Ip, "User")
;~ EndIf
    
While 1
    If $iConnectedSocket >= 0 Then 
        $sData = TCPRecv($iConnectedSocket,1024) 
        If @error Then 
            $iConnectedSocket = -1
            ConsoleWrite("Client has disconnected" & @CRLF)
        ElseIf $sData Then 
            MsgBox(0, "Message Received", $sData)
        EndIf
    Else 
        $iConnectedSocket = TCPAccept($iMainSocket) 
        If $iConnectedSocket >= 0 Then
            ConsoleWrite("Connection established" & @CRLF)
        EndIf
    EndIf
Wend

QUESTION:

How do you insert code where it still gives the autoit colors etc.?

Link to comment
Share on other sites

I'm new to all the Network programming commands... I understand arrays but I don't know how I would use them here.

Could you please give me an example?

Edited by Drew
Link to comment
Share on other sites

Alright , but how would I use this to accept connections and etc. though?

Oh and I'm not going to know whos connecting to the server side program. What would I enter into the array? Also, I'm unsure HOW MANY would need to connect to this. Ugh. I'm beginning to wonder if what I'm doings even possible.

Link to comment
Share on other sites

Could someone please give me an example? In my mind, I understand how that works... but I'm having trouble directing it to the program.

GREATLY appreciated as I've been trying and trying for some time now. Thanks,

Link to comment
Share on other sites

I'm going to bed , 1:30am , but I'm going to check this in the morning. Here's my situation.

I need to be able to allow more than 1 connection at a time. I was told to do this:

TCPAccept in your main loop.... if it succeeds... add that socket to an array... cycle through array for TCPRecv ... if TCPRecv fails... remove that socket from the array.

But I don't know how. If someone could PLEASE show me an example of what this person is telling me to do, I would be forever grateful.

Here are my updated scripts:

SERVER-SIDE

HotKeySet('!c', '_Test'); Set up an A hotkey to send the message

Dim $iMainSocket = 0
Dim $iConnectedSocket = -1
Dim $sData = ""
TCPStartup() 
$iMainSocket = TCPListen(@IPAddress1,7000)
;~ $Log = FileExists( @DesktopDir&"\AntiHck\Log.ini")
;~ If $Log = 0 Then
;~  IniWrite( "Log.ini", "Logged-In Ip Addresses", ""&$Ip, "User")
;~ EndIf
    
While 1
    If $iConnectedSocket >= 0 Then 
        $sData = TCPRecv($iConnectedSocket,1024) 
        If @error Then 
            $iConnectedSocket = -1
            ConsoleWrite("Client has disconnected" & @CRLF)
        ElseIf $sData Then 
            MsgBox(0, "Message Received", $sData)
        EndIf
    Else 
        $iConnectedSocket = TCPAccept($iMainSocket) 
        If $iConnectedSocket >= 0 Then
            ConsoleWrite("Connection established" & @CRLF)
        EndIf
    EndIf
Wend

Func _Test()
;$Ip = _GetIp()
    $Input = InputBox( "Message", "What message do you want to send the client?")
    TCPSend($iConnectedSocket, $Input); Send the data
EndFunc

CLIENT-SIDE

#include <INet.au3>

HotKeySet('!b', '_Test'); Set up an A hotkey to send the message
HotkeySet( '!a', '_Ip')
HotKeySet('{ESC}', '_Close'); Call a close function to close the script when someone presses escape
TCPStartup(); Initialize the TCP functions/library



$Socket = TCPConnect( "64.22.75.225", 7000); Connect to the server
If @error Then; If no connection is made, the server probably is not running, or another error occurs, give an error message to the user
    MsgBox(0x20,"Connection error", "Unable to connect.")
    Exit; Close the script
EndIf
$Ip = _GetIp()
TCPSend($Socket,"Hai there, "&$Ip& " ,has connected client-side to the Anti-Hack."); Just send a test message to make sure we can send some data. ( Not necessary )

While 1
        $sData = TCPRecv($Socket,1024) 
            If $sData Then 
            MsgBox(0, "Message Received", $sData)
        EndIf
WEnd

Func _Test()
;$Ip = _GetIp()
    $Input = InputBox( "Message", "What message do you want to send the server?")
    TCPSend($Socket, $Input); Send the data
EndFunc

Func _Ip()
    TcPSend($Socket, "The users IP is: "&$Ip)
EndFunc

Func _Close()
    TCPCloseSocket($Socket); Close the socket to the server
    TCPShutdown(); Deinitialize the TCP functions/library
    Exit; Close the script
EndFunc
Link to comment
Share on other sites

  • Moderators

Don't recreate new threads when it is the same topic just because you aren't getting answers fast enough. That's a quick way to get posting privileges taken away all together.

If you don't get an answer within 24 hours, then you can bump your thread... if you bump it 3 times, consider it dead...

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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...