'Client socket coded in ASM (FASM) does not connect to Server

I am creating a communication between a client and a server via tcp/ip socket. I am developing the client in ASM (FASM) and I cannot connect to the server.

The client code in assembler:

    include 'win32ax.inc'

.data
        ; Variables
        address        db '127.0.0.1', 0
        port           dd 2222
        wsa            WSADATA          ?
        s              dd               ?
        sdr            sockaddr_in      ?
        conec          hostent          ?

start :
        ; Initialising Winsock
        push wsa
        push 200
        call [WSAStartup]
        ;cmp eax, 0

        ; Creating a socket
        push 0
        push 1
        push 2
        call [socket]
        ;cmp eax, -1
        mov [s], eax

        ; Connect to a Server
        push address
        call [gethostbyname]
        mov [conec],eax

        push [port]
        call [htons]
 
        mov [sdr.sin_family], 2
        mov [sdr.sin_port], ax
        mov eax,[conec]
        mov [sdr.sin_addr], eax
 
        push 20
        push sdr
        push [s]
        call[connect]

.end start

Suggestions and improvements are welcome. Thanks.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source