Echo server: Difference between revisions
Content added Content deleted
(added factor example) |
m (→{{header|AutoHotkey}}: format to improve) |
||
Line 6: | Line 6: | ||
The implementation must not stop responding to other clients if one client sends a partial line or stops reading responses. |
The implementation must not stop responding to other clients if one client sends a partial line or stops reading responses. |
||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
⚫ | |||
{{lines_too_long}} |
|||
⚫ | |||
[http://www.autohotkey.com/forum/topic13829.html script] by zed gecko. |
[http://www.autohotkey.com/forum/topic13829.html script] by zed gecko. |
||
<lang AutoHotkey>#SingleInstance Force |
<lang AutoHotkey>#SingleInstance Force |
||
Line 42: | Line 41: | ||
"UInt", ScriptMainWindowId, "UInt", ExitMsg, "Int", FD_CLOSE) |
"UInt", ScriptMainWindowId, "UInt", ExitMsg, "Int", FD_CLOSE) |
||
{ |
{ |
||
msgbox, closed |
msgbox, closed |
||
} |
} |
||
if DllCall("Ws2_32\WSAAsyncSelect", "UInt", socket, |
if DllCall("Ws2_32\WSAAsyncSelect", "UInt", socket, |
||
"UInt", ScriptMainWindowId, "UInt", NotificationMsg, "Int", |
"UInt", ScriptMainWindowId, "UInt", NotificationMsg, "Int", |
||
FD_READ|FD_CONNECT) |
|||
{ |
{ |
||
MsgBox % "WSAAsyncSelect() indicated Winsock error " |
MsgBox % "WSAAsyncSelect() indicated Winsock error " |
||
DllCall("Ws2_32\ |
. DllCall("Ws2_32\WSAGetLastError") |
||
DllCall("Ws2_32\WSAAsyncSelect", "UInt", socket, |
|||
"UInt", ScriptMainWindowId, "UInt", ExitMsg, "Int", FD_CLOSE) |
"UInt", ScriptMainWindowId, "UInt", ExitMsg, "Int", FD_CLOSE) |
||
ExitApp |
ExitApp |
||
} |
} |
||
Line 63: | Line 64: | ||
if ErrorLevel |
if ErrorLevel |
||
{ |
{ |
||
MsgBox WSAStartup() could not be called due to error %ErrorLevel%. |
MsgBox % "WSAStartup() could not be called due to error %ErrorLevel%. " |
||
. "Winsock 2.0 or higher is required." |
|||
return -1 |
return -1 |
||
} |
} |
||
if result |
if result |
||
{ |
{ |
||
MsgBox % "WSAStartup() indicated Winsock error " |
MsgBox % "WSAStartup() indicated Winsock error " |
||
. DllCall("Ws2_32\WSAGetLastError") |
|||
return -1 |
return -1 |
||
} |
} |
||
Line 78: | Line 81: | ||
if socket = -1 |
if socket = -1 |
||
{ |
{ |
||
MsgBox % "socket() indicated Winsock error " |
MsgBox % "socket() indicated Winsock error " |
||
. DllCall("Ws2_32\WSAGetLastError") |
|||
return -1 |
return -1 |
||
} |
} |
||
Line 85: | Line 89: | ||
InsertInteger(2, SocketAddress, 0, AF_INET) |
InsertInteger(2, SocketAddress, 0, AF_INET) |
||
InsertInteger(DllCall("Ws2_32\htons", "UShort", Port), SocketAddress, 2, 2) |
InsertInteger(DllCall("Ws2_32\htons", "UShort", Port), SocketAddress, 2, 2) |
||
InsertInteger(DllCall("Ws2_32\inet_addr", "Str", IPAddress), |
InsertInteger(DllCall("Ws2_32\inet_addr", "Str", IPAddress), |
||
SocketAddress, 4, 4) |
|||
if DllCall("Ws2_32\bind", "UInt", socket, |
if DllCall("Ws2_32\bind", "UInt", socket, |
||
"UInt", &SocketAddress, "Int", SizeOfSocketAddress) |
"UInt", &SocketAddress, "Int", SizeOfSocketAddress) |
||
{ |
{ |
||
MsgBox % "bind() indicated Winsock error |
MsgBox % "bind() indicated Winsock error " |
||
. DllCall("Ws2_32\WSAGetLastError") . "?" |
|||
return -1 |
return -1 |
||
} |
} |
||
if DllCall("Ws2_32\listen", "UInt", socket, "UInt", "SOMAXCONN") |
if DllCall("Ws2_32\listen", "UInt", socket, "UInt", "SOMAXCONN") |
||
{ |
{ |
||
MsgBox % "LISTEN() indicated Winsock error |
MsgBox % "LISTEN() indicated Winsock error " |
||
. DllCall("Ws2_32\WSAGetLastError") . "?" |
|||
return -1 |
return -1 |
||
} |
} |
||
Line 201: | Line 208: | ||
DllCall("Ws2_32\WSACleanup") |
DllCall("Ws2_32\WSACleanup") |
||
ExitApp</lang> |
ExitApp</lang> |
||
echoclient.ahk |
<tt>echoclient.ahk</tt> |
||
<lang AutoHotkey>#SingleInstance OFF |
<lang AutoHotkey>#SingleInstance OFF |
||
Network_Port = 12321 |
Network_Port = 12321 |
||
Line 236: | Line 243: | ||
FD_CLOSE = 32 |
FD_CLOSE = 32 |
||
if DllCall("Ws2_32\WSAAsyncSelect", "UInt", socket, |
if DllCall("Ws2_32\WSAAsyncSelect", "UInt", socket, |
||
"UInt", ScriptMainWindowId, "UInt", NotificationMsg, "Int", |
"UInt", ScriptMainWindowId, "UInt", NotificationMsg, "Int", |
||
FD_READ|FD_CLOSE) |
|||
{ |
{ |
||
MsgBox % "WSAAsyncSelect() indicated Winsock error " |
MsgBox % "WSAAsyncSelect() indicated Winsock error " |
||
. DllCall("Ws2_32\WSAGetLastError") |
|||
ExitApp |
ExitApp |
||
} |
} |
||
Line 251: | Line 260: | ||
if ErrorLevel |
if ErrorLevel |
||
{ |
{ |
||
MsgBox WSAStartup() could not be called due to error %ErrorLevel%. |
MsgBox % "WSAStartup() could not be called due to error %ErrorLevel%. " |
||
. "Winsock 2.0 or higher is required." |
|||
return -1 |
return -1 |
||
} |
} |
||
if result |
if result |
||
{ |
{ |
||
MsgBox % "WSAStartup() indicated Winsock error " |
MsgBox % "WSAStartup() indicated Winsock error " |
||
. DllCall("Ws2_32\WSAGetLastError") |
|||
return -1 |
return -1 |
||
} |
} |
||
Line 266: | Line 277: | ||
if socket = -1 |
if socket = -1 |
||
{ |
{ |
||
MsgBox % "socket() indicated Winsock error " |
MsgBox % "socket() indicated Winsock error " |
||
. DllCall("Ws2_32\WSAGetLastError") |
|||
return -1 |
return -1 |
||
} |
} |
||
Line 273: | Line 285: | ||
InsertInteger(2, SocketAddress, 0, AF_INET) |
InsertInteger(2, SocketAddress, 0, AF_INET) |
||
InsertInteger(DllCall("Ws2_32\htons", "UShort", Port), SocketAddress, 2, 2) |
InsertInteger(DllCall("Ws2_32\htons", "UShort", Port), SocketAddress, 2, 2) |
||
InsertInteger(DllCall("Ws2_32\inet_addr", "Str", IPAddress), |
InsertInteger(DllCall("Ws2_32\inet_addr", "Str", IPAddress), |
||
SocketAddress, 4, 4) |
|||
if DllCall("Ws2_32\connect", "UInt", socket, |
if DllCall("Ws2_32\connect", "UInt", socket, |
||
"UInt", &SocketAddress, "Int", SizeOfSocketAddress) |
"UInt", &SocketAddress, "Int", SizeOfSocketAddress) |
||
{ |
{ |
||
MsgBox % "connect() indicated Winsock error |
MsgBox % "connect() indicated Winsock error " |
||
. DllCall("Ws2_32\WSAGetLastError") . "?" |
|||
return -1 |
return -1 |
||
} |
} |