tsolrm Posted January 8, 2012 Share Posted January 8, 2012 Is this possible? I've got a server that recieves information from many clients. However i don't know how to send some info back to clients if they request it. Because for them to connect to the server - they must know the ip but the server can't know the IPs of all the clients... thanks Link to comment Share on other sites More sharing options...
tsolrm Posted January 9, 2012 Author Share Posted January 9, 2012 (edited) I've had a go at this, the server accepts the clients message but when it sends one back through the open socket - the client doesn't recieve itServerTCPStartup()$TCPListen = TCPListen ("IP", port, 100)While 1;MsgBox (0, "LISTEN", $TCPListen)Do$TCPAccept = TCPAccept($TCPListen);MsgBox (0, "Accept", $TCPAccept)Until $TCPAccept <> -1Do$TCPRec = TCPRecv ($TCPAccept, 1000000)Until $TCPRec <> ""MsgBox (0, "test", $TCPRec)If $TCPRec = "test" ThenSleep (3000)TCPSend ($TCPListen, "CLIENT HAS RECIEVED THE MESSAGE")MsgBox (0, "test", @error)EndifWEndCLIENT$myip = "IP"TCPStartup ()$TCPConnect = TCPConnect ($myip, port)If $TCPConnect = -1 Then ExitTCPSend($TCPConnect, "test")While 1MsgBox (0, "Connection", $TCPConnect)Do$TCPAccept = TCPAccept($TCPConnect);MsgBox (0, "Accept", $TCPAccept)Until $TCPAccept <> -1Do$TCPRec = TCPRecv ($TCPAccept, 1000000)Until $TCPRec <> ""If not $TCPRec <> "" Then MsgBox (0, "test", $TCPRec)WEnd Edited January 9, 2012 by tsolrm Link to comment Share on other sites More sharing options...
bogQ Posted January 9, 2012 Share Posted January 9, 2012 see if this post can help you 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...
tsolrm Posted January 9, 2012 Author Share Posted January 9, 2012 see if this post can help youi would prefer something a bit more specific.anyone? Link to comment Share on other sites More sharing options...
bogQ Posted January 13, 2012 Share Posted January 13, 2012 (edited) soory i totaly forgot about this topic now to b more specific client side TCPStartup () $TCPConnect = TCPConnect ("127.0.0.1", 8080) If $TCPConnect = -1 Then Exit TCPSend($TCPConnect, "Hi server how are you") While 1 $TCPRec = TCPRecv ($TCPConnect, 1000000) If $TCPRec <> "" Then MsgBox (0, "Server sended me response", $TCPRec,9);9 seconds close, server have sleep 10 seconds before msgbox so its important to get that msg so that client can exit If $TCPRec = 'bye' Then Exit TCPSend($TCPConnect, "Yes i'm enjoying if ty for all the help") EndIf WEnd as you see client have 9 seconds displaying msgbox so that we can enshure that its ready when the next message arrive, i suggest using something that dont pause script so that you can display results, something like gui commands. You dont need TCPAccept in client, because its already connected to server so it will recive and send msgs based on TCPConnect server, TCPAccept is only server side to add one or more new connections and it dont have place in client script. and now the server, so i set this to resamble your trying to comunicate with server TCPStartup() $TCPListen = TCPListen ("127.0.0.1", 8080, 100) Do $TCPAccept = TCPAccept($TCPListen) Until $TCPAccept <> -1 TrayTip("Someone need to talk to me, i wonder who he is?!!!", "it must be my old friend with socket ID "&$TCPAccept, 5, 1) Do $TCPRec = TCPRecv ($TCPAccept, 1000000) Until $TCPRec <> "" MsgBox (0, "Client connected and tolded me", $TCPRec) TCPSend ($TCPAccept, "Hi client, i'm fine today, hope your enjoying yourself learning on autoitscript forum") ;~ Sleep (6000) Do $TCPRec = TCPRecv ($TCPAccept, 1000000) Until $TCPRec <> "" MsgBox (0, "Connected client tolded me", $TCPRec) TCPSend ($TCPAccept, "Glad to be of service, please feel free to ask if you have other questions, i'm sure that someone will jump into your help if he is familiar with codes that your using") Sleep (10000) TCPSend ($TCPAccept, "bye") as you can see server wait to someone connect to him and record his ID and after it its looking for msges from that connection (or connections) or can send msg before someone answer him, so basicly server sends and recive data based on ID that connected (so client connect to servers IP and sends and recive data from returned socket identifier) Adding array to $TCPAccept = TCPAccept($TCPListen) On server side that array will need loop while server is trying to get if there is any msg, that will enshure that you can record more than one socket identifier and put it into array. after that server will need to loop on all socket identifier array to recive msg from clients and correspond with them thats why i posted you link on previous post clients send data to server and server log them into GUI. after that server sends some data to client and client (or clients) display them as tooltip so im using on server TCPAccept($TCPListen) and record connecting ID to array and then i loop array to see did any ID from array sended me msg if it did i send msg to that array element that holds senders connecting ID. Edited January 13, 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...
Deathdn Posted January 13, 2020 Share Posted January 13, 2020 @bogQ, Your code is p2p, not client-server because your server have specific client ip address. 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