Buffo Posted January 17, 2007 Share Posted January 17, 2007 Hello!I am new to TCp connections and made my first attempts but something went wrong. Perhaps you can help me.It's only for a test. Client and server are running on the same machine and the only thing that should happen is that filled in text in client app should be sent to the server app as long as the string "quit" is not used.Have a look what I have done so far:ServerTCPStartup() $iMainSocket = TCPListen("127.0.0.1", 10372) If $iMainSocket = -1 Then Exit While 1 $iConnectedSocket = TCPAccept($iMainSocket) If $iConnectedSocket <> -1 Then $sReceived = TCPRecv($iConnectedSocket, 1024) If $sReceived = "" Then ExitLoop Else MsgBox(0, "Received", $sReceived) EndIf EndIf WEnd TCPShutdown()ClientDo $sInput = Input() Sleep(100) Until $sInput = "quit" Func Input() TCPStartup() $iConnectedSocket = TCPConnect("127.0.0.1", 10372) If $iConnectedSocket = -1 Then Exit $sData = Inputbox("Input", "String to send") TCPSend($iConnectedSocket, $sData) TCPShutdown() Return $sData EndFuncI thin the problem will be the While...Wend part on server side, but I don't have an idea. I hope you can help Thx in advance Regards,Buffo Link to comment Share on other sites More sharing options...
jvanegmond Posted January 17, 2007 Share Posted January 17, 2007 Here's your server revised. This is how I would do it, not saying that this is the only way to go. Dim $iConnectedSocket = -1 TCPStartup() $iMainSocket = TCPListen(@IPAddress1, 10372) If @error Then MsgBox(0, "", "Server could not be started on " & @IPAddress1 & ":" & "10372") Exit EndIf While 1 $iNewSocket = TCPAccept($iMainSocket) If $iNewSocket <> -1 Then $iConnectedSocket = $iNewSocket EndIf If $iConnectedSocket <> -1 Then $sReceived = TCPRecv($iConnectedSocket,1024) ;If @error Then ExitLoop ;uncomment this if you want it to quit after the client has disconnected If $sReceived <> "" Then MsgBox(0,"Received data", $sReceived) EndIf EndIf WEnd TCPShutdown() github.com/jvanegmond Link to comment Share on other sites More sharing options...
Buffo Posted January 17, 2007 Author Share Posted January 17, 2007 @Manadar: Thx a lot for your reply This works already a little bit The problem here is that the first given input will be displayed but after that the MsgBox in server keeps quiet. That can that be? Regards, Buffo Link to comment Share on other sites More sharing options...
jvanegmond Posted January 17, 2007 Share Posted January 17, 2007 @Manadar: Thx a lot for your reply This works already a little bit The problem here is that the first given input will be displayed but after that the MsgBox in server keeps quiet.That can that be?Regards,BuffoMsgBox is a so called 'Blocking function'. Whenever AutoIt displays a MsgBox it is unabled to perform any other commands. Try to close the MsgBox and resend. Alternately, use a ToolTip to display information from the server. ToolTip is not a blocking function. github.com/jvanegmond 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