yucatan Posted September 22, 2008 Share Posted September 22, 2008 hi i hav a server and a client when the client logs in to the server the server is waiting for the usernamer ofcourse but the problem is at the same time another client cannot login because he is waitingfor the data of the other client so then i can not log in so the piont is i cannot login with more client at the same time here is my server code somebody wanne take a look pleas thx alot expandcollapse popup; Server (Start first) #include <Array.au3> dim $socket dim $listen if $socket <> -1 then TCPStartup() $listen = TCPListen("127.0.0.1", 2111) $socket = TCPAccept($listen) Else sleep(1) EndIf main() dim $loggedin func main() while 1 ConsoleWrite("top part"& @CRLF) $result = "" $var = IniReadSection("C:\Temp\users.ini", "user") If @error Then MsgBox(4096, "", "Error occurred, probably no INI file.") Else For $i = 1 To $var[0][0] $result &= $var[$i][0]&"|" Next EndIf $data = StringTrimRight($result, 1) $socket = TCPAccept($listen) If $socket <> -1 Then ConsoleWrite("after top part"& @CRLF) Do Sleep(100) $temp = TCPRecv($socket, 256) Until $temp <> "" MsgBox(4096, "Test", $temp) $array = StringSplit($temp, "|") $var = IniRead("C:\temp\users.ini", "User", $array[1], "Not Found.") $mask = IniRead("C:\temp\users.ini", "privileges", $array[1], "0") If $array[2] == $var Then TCPSend($socket, "Connected%"& $mask&"%"&$data) $loggedin = True *this is not the fully code because i dont wanne share the fully program.* Link to comment Share on other sites More sharing options...
Andreik Posted September 22, 2008 Share Posted September 22, 2008 Try this: Global $CurrentSocket = 0 Global $ListenSocket Global $ConnectedSocket[16] $TCP = TCPStartup() If $TCP = 0 Then MsgBox(0, "Error", "Unable to startup TCP Services!") Exit EndIf $ListenSocket = TCPListen(@IPAddress1,1777,16) If $ListenSocket = -1 Then MsgBox(0, "ERROR", "Unable to start listening on port 1777") Exit EndIf While 1 $ConnectedSocket[$CurrentSocket] = TCPAccept($ListenSocket) If $ConnectedSocket[$CurrentSocket] <> -1 Then $CurrentSocket = $CurrentSocket + 1 EndIf For $INDEX = 0 To 15 If $ConnectedSocket[$INDEX] <> -1 Or $ConnectedSocket[$INDEX] <> "" Then $Recv = TCPRecv($ConnectedSocket[$INDEX],1024) If $Recv <> "" Then ... EndIf EndIf Next Sleep(20) WEnd When the words fail... music speaks. Link to comment Share on other sites More sharing options...
yucatan Posted February 9, 2009 Author Share Posted February 9, 2009 Try this: Global $CurrentSocket = 0 Global $ListenSocket Global $ConnectedSocket[16] $TCP = TCPStartup() If $TCP = 0 Then MsgBox(0, "Error", "Unable to startup TCP Services!") Exit EndIf $ListenSocket = TCPListen(@IPAddress1,1777,16) If $ListenSocket = -1 Then MsgBox(0, "ERROR", "Unable to start listening on port 1777") Exit EndIf While 1 $ConnectedSocket[$CurrentSocket] = TCPAccept($ListenSocket) If $ConnectedSocket[$CurrentSocket] <> -1 Then $CurrentSocket = $CurrentSocket + 1 EndIf For $INDEX = 0 To 15 If $ConnectedSocket[$INDEX] <> -1 Or $ConnectedSocket[$INDEX] <> "" Then $Recv = TCPRecv($ConnectedSocket[$INDEX],1024) If $Recv <> "" Then ... EndIf EndIf Next Sleep(20) WEnd andriek i have a question is it possble to check if the server if full this server acept connection up to 15 but when the 16 connection is opend is there a way i can send server is full ? that the person who connect gets a msgbox with Server is full try connecting later. ? Link to comment Share on other sites More sharing options...
Andreik Posted February 9, 2009 Share Posted February 9, 2009 Something like this? expandcollapse popupGlobal $MAX_CONNECTION = 4 Global $CurrentSocket Global $ListenSocket Global $ConnectedSocket[$MAX_CONNECTION+1] $TCP = TCPStartup() If $TCP = 0 Then MsgBox(0, "Error", "Unable to startup TCP Services!") Exit EndIf $ListenSocket = TCPListen(@IPAddress1,1777,$MAX_CONNECTION) If $ListenSocket = -1 Then MsgBox(0, "ERROR", "Unable to start listening on port 1777") Exit EndIf $CurrentSocket = GetFreeSocket() While 1 $ConnectedSocket[$CurrentSocket] = TCPAccept($ListenSocket) If $ConnectedSocket[$CurrentSocket] <> -1 Then $CurrentSocket = GetFreeSocket() EndIf If $CurrentSocket = "SERVER_FULL" Then Call("ServerError") For $INDEX = 0 To $MAX_CONNECTION If $ConnectedSocket[$INDEX] <> -1 Or $ConnectedSocket[$INDEX] <> "" Then $Recv = TCPRecv($ConnectedSocket[$INDEX],1024) If $Recv <> "" Then If $Recv = "EXIT" Then Call("Quit") If $Recv = "GET_SOCKET" Then TCPSend($ConnectedSocket[$INDEX],$CurrentSocket) EndIf EndIf Next Sleep(20) WEnd Func GetFreeSocket() $FREE = "SERVER_FULL" For $INDEX = $MAX_CONNECTION To 0 Step -1 If $ConnectedSocket[$INDEX] = -1 Or $ConnectedSocket[$INDEX] = "" Then $FREE = $INDEX Next Return $FREE EndFunc Func ServerError() TCPSend($ConnectedSocket[$MAX_CONNECTION],"The server is full. Please try again later") TCPCloseSocket($ConnectedSocket[$MAX_CONNECTION]) EndFunc Func Quit() TCPCloseSocket($ListenSocket) TCPShutdown() Exit EndFunc When the words fail... music speaks. Link to comment Share on other sites More sharing options...
yucatan Posted February 9, 2009 Author Share Posted February 9, 2009 Something like this? expandcollapse popupGlobal $MAX_CONNECTION = 4 Global $CurrentSocket Global $ListenSocket Global $ConnectedSocket[$MAX_CONNECTION+1] $TCP = TCPStartup() If $TCP = 0 Then MsgBox(0, "Error", "Unable to startup TCP Services!") Exit EndIf $ListenSocket = TCPListen(@IPAddress1,1777,$MAX_CONNECTION) If $ListenSocket = -1 Then MsgBox(0, "ERROR", "Unable to start listening on port 1777") Exit EndIf $CurrentSocket = GetFreeSocket() While 1 $ConnectedSocket[$CurrentSocket] = TCPAccept($ListenSocket) If $ConnectedSocket[$CurrentSocket] <> -1 Then $CurrentSocket = GetFreeSocket() EndIf If $CurrentSocket = "SERVER_FULL" Then Call("ServerError") For $INDEX = 0 To $MAX_CONNECTION If $ConnectedSocket[$INDEX] <> -1 Or $ConnectedSocket[$INDEX] <> "" Then $Recv = TCPRecv($ConnectedSocket[$INDEX],1024) If $Recv <> "" Then If $Recv = "EXIT" Then Call("Quit") If $Recv = "GET_SOCKET" Then TCPSend($ConnectedSocket[$INDEX],$CurrentSocket) EndIf EndIf Next Sleep(20) WEnd Func GetFreeSocket() $FREE = "SERVER_FULL" For $INDEX = $MAX_CONNECTION To 0 Step -1 If $ConnectedSocket[$INDEX] = -1 Or $ConnectedSocket[$INDEX] = "" Then $FREE = $INDEX Next Return $FREE EndFunc Func ServerError() TCPSend($ConnectedSocket[$MAX_CONNECTION],"The server is full. Please try again later") TCPCloseSocket($ConnectedSocket[$MAX_CONNECTION]) EndFunc Func Quit() TCPCloseSocket($ListenSocket) TCPShutdown() Exit EndFunc sorry i dont fully understand how u should use this script.. Link to comment Share on other sites More sharing options...
Andreik Posted February 9, 2009 Share Posted February 9, 2009 sorry i dont fully understand how u should use this script.. It`s the same script. Just change $MAX_CONNECTION with another number (maximum connections). What client you use to connect to server? When the words fail... music speaks. Link to comment Share on other sites More sharing options...
CodyBarrett Posted February 10, 2009 Share Posted February 10, 2009 Why Dont YOu Have The Option Of Making The Server As Large As You Want? As In A Settings Option In The GUI, Or An INI Section? Its Just A Thought. [size="1"][font="Tahoma"][COMPLETED]-----[FAILED]-----[ONGOING]VolumeControl|Binary Converter|CPU Usage| Mouse Wrap |WinHide|Word Scrammbler|LOCKER|SCREEN FREEZE|Decisions Decisions|Version UDF|Recast Desktop Mask|TCP Multiclient EXAMPLE|BTCP|LANCR|UDP serverless|AIOCR|OECR|Recast Messenger|AU3C|Tik-Tak-Toe|Snakes & Ladders|BattleShips|TRON|SNAKE_____________________[u]I love the Helpfile it is my best friend.[/u][/font][/size] Link to comment Share on other sites More sharing options...
Andreik Posted February 10, 2009 Share Posted February 10, 2009 Why Dont YOu Have The Option Of Making The Server As Large As You Want? As In A Settings Option In The GUI, Or An INI Section? Its Just A Thought.Beacause it was an example. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
BrettF Posted February 10, 2009 Share Posted February 10, 2009 Why Dont YOu Have The Option Of Making The Server As Large As You Want? As In A Settings Option In The GUI, Or An INI Section? Its Just A Thought.And could you just not talk like that? It Is Really Annoying To Read Text Like This.So just don't.Cheers,Brett Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
yucatan Posted February 10, 2009 Author Share Posted February 10, 2009 Dear Andriek why is this code in the script ... why and when should $recv become get_socket do i need at the start of my client to add tcpsend get_socket or what can u pleas explane me that If $Recv = "EXIT" Then Call("Quit") If $Recv = "GET_SOCKET" Then TCPSend($ConnectedSocket[$INDEX],$Curr thx for all ur help ur realy a good guy i realy try to help us guys out i realy respect that! Link to comment Share on other sites More sharing options...
Andreik Posted February 11, 2009 Share Posted February 11, 2009 Dear Andriek why is this code in the script ... why and when should $recv become get_socket do i need at the start of my client to add tcpsend get_socket or what can u pleas explane me that If $Recv = "EXIT" Then Call("Quit") If $Recv = "GET_SOCKET" Then TCPSend($ConnectedSocket[$INDEX],$Curr thx for all ur help ur realy a good guy i realy try to help us guys out i realy respect that!It was only for test, you can remove this lines. If in your client you write GET_SOCKET you should receive the socket number. And if you write in you client EXIT and send this from server this will be closed. Hope you understand. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
yucatan Posted February 11, 2009 Author Share Posted February 11, 2009 It was only for test, you can remove this lines.If in your client you write GET_SOCKET you should receive the socket number.And if you write in you client EXIT and send this from server this will be closed.Hope you understand. haha yeah i get that thx for ur quick response and thx for the u realy give me self-confidence with that hahaha Link to comment Share on other sites More sharing options...
yucatan Posted February 12, 2009 Author Share Posted February 12, 2009 (edited) haha yeah i get that thx for ur quick response and thx for the u realy give me self-confidence with that hahaha hi Andriek i use this to let people log in to my server if $array[1] = "login" then If $array[3] == $var Then TCPSend($ConnectedSocket[$INDEX], "Connected%"& $mask&"%"&$data&"%"&$version) $loggedin = True Else TCPSend($ConnectedSocket[$INDEX], "login fails") EndIf endif the $array he read from a ini file there are the username and password stored how i can check if somebody is already logged in pleas some help or advice;) thx alot greetz yucatan Edited February 12, 2009 by yucatan Link to comment Share on other sites More sharing options...
JohnRichard Posted February 18, 2009 Share Posted February 18, 2009 Something like this? expandcollapse popupGlobal $MAX_CONNECTION = 4 Global $CurrentSocket Global $ListenSocket Global $ConnectedSocket[$MAX_CONNECTION+1] $TCP = TCPStartup() If $TCP = 0 Then MsgBox(0, "Error", "Unable to startup TCP Services!") Exit EndIf $ListenSocket = TCPListen(@IPAddress1,1777,$MAX_CONNECTION) If $ListenSocket = -1 Then MsgBox(0, "ERROR", "Unable to start listening on port 1777") Exit EndIf $CurrentSocket = GetFreeSocket() While 1 $ConnectedSocket[$CurrentSocket] = TCPAccept($ListenSocket) If $ConnectedSocket[$CurrentSocket] <> -1 Then $CurrentSocket = GetFreeSocket() EndIf If $CurrentSocket = "SERVER_FULL" Then Call("ServerError") For $INDEX = 0 To $MAX_CONNECTION If $ConnectedSocket[$INDEX] <> -1 Or $ConnectedSocket[$INDEX] <> "" Then $Recv = TCPRecv($ConnectedSocket[$INDEX],1024) If $Recv <> "" Then If $Recv = "EXIT" Then Call("Quit") If $Recv = "GET_SOCKET" Then TCPSend($ConnectedSocket[$INDEX],$CurrentSocket) EndIf EndIf Next Sleep(20) WEnd Func GetFreeSocket() $FREE = "SERVER_FULL" For $INDEX = $MAX_CONNECTION To 0 Step -1 If $ConnectedSocket[$INDEX] = -1 Or $ConnectedSocket[$INDEX] = "" Then $FREE = $INDEX Next Return $FREE EndFunc Func ServerError() TCPSend($ConnectedSocket[$MAX_CONNECTION],"The server is full. Please try again later") TCPCloseSocket($ConnectedSocket[$MAX_CONNECTION]) EndFunc Func Quit() TCPCloseSocket($ListenSocket) TCPShutdown() Exit EndFunc hi andreik. don't know i you receive my message. is it possible that client will connect to two servers? if one is down it will then look for another server that is available. hope you don't mind asking it with you. thank you. Link to comment Share on other sites More sharing options...
Andreik Posted February 18, 2009 Share Posted February 18, 2009 hi Andriek i use this to let people log in to my server if $array[1] = "login" then If $array[3] == $var Then TCPSend($ConnectedSocket[$INDEX], "Connected%"& $mask&"%"&$data&"%"&$version) $loggedin = True Else TCPSend($ConnectedSocket[$INDEX], "login fails") EndIf endif the $array he read from a ini file there are the username and password stored how i can check if somebody is already logged in pleas some help or advice;) thx alot greetz yucatanLook at this example. You can do something like in this example with $AUTH array When the words fail... music speaks. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now