Hubert24 Posted October 14, 2012 Share Posted October 14, 2012 Hi everyone, please can someone help me out, i am trying to open, connect, send, receive, and close a socket connected to a existing server through TCP. Here attached is my code, but it is not working. I can see my sent message nor received the meassage. Please help! Thankstcp-test.au3 Link to comment Share on other sites More sharing options...
caleb41610 Posted October 14, 2012 Share Posted October 14, 2012 Looks to me like you should start with something more basic. You're using TCPSend 10 times per second, sending the same message. I doubt that is your goal. Search for some basic client/server scripts here on the forum and read the help file a little more thoroughly. Multi-Connection TCP Server Link to comment Share on other sites More sharing options...
Hubert24 Posted October 17, 2012 Author Share Posted October 17, 2012 thanks for your reaction, please can you help me search for one basic client/server script, because i can't find any. My server and client are two different computers but connected on the small local network. Thanks for your solution in advance. Regards Link to comment Share on other sites More sharing options...
bogQ Posted October 17, 2012 Share Posted October 17, 2012 look in my signature Hubert24 1 TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Link to comment Share on other sites More sharing options...
FireFox Posted October 17, 2012 Share Posted October 17, 2012 This topic is a joke, like those who don't take the time to make a forum search Link to comment Share on other sites More sharing options...
kudrow Posted October 17, 2012 Share Posted October 17, 2012 This topic is a joke, like those who don't take the time to make a forum search Agreed! I found a great example in the help file alone. Start in the help file. Get that working before you change anything about it so you know your communicating successfully. If your trying to communicate over the network you need to open up ports on your router as well as windows firewall. Link to comment Share on other sites More sharing options...
Hubert24 Posted October 19, 2012 Author Share Posted October 19, 2012 Hi all,i know it might sought like a joke to some of you, but know i am just a beginner please.Here is my code, i can send but cannot receive anything, by the way bogQ thanks i have gone through your signature.;CLIENT!!!!!!!! Start SERVER First... dummy!!Local $g_IP = "190.16.7.185"Local $socketLocal $recvLocal $statusLocal $ConnectedSocketLocal $szIP_Accepted; Start The TCP ServicesTCPStartup(); Attempt to connect to SERVER at its IP and PORT X$socket = TCPConnect($g_IP, 50000)MsgBox (0, "Socket", "Socket: " &$socket)If $socket = -1 Then Exit ;Initialize a variable to represent a connection > -1While (1) $status = TCPSend($socket, "StringToBinary(ap_ca_version)") If $status = 0 Then MsgBox(0, "ERROR", "Error while sending TCP message: " &@error) Else MsgBox(0, "Sent", "mgn sent is: " &$status) Exit EndIf Do $srcv = TCPRecv($socket, 2048) ; convert from UTF-8 to AutoIt native UTF-16 $recv = BinaryToString($recv, 4) MsgBox(0, "Received", "Message received: " &$recv) Until $recv <> "" ExitLoopWEndTCPCloseSocket ($socket)TCPShutdown()regards Link to comment Share on other sites More sharing options...
FireFox Posted October 19, 2012 Share Posted October 19, 2012 (edited) Hi, With your code (using local IP) you need two computers, If you want to test it on your own computer you have to use the loopback which is : 127.0.0.1 Br, FireFox. Edited October 19, 2012 by FireFox Link to comment Share on other sites More sharing options...
Hubert24 Posted October 19, 2012 Author Share Posted October 19, 2012 Hi, I have tried that with 127.0.0.1 but i could not still receive my sent message, I believe the problem has something to do with TCPRecv. My message box "MsgBox(0, "Received", "Message received: " &$recv) " is executed but contained no message inside. looking forward for your assistance. regards Hubert24 Link to comment Share on other sites More sharing options...
FireFox Posted October 19, 2012 Share Posted October 19, 2012 Take a look at my signature for Basic TCP. Br, FireFox. Link to comment Share on other sites More sharing options...
bogQ Posted October 19, 2012 Share Posted October 19, 2012 (edited) your code looks wrong in some casesyour dooing:$srcv = TCPRecv($socket, 2048)$recv = BinaryToString($recv, 4)so your requesting binary from notingsecond you're never gona exit loop cos $recv is always NULL and even if you do receive something your msgbox will display nothing. And your msgbox shud stand outside of Do Untill loop in this case and you shud use msgbox only if you intend to exiting from program after it.And your error check (If $status = 0 Then Else) for not error is using msgbox, that will pause the script, pls don't use msg boxes for something like that when your working with TCP, use ConsoleWrite while your testing, and gui commands if and when your finalizing your program.Edited your code so that you can try something like this;CLIENT!!!!!!!! Start SERVER First... dummy!! Local $g_IP = @IPAddress1 Local $socket Local $recv Local $status Local $ConnectedSocket Local $szIP_Accepted ; Start The TCP Services TCPStartup() ; Attempt to connect to SERVER at its IP and PORT X $socket = TCPConnect($g_IP, 1018) If $socket = -1 Then Exit ;Initialize a variable to represent a connection > -1 While 1 $status = TCPSend($socket, "StringToBinary(ap_ca_version)") If @error Then MsgBox(0, "ERROR", "Error while sending TCP message: " &@error) ExitLoop Else ; MsgBox(0, "Sent", "mgn sent is: " &$status) EndIf Do $recv = TCPRecv($socket, 2048) Until $recv $srcv = BinaryToString($recv, 4) MsgBox(0, "Received", "Message received: " &$srcv) ExitLoop WEnd TCPCloseSocket ($socket) TCPShutdown() Edited October 19, 2012 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Link to comment Share on other sites More sharing options...
Hubert24 Posted October 19, 2012 Author Share Posted October 19, 2012 Thanks a lot Br, FireFox. Infact you are very helpful. I could have a rest now. once more thank you. Please permit me ask this question, what if i have two computers, one is my server with IP address 192.168.1.1 and the other is my client with ip address 190.16.7.185. how can i send and receive via TCP? will be grateful for your help once again Link to comment Share on other sites More sharing options...
FireFox Posted October 19, 2012 Share Posted October 19, 2012 (edited) You're welcome Always the same rule (except for same computer test) : Local IP for the server (here 192.168.1.1) and server public IP for the client (available with _GetIP). But I doubt that the serv address is 192.168.1.1, because for me it's my box. (available with @IPAddress1) Br, FireFox. Edited October 19, 2012 by FireFox Link to comment Share on other sites More sharing options...
Hubert24 Posted October 19, 2012 Author Share Posted October 19, 2012 Thanks, i will try that next week, is weekend time. I wish you a nice weekend. Best regards Link to comment Share on other sites More sharing options...
Hubert24 Posted October 22, 2012 Author Share Posted October 22, 2012 Hi Br, FireFox, I have tried it the way you requested but it doesn't work. On same PC, I can use just the @IPAddress1 instead of 127.0.0.1 and it works perfectly, but if I try to use 2 computers, one with @IPAddress (server) and the other with _GetIP() (client), it doesn't work even if I try @IPAddress1 or _GetIP() on both computers it still does not work. Could you please look at it again? To make myself more clear, I have two computers, one is server and the other is client, how can i send in both directions via TCP sockets? I will be grateful to hear from you. Best regards Hubert Link to comment Share on other sites More sharing options...
caleb41610 Posted October 22, 2012 Share Posted October 22, 2012 Maybe you can modify this to your needs: I haven't taken the time to add comments.. but it has an example for sending messages back and forth. Multi-Connection TCP Server 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