AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Client & Server Script for TCP/IP Network Communication
Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8, 9  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
LYCOS17-NotLoggedIn
Guest





PostPosted: Thu May 22, 2008 4:00 am    Post subject: Reply with quote

Hi there. I am still having trouble.

So, you say if one of us runs the Server script configured like this below

(I am excerpting this from the original code in this thread)

Code:

; -------------------------------------------------
; ------------SERVERSCRIPT------------------
; -------------------------------------------------
; CONFIGURATION SECTION:

; Specify Your own Network's address and port.
Network_Address = 70.74.71.100
Network_Port = 8765



I am assuming from the comment on this code, I am to put my PUBLIC IP address in that Network_Address spot and a port I want to open.

And my friend runs the Client in another part of town,....

Code:

; -------------------------------------------------
;-----------CLIENTSCRIPT----------------------
; -------------------------------------------------
; CONFIGURATION SECTION:

; Specify address and port of the server.
Network_Address = 70.74.71.100
Network_Port = 8765


So, my buddy runs this part of the script... and that should have my PUBLIC IP and same port. ....and so then, upon him clicking CONNECT from the client script, it should reach my end, and connect to my server script?

Right? The problem I am facing is, when I run the Server script it just crashes. I am getting a bind() indicated Winsock error 10049 message. Same thing happens with him if he attempts to run the server script. However, I am not running nor my friend is running any firewalls and we are on the same ISP. Further, we can actually ping each other, and so from DOS when we PING each other we see data there at that level.... so there are no blocks in theory between us.

So what are we doing wrong? If I put something like 127.0.0.1 on the Server Script, it just sends messages to itself... that works.

..... Any ideas on what we could be doing wrong, and need to do to make this function over the Internet? Smile
Back to top
jmanx



Joined: 14 May 2008
Posts: 110

PostPosted: Thu May 22, 2008 4:50 am    Post subject: Reply with quote

either put 127.0.0.1 or your local IP address for the server
________
Iolite vaporizer


Last edited by jmanx on Thu Feb 10, 2011 8:32 pm; edited 1 time in total
Back to top
View user's profile Send private message
Zippo()
Guest





PostPosted: Thu May 22, 2008 7:10 am    Post subject: Reply with quote

Lexikos wrote:
It seems Zippo() skipped over half my post. Rolling Eyes

I'll try to make it more obvious next time Razz
Back to top
Lexikos



Joined: 17 Oct 2006
Posts: 7299
Location: Australia

PostPosted: Thu May 22, 2008 8:26 am    Post subject: Reply with quote

jmanx wrote:
either put 127.0.0.1 or your local IP address for the server
IIRC, the address in the server is the address of the local interface it binds to. If it binds to localhost (127.0.0.1), it will only accept connections from the local machine. Binding to 0.0.0.0 on the other hand, should allow connections from any network.
Back to top
View user's profile Send private message Visit poster's website
LYCOS17



Joined: 06 Feb 2008
Posts: 23
Location: Dallas

PostPosted: Thu May 22, 2008 3:56 pm    Post subject: Reply with quote

Thank you all! Now it works and I appreciate all the assistance.Very Happy
Back to top
View user's profile Send private message
U90
Guest





PostPosted: Thu May 22, 2008 11:12 pm    Post subject: Reply with quote

jmanx wrote:
It works now thanks.
Is there anyway to define when a certain address disconnects though?


Hmm... interesting approach. I was thinking more functionally, disconnecting from the current client connected to. (I.e. path > press CONNECT to connect > DISCONNECT to disconnect > and CONNECT to reconnect, ... ) How would this be done?
Back to top
LYCOS17



Joined: 06 Feb 2008
Posts: 23
Location: Dallas

PostPosted: Wed Jun 04, 2008 6:39 pm    Post subject: Reply with quote

I am wondering if anyone has had luck prusing the notions U90 presented above. I think it would be very useful to have this capability inside this TCP/IP function, for re-connection to server without reloading script Smile
Back to top
View user's profile Send private message
Guest






PostPosted: Sun Jul 06, 2008 5:44 pm    Post subject: Reply with quote

Can anyone see if this last requests is possible? It seems like a easy to do thing, but appears to be harder in execution than it seems. Confused
Back to top
Guest






PostPosted: Sat Jul 12, 2008 6:57 pm    Post subject: Reply with quote

please? Embarassed Crying or Very sad , i would very much like to make this work for a project if anyone knows! Very Happy


Zebra.
Back to top
IsNull



Joined: 10 May 2007
Posts: 593
Location: .switzerland

PostPosted: Thu Jan 15, 2009 8:19 am    Post subject: Reply with quote

I tryed to convert the ConnectToAddress(IPAddress, Port) to allow IPv6 adr. My problem is, I have to create a ipv6 adrsocket-struct.
Code:

/**************************************************************
connect to a IPv6
***************************************************************
*/
ConnectToAddress(IPAddress, Port){
    VarSetCapacity(wsaData, 32)  ; The struct is only about 14 in size, so 32 is conservative.
    ;ipv6 requires wsock 2.2
    WSOCK_20    := 0x0002 ;wsock 2.0
    WSOCK_22    := 0x0202 ;wsock 2.2
    result := DllCall("Ws2_32\WSAStartup", "UShort", 0x0202, "UInt", &wsaData) ; Request Winsock 2.0 (0x0202)
    ; Since WSAStartup() will likely be the first Winsock function called by this script,
    ; check ErrorLevel to see if the OS has Winsock 2.2 available:
    if (ErrorLevel){
        MsgBox WSAStartup() could not be called due to error %ErrorLevel%. Winsock 2.0 or higher is required.
        return -1
    }
    if (result){  ; Non-zero, which means it failed (most Winsock functions return 0 upon success).
        MsgBox % "WSAStartup() indicated Winsock error " . DllCall("Ws2_32\WSAGetLastError")
        return -1
    }

    AF_INET     := 2    ;for IPv4
    AF_INET6    := 23   ;for IPv6
    SOCK_STREAM := 1
    IPPROTO_TCP := 6
    socket := DllCall("Ws2_32\socket", "Int", AF_INET6, "Int", SOCK_STREAM, "Int", IPPROTO_TCP)
    if socket = -1
    {
        MsgBox % "socket() indicated Winsock error " . DllCall("Ws2_32\WSAGetLastError")
        return -1
    }

;...until here it works, but now I need the sockaddr_in6 Data-struct.

   
    /* struct def postet by Lexicos
typedef struct sockaddr_in6 {
    ADDRESS_FAMILY sin6_family; // AF_INET6.
    USHORT sin6_port;           // Transport level port number.
    ULONG  sin6_flowinfo;       // IPv6 flow information.
    IN6_ADDR sin6_addr;         // IPv6 address.
    union {
        ULONG sin6_scope_id;     // Set of interfaces for a scope.
        SCOPE_ID sin6_scope_struct;
    };
} SOCKADDR_IN6_LH, *PSOCKADDR_IN6_LH, FAR *LPSOCKADDR_IN6_LH;

typedef struct in6_addr {
    union {
        UCHAR       Byte[16];
        USHORT      Word[8];
    } u;
} IN6_ADDR, *PIN6_ADDR, FAR *LPIN6_ADDR;
   
    */


/* THIS IS IPv4 sockadr Struct
    ; Prepare for connection:
    SizeOfSocketAddress = 16
    VarSetCapacity(SocketAddress, SizeOfSocketAddress)
    InsertInteger(2, SocketAddress, 0, AF_INET)   ; sin_family
    InsertInteger(DllCall("Ws2_32\htons", "UShort", Port), SocketAddress, 2, 2)   ; sin_port
    InsertInteger(DllCall("Ws2_32\inet_addr", "Str", IPAddress), SocketAddress, 4, 4)   ; sin_addr.s_addr
*/

    ; Attempt connection:
    if DllCall("Ws2_32\connect", "UInt", socket, "UInt", &SocketAddress, "Int", SizeOfSocketAddress)
    {
        MsgBox % "connect() indicated Winsock error " . DllCall("Ws2_32\WSAGetLastError") . "?"
        return -1
    }
    return socket  ; Indicate success by returning a valid socket ID rather than -1.
}


I tried a bit, but I doesnt work. So, is there a struct-pro here, who can help me to create this ipv6-struct?

greets
IsNull


EDIT:
Maby this could be of interest:
http://msdn.microsoft.com/en-us/library/ms737937(VS.85).aspx

WSAConnectByName does include the following steps:

Quote:
Resolve a hostname to a set of IP addresses.
For each IP address:

Create a socket of the appropriate address family.
Attempts to connect to the remote IP address. If the connection was successful, it returns; otherwise the next remote IP address for the host is tried
..so we can maby make this client/server script more simple.
_________________
http://securityvision.ch
AHK 2D GAME ENGINE
Back to top
View user's profile Send private message Visit poster's website
mindlord



Joined: 09 Jan 2009
Posts: 6

PostPosted: Thu Jan 29, 2009 7:31 pm    Post subject: Reply with quote

When sending an Integer using this script is it actually sent as an integer or is it still just a string?
Back to top
View user's profile Send private message
Z_Gecko
Guest





PostPosted: Thu Jan 29, 2009 7:45 pm    Post subject: Reply with quote

a string
Back to top
mindlord



Joined: 09 Jan 2009
Posts: 6

PostPosted: Thu Jan 29, 2009 8:06 pm    Post subject: Reply with quote

Thanks, so no sense trying to optimize the traffic for compactness then.
Back to top
View user's profile Send private message
Sarah



Joined: 12 Jul 2007
Posts: 103
Location: Hawaii, USA

PostPosted: Sat Feb 14, 2009 9:43 am    Post subject: Reply with quote

Hello, I am wondering if someone can review ISNULL's post just above... and see what they think? I am interested.
Back to top
View user's profile Send private message
ahk newbie
Guest





PostPosted: Thu Mar 12, 2009 11:59 am    Post subject: problems by inter-script communication Reply with quote

Hello,

i will use this great script for inter-script communication, between java and autohotkey.
My idea is, to send an messages from java client to the server an the server answer to the java client.
So i simple modify the "ReceiveData(wParam, lParam)" funtion by adding the sendData funtion directly after
an incomming message arrived. (see code example) But the senddata command not fill the socket input stream in java. Sad
and java always waits for inncomming message from socketinputstream. In ZED's AHK Client script it works perfect.

The Message send from JAVA to the Server working without any problems and ZED's AHK-Server script recieved the data correctly.
But i have no idea, why my JAVA Client becomes no answer from the AHK-Server Script in the socket input stream.

Can anybody help me what can i do?
Must I convert the send data to an other send data variable or what is my misstake.

many thx for any ideas & greets
ahk newbie
Back to top
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8, 9  Next
Page 7 of 9

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group