News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Winsock not 'working'

Started by Samuel, January 26, 2006, 08:37:25 AM

Previous topic - Next topic

Samuel

Hey!

Ive been programming with C++ for a few years now and have decided to learn MASM. Ive already had a bit of experience with 16bit dos asm and a little inline asm.

Ive been trying to port some of my old C++ projects to MASM, but I havnt had much success with sockets. This chunk of code is supposed to create and open a TCP socket, however it doesnt appear to be working. It assembles fine, and doesnt create any errors when it runs, but the socket isnt opening.


.data
      ClassName db "Samsn",0
      AppName  db "Samuel's MSN",0
      ErrorText db "Error creating socket", 0
      SockVersion dw 0, 0
      Check1 db "Check1", 0
      Check2 db "Check2", 0
      Check3 db "Check3", 0

.data?
      hInstance HINSTANCE ?
      CommandLine LPSTR ?
      listeningSocket SOCKET ?


InitSocket proc
      LOCAL serverInfo:sockaddr_in
      LOCAL WSAData:WSADATA
      mov al, 1
      mov ah, 1
      mov SockVersion, ax
      invoke WSAStartup, addr SockVersion,addr WSAData
      invoke socket, AF_INET, SOCK_STREAM, IPPROTO_TCP
      mov listeningSocket, eax
      invoke MessageBox, NULL, addr Check1, addr AppName, MB_OK
      cmp listeningSocket, INVALID_SOCKET
      je ReportError
      mov serverInfo.sin_family, AF_INET
      mov serverInfo.sin_addr, INADDR_ANY
      invoke htons, 8888
      mov serverInfo.sin_port, ax
      invoke bind, listeningSocket, addr serverInfo, SIZEOF sockaddr_in
      invoke MessageBox, NULL, addr Check2, addr AppName, MB_OK
      cmp ax, SOCKET_ERROR
      je ReportError
      invoke listen, listeningSocket, 10
      invoke MessageBox, NULL, addr Check3, addr AppName, MB_OK
      cmp ax, SOCKET_ERROR
      je ReportError
      ret
InitSocket endp

Tedd

Not sure whether it is your actual problem, but it will definitely not help..


    invoke bind, listeningSocket, addr serverInfo, SIZEOF sockaddr_in    ;eax = return value of bind
    invoke MessageBox, NULL, addr Check2, addr AppName, MB_OK            ;eax = return value of messagebox (not bind)
    cmp ax, SOCKET_ERROR                                                 ;eax = return value from messagebox (NOT bind!!)


You've done it more than once.
Just for debugging, you can simply: push eax; messagebox; pop eax
No snowflake in an avalanche feels responsible.