I seem to have problems on multithread with winsock ;-(
I am stuck on how to communicate with threads...
please help me out !!!
so far I have this:
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL ThreadID:DWORD
.IF uMsg==WM_CREATE
invoke WSAStartup, 101h, addr WSAdata
invoke socket, AF_INET, SOCK_STREAM, 0
.IF (eax!=INVALID_SOCKET)
mov hListenSocket, eax
.ENDIF
invoke WSAAsyncSelect, hListenSocket, hWnd, WM_SOCKET, FD_ACCEPT+FD_CLOSE
mov SA_IN.sin_family, AF_INET
invoke htons, szPort
mov SA_IN.sin_port, ax
mov SA_IN.sin_addr, INADDR_ANY
invoke bind, hListenSocket, addr SA_IN, sizeof SA_IN
invoke listen, hListenSocket, 5
.ELSEIF uMsg==WM_SOCKET
mov eax, lParam
.IF (ax==FD_ACCEPT)
shr eax, 16
.IF (eax==0)
mov ecx, offset ListenThread
invoke CreateThread, NULL, NULL, ecx, NULL, NORMAL_PRIORITY_CLASS, ADDR ThreadID
.ENDIF
.ELSEIF (ax==FD_CLOSE)
.ENDIF
.ENDIF
ListenThread proc Param:DWORD
LOCAL ThreadID:DWORD
LOCAL ClientSocket:DWORD
LOCAL ClientSocketAddr:sockaddr_in
mov ecx, sizeof sockaddr_in
invoke accept, hSocket, addr ClientSocketAddr, ecx
invoke WSAAsyncSelect, hListenSocket, hWnd, WM_SOCKET, FD_READ+FD_WRITE+FD_CLOSE
mov ClientSocket, eax
mov ecx, offset ClientThread
invoke CreateThread, NULL, NULL, ecx, NULL, NORMAL_PRIORITY_CLASS, ADDR ThreadID
invoke CloseHandle, eax
;;; how do I process the FD_xxxx msg?? so that I can send to the ClientThread????
ret
ListenThread endp
ClientThread proc Param:DWORD
;;; how do I receive the FD_xxxxx msg from the listenThread????
ret
ClientThread endp
I am stuck on how to communicate with threads...
please help me out !!!
so far I have this:
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL ThreadID:DWORD
.IF uMsg==WM_CREATE
invoke WSAStartup, 101h, addr WSAdata
invoke socket, AF_INET, SOCK_STREAM, 0
.IF (eax!=INVALID_SOCKET)
mov hListenSocket, eax
.ENDIF
invoke WSAAsyncSelect, hListenSocket, hWnd, WM_SOCKET, FD_ACCEPT+FD_CLOSE
mov SA_IN.sin_family, AF_INET
invoke htons, szPort
mov SA_IN.sin_port, ax
mov SA_IN.sin_addr, INADDR_ANY
invoke bind, hListenSocket, addr SA_IN, sizeof SA_IN
invoke listen, hListenSocket, 5
.ELSEIF uMsg==WM_SOCKET
mov eax, lParam
.IF (ax==FD_ACCEPT)
shr eax, 16
.IF (eax==0)
mov ecx, offset ListenThread
invoke CreateThread, NULL, NULL, ecx, NULL, NORMAL_PRIORITY_CLASS, ADDR ThreadID
.ENDIF
.ELSEIF (ax==FD_CLOSE)
.ENDIF
.ENDIF
ListenThread proc Param:DWORD
LOCAL ThreadID:DWORD
LOCAL ClientSocket:DWORD
LOCAL ClientSocketAddr:sockaddr_in
mov ecx, sizeof sockaddr_in
invoke accept, hSocket, addr ClientSocketAddr, ecx
invoke WSAAsyncSelect, hListenSocket, hWnd, WM_SOCKET, FD_READ+FD_WRITE+FD_CLOSE
mov ClientSocket, eax
mov ecx, offset ClientThread
invoke CreateThread, NULL, NULL, ecx, NULL, NORMAL_PRIORITY_CLASS, ADDR ThreadID
invoke CloseHandle, eax
;;; how do I process the FD_xxxx msg?? so that I can send to the ClientThread????
ret
ListenThread endp
ClientThread proc Param:DWORD
;;; how do I receive the FD_xxxxx msg from the listenThread????
ret
ClientThread endp
invoke WSAAsyncSelect, hListenSocket, hWnd, WM_SOCKET, FD_READ+FD_WRITE+FD_CLOSE
tells the system to alert hWnd when an event occures. It does this through the wndproc registered with RegisterClassEx.
Another way of using threads is with events. Look at WSACreateEvent and WSAWaitForMultipleEvents.
tells the system to alert hWnd when an event occures. It does this through the wndproc registered with RegisterClassEx.
Another way of using threads is with events. Look at WSACreateEvent and WSAWaitForMultipleEvents.
thankx for the reply,
but I want to know how to solve my problem above,
how to make sure my threads can receive msg from other threads???
I just duno how to send msg to a thread and make sure the thread I want to send msg to able to receive the msg...
anyone can help me out here???
thankx alots
but I want to know how to solve my problem above,
how to make sure my threads can receive msg from other threads???
I just duno how to send msg to a thread and make sure the thread I want to send msg to able to receive the msg...
anyone can help me out here???
thankx alots
PostThreadMessage(...) in the message loop should do the trick. Look here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/messques_1ued.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/messques_1ued.asp
I got it,
thankx
thankx