Jump to content

Echo server: Difference between revisions

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