AutoHotkey Community

It is currently May 27th, 2012, 10:53 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 131 posts ]  Go to page 1, 2, 3, 4, 5 ... 9  Next
Author Message
PostPosted: November 2nd, 2006, 4:00 pm 
Offline

Joined: September 23rd, 2006, 1:58 pm
Posts: 149
I managed to modify the Winlirc-Script
http://www.autohotkey.com/docs/scripts/WinLIRC.htm
with the help of this article: http://www.microsoft.com/germany/techne ... 00854.mspx
(sorry only German), and now i can proudly present:
TCP/IP Network Communication without extra Tools
Client- and Server-Script

Full 2-way communication between 2 Scripts only using DLL Calls of Ws2_32.dll (Winsock 2.0). No extra Tools or support-dlls needed, no Command Line. And it is possible to modify the server-script to handle more than one communication parallel.

The examples are very simple: a Textbox whose contents will be shown in a Tooltip on the remote-computer when pressing send button. (the client script has a connect-button in addition)

You will notice, that it took only 4 more DLL-Calls to make the Winlirc-Script into a general Client-Server-Script

Server

Code:
code removed due to protest.
http://www.autohotkey.com/forum/viewtopic.php?t=81795

[/b]


Last edited by Zed Gecko on January 28th, 2012, 3:03 am, edited 3 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 2nd, 2006, 4:38 pm 
GOSH! Das nenn ich beeindruckend :shock: Thx/Danke. :D


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 2nd, 2006, 4:54 pm 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
Wow! I didn't looked the code, but this sure have been asked many times!
If it works with both client and server on same computer, it can even be used for inter-script communication...

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 2nd, 2006, 5:39 pm 
Offline

Joined: September 23rd, 2006, 1:58 pm
Posts: 149
Yeah, and it was so close ^^

And it works with both client and server on the same computer.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 3rd, 2006, 12:28 am 
Offline

Joined: December 18th, 2005, 5:40 pm
Posts: 234
Location: Italy - Galatro(RC)
very impressive

_________________
____________________
______________________
kiu - www.romeosa.com


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 3rd, 2006, 12:43 am 
Offline

Joined: October 17th, 2006, 2:45 am
Posts: 23
Can you guide me in what changes need to be made to allow more then one connection to the server.

I would like multple client to connect to the server. When the server sends a message, I would like it sent to all clients.

When I connect a 2nd client to the server I get the error: connect() indicated Winsock error 0?

-which is funny because 0 means no error right?

Great work,
Matt


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 3rd, 2006, 9:43 am 
Offline

Joined: September 23rd, 2006, 1:58 pm
Posts: 149
First of all i want to state that i´m a noob to this, so this may be (partially) wrong and i might use wrong words.

To make a Server for more than one connection,
you should seperate the operations for the different sockets,
because right now the script does this:

1. the server initalizes the winsock with
Code:
WSAStartup


2. the creates a socket (the first socket of two) with
Code:
socket


3. the server binds itself to the socket and tells the
socket that it is listening with
Code:
bind
listen


4. the server tells the socket to send WindowsMessages on Received Data
(this is optional, because you can just question the socket with a
looped receive instead) with
Code:
WSAAsyncSelect


5. the server accepts an incoming connection blind
(without knowing if there really one) in a loop
until it returnes a valid socket ID with
Code:
accept

if accept returns a valid socket id, it means that
there realy was an incomming connection, that could be accepted, and
winsock has automacaly created a new socket with the
same properties as the first socket
(not only same type and ip, but also
if it is sending Windows Messages when WSAAsyncSelect was called)
[My Loop stopps after one accepted connection]

6. the server sends and receives data through the new socket with
Code:
send
recv

The send and receive command have to work with the new socket,
that was created by winsock, because the incoming connection will
talk to this socket and not the one that was monitoring for the incoming connection.

To handle more than one connection you will first have make the
accept loop (Nr.6)keep going after the first accepted connection.
You will hopefully get a socket for each incoming connection.

The tricky part will be to handle all the sockets. The MSDN recommends
to start a new thread for each socket.
(That would probably mean to start
another script with the socket id as commandline parameter,
or using WindowsMessages for the transfer of the socket id.
The new script will maybe need to init Winsock itself, but i don´t know?

If you only have limited demands, you can also use the function
that is called by the WindowsMessages received from the socket,
to not only receive but also send some data, but i´m not shure if there
will be "collision" problems.

Or you don´t tell the winsock to send WindowsMessages at all(Nr.4),
and question and respond to all the open sockets
one after another in a loop.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 3rd, 2006, 9:52 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
beutiful

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 3rd, 2006, 3:00 pm 
Offline

Joined: August 8th, 2006, 3:55 pm
Posts: 49
copy - paste - network adresses specified - run without error <== great, Zed Gecko


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 7th, 2006, 6:33 pm 
Offline

Joined: October 17th, 2006, 2:45 am
Posts: 23
Here is my ~solution~ to sending one message to multiple clients.


I changed this
Code:
Loop ; Wait for incomming connections
{
; accept requests that are in the pipeline of the socket   
   conectioncheck := DllCall("Ws2_32\accept", "UInt", socket, "UInt", &SocketAddress, "Int", SizeOfSocketAddress)
; Ws2_22/accept returns the new Connection-Socket if a connection request was in the pipeline
; on failure it returns an negative value
    if conectioncheck > 1
    {
       MsgBox Incoming connection accepted
       break   
   }
    sleep 500 ; wait half 1 second then accept again
}   
return


to this...
Code:
i=1
Loop ; Wait for incomming connections
{
; accept requests that are in the pipeline of the socket   
   conectioncheck%i% := DllCall("Ws2_32\accept", "UInt", socket, "UInt", &SocketAddress, "Int", SizeOfSocketAddress)
; Ws2_22/accept returns the new Connection-Socket if a connection request was in the pipeline
; on failure it returns an negative value
    if conectioncheck%i% > 1
    {
       ;MsgBox Incoming connection accepted
       i++
    }       
    sleep 500 ; wait half 1 second then accept again
}   
return


and updated send via net to this...
Code:
SendviaNet:
Gui, Submit, NoHide
Loop %i% {
   SendData(conectioncheck%A_Index%,SendText)
}
SentText =
return


I know, I know... but it works!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 13th, 2006, 7:19 pm 
Offline

Joined: September 23rd, 2006, 1:58 pm
Posts: 149
Quote:
Your script is working beautifully. It's very fast. < 10 ms, I have a small problem, when I close any of the connected clients, it kills the server also. Any idea why this is and how I can stop it?


This is the default behaivour from the WinLirc Script, which i didn´t change,
also the server will kill the clients.

to change this, in the serverscript you got to get rid of these lines:
Code:
if ReceivedDataLength = 0  ; The connection was gracefully closed,
   ExitApp  ; The OnExit routine will call WSACleanup() for us.

in the ReciverData function.

and you better change the WindowsMessages the socket sends
from
Code:
if DllCall("Ws2_32\WSAAsyncSelect", "UInt", socket, "UInt", ScriptMainWindowId, "UInt", NotificationMsg, "Int", FD_READ|FD_CLOSE|FD_CONNECT)

to
Code:
if DllCall("Ws2_32\WSAAsyncSelect", "UInt", socket, "UInt", ScriptMainWindowId, "UInt", NotificationMsg, "Int", FD_READ|FD_CONNECT)


and you better create a new WindowsMessage Handler for the FD_CLOSE Message, like:
Code:
NotificationMsg2 = 0x6666
OnMessage(NotificationMsg2, "ConnectionClosed")

Code:
if DllCall("Ws2_32\WSAAsyncSelect", "UInt", socket, "UInt", ScriptMainWindowId, "UInt", NotificationMsg2, "Int", FD_CLOSE)

Code:
ConnectionClosed(wParam, lParam)
{
}



but this is all guessing, so please try out and report in forum please.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: like key2Lan
PostPosted: November 14th, 2006, 3:28 pm 
Can this code be changed so i can send keystrokes just like i am on the other PC? (1 server 3 clients?)

just like key2lan does ?

http://www.wideview.it/key2lan.htm

Flyer


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 14th, 2006, 6:47 pm 
Offline

Joined: September 23rd, 2006, 1:58 pm
Posts: 149
Well, since autohotkey can send Keystrokes, using "send" and other commands. It is possible to send Keystrokes over the net with this script.
Just exchange the "Tooltip" command with a "send" command for a start


Report this post
Top
 Profile  
Reply with quote  
 Post subject: problem solved
PostPosted: November 14th, 2006, 7:07 pm 
Offline

Joined: October 17th, 2006, 2:45 am
Posts: 23
Thanks Zed. Taking out the FD_CLOSE was enough to stop the client from closing the server. For my purposes (only 3 users) that was enough. I am ok with the server killing the clients because its good to know that they need to be reconnected. Thank you for the hardwork and ongoing support.

Matt


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 15th, 2006, 8:25 am 
Zed Gecko wrote:
Well, since autohotkey can send Keystrokes, using "send" and other commands. It is possible to send Keystrokes over the net with this script.
Just exchange the "Tooltip" command with a "send" command for a start


Great !!!!

Now I need to change this script for my FS.

Thanks a lot Zed !!!


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 131 posts ]  Go to page 1, 2, 3, 4, 5 ... 9  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 51 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group