ASocket_Initialize proto :DWORD, :DWORD
ASocket_Listen proto :DWORD
ASocket_MessageM proto
ASocket_MessageP proto :DWORD, :DWORD, :DWORD, :DWORD
ASocket_CallbackCode equ WM_USER + 1024
.data
; Window
ASocket_WindowStrc WNDCLASSEX <sizeof WNDCLASSEX, NULL, offset ASocket_MessageP, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL>
ASocket_Window_hWnd dd 0
ASocket_Window_Message MSG <>
ASocket_Window_Instance dd 0
; Socket
ASocket_Socket_WSAData WSADATA <>
ASocket_Socket_Listener dd 0
.code
ASocket_Initialize proc hInstance:DWORD, ClassName:DWORD
; Make a window for process message
mov eax, ClassName
mov ASocket_WindowStrc.lpszClassName, eax
mov eax, hInstance
mov ASocket_WindowStrc.hInstance, eax
invoke RegisterClassEx, addr ASocket_WindowStrc ; Register information
cmp eax, NULL
mov edx, 10000000h ; Error code - on RegisterClassEx
je PError_RC
invoke CreateWindowEx, NULL, ClassName, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, hInstance, NULL ; Create the window
cmp eax, NULL
mov edx, 10000001h ; Error code - on CreateWindowEx
je PError_RC
mov ASocket_Window_hWnd, eax
; Initialize socket
invoke WSAStartup, 202h, addr ASocket_Socket_WSAData
cmp eax, NULL
mov edx, 10000002h ; Error code - on WSAStartup
jne PError_RC
; NEED OTHER ROUTINES
; Start the thread of 'Message Manager'
invoke CreateThread, NULL, NULL, addr ASocket_MessageM, NULL, NULL, NULL
ret
PError_RC: ; Return error code
mov eax, edx
ret
ASocket_Initialize endp
ASocket_Listen proc lPort:DWORD
local RSocket_Addr:sockaddr_in
; Set up sockaddr_in structure
mov RSocket_Addr.sin_family, AF_INET ; TCP/IP
invoke htons, lPort
mov RSocket_Addr.sin_port, ax
mov RSocket_Addr.sin_addr, INADDR_ANY
; Make a socket
invoke socket, AF_INET, SOCK_STREAM, IPPROTO_TCP
cmp eax, INVALID_SOCKET
mov edx, 10000000h ; Error code - During make a socket
je PError_RC
mov ASocket_Socket_Listener, eax
; Bind the socket
invoke bind, ASocket_Socket_Listener, addr RSocket_Addr, sizeof sockaddr_in
cmp eax, SOCKET_ERROR
mov edx, 10000001h ; Error code - During bind
je PError_RC
; Listen the socket
invoke listen, ASocket_Socket_Listener, 200d
cmp eax, SOCKET_ERROR
mov edx, 10000002h ; Error code - During listen
je PError_RC
; ASYNCSELECT!
invoke WSAAsyncSelect, ASocket_Socket_Listener, ASocket_Window_hWnd, ASocket_CallbackCode, FD_ACCEPT
cmp eax, SOCKET_ERROR
mov edx, 10000003h ; Error code - During asynchronous select
je PError_RC
ret
PError_RC: ; Return error code
mov eax, edx
ret
ASocket_Listen endp
ASocket_MessageM proc ; Message Manager
@@:
invoke GetMessage, addr ASocket_Window_Message, NULL, NULL, NULL
test eax, eax
jz short @F
;invoke TranslateMessage, addr ASocket_Window_Message
invoke DispatchMessage, addr ASocket_Window_Message
jmp short @B
@@:
invoke Beep, 100, 100
ASocket_MessageM endp
ASocket_MessageP proc hWin:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD ; Message Processor
.if uMsg == ASocket_CallbackCode
invoke Beep, 1000, 100
.else
invoke Beep, 100, 100
invoke DefWindowProc, hWin, uMsg, wParam, lParam
.endif
ret
ASocket_MessageP endp
It is my asynchronous socket's code. I don't know why it doesn't occur callback.
Please catch up its problem and fix it.
I want to make a stable socket from critical attack.
If you have IOCP socket model's example what is wrote for assembly language, please give me it.
I can't find the example code.
Sorry for my poor English.