News:

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

Problems with winsock

Started by Celtic, February 12, 2010, 04:48:48 PM

Previous topic - Next topic

Celtic

I need help. This is my Server code

.486p
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\wsock32.inc
include \masm32\include\kernel32.inc
include \masm32\include\winmm.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\wsock32.lib
includelib \masm32\lib\kernel32.lib

includelib \masm32\lib\winmm.lib


.data



buff      db 512 dup (0)

.data?
s1        SOCKET ?
s2        SOCKET ?
sin1      sockaddr_in <>
sin2      sockaddr_in <>
wsaData   WSADATA <>
temp      dd ?




.code

start:
    invoke WSAStartup,0101h,ADDR wsaData
    invoke socket,PF_INET,SOCK_STREAM,0
    mov s1,eax
    mov ax,AF_INET
    mov sin1.sin_family,ax
    xor eax,eax
    mov sin1.sin_addr,eax
    invoke htons,23 ;Telnet port
    mov sin1.sin_port,ax
    invoke bind,s1,ADDR sin1,SIZEOF sockaddr_in
    cmp eax,SOCKET_ERROR
    jne @F
    invoke WSACleanup
    xor eax,eax
    ret
@@:
    invoke listen,s1,1
next_user:
    invoke closesocket,s2
    mov eax,SIZEOF sockaddr_in
    mov temp,eax
    invoke accept,s1,ADDR sin2,ADDR temp
    mov s2,eax

weiter:
invoke recv,s2,addr buff,sizeof buff,0
or eax,eax
jz weiter

invoke MessageBox,0,addr buff,0,0


jmp weiter

    invoke Sleep,2000
    invoke closesocket,s1
    invoke closesocket,s2
    invoke WSACleanup
    xor eax,eax
    ret

end start


It works fine with telnet but when i use this code



.486p
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\wsock32.inc
include \masm32\include\kernel32.inc
include \masm32\include\gdi32.inc
include \masm32\include\winmm.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\wsock32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\winmm.lib

include \masm32\include\shell32.inc
includelib \masm32\lib\shell32.lib


.data

SendBuff    db  "Comming from the client..."
            db  0
           
Buff2       db  512  dup(0)
            db  0

TempVar     dd  0

           
ServerIPAddress db  "127.0.0.1", 0

.data?
S1        SOCKET ?
S2        SOCKET ?
Sin1      sockaddr_in <>
Sin2      sockaddr_in <>
WSAData   WSADATA <>
Temp      dd ?


.code
start:

invoke  WSAStartup, 0101h, ADDR WSAData
invoke  socket, PF_INET, SOCK_STREAM, IPPROTO_TCP
mov     S1, eax
mov     ax, AF_INET
mov     Sin1.sin_family, ax
xor     eax, eax
mov     Sin1.sin_addr, eax
invoke  inet_addr, addr ServerIPAddress
mov     Sin1.sin_addr, eax
invoke  htons, 23                             
mov     Sin1.sin_port, ax
invoke  bind, S1, ADDR Sin1, SIZEOF sockaddr_in


invoke  closesocket, S2
mov     eax, SIZEOF sockaddr_in
mov     Temp, eax
invoke  accept, S1, ADDR Sin2, ADDR Temp
mov     S2,eax


invoke  connect, S1, addr Sin1, SIZEOF Sin1

mov     TempVar, SIZEOF SendBuff
invoke send, S2, addr SendBuff, TempVar, 0

ret
end start


Nothing Happends :( ?!?


Added code tags

smurf

not sure if you were looking for something like this.

.486p
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\wsock32.inc
include \masm32\include\kernel32.inc
include \masm32\include\gdi32.inc
include \masm32\include\winmm.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\wsock32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\winmm.lib

include \masm32\include\shell32.inc
includelib \masm32\lib\shell32.lib


.data
SendBuff    db  "Comming from the client...",0
Buff2        db  512  dup(0)
ServerIPAddress db  "127.0.0.1", 0

.data?
S1        SOCKET ?
Sin1      sockaddr_in <>
WSAData   WSADATA <>

.code
start:

invoke  WSAStartup, 0101h, ADDR WSAData
invoke  socket, PF_INET, SOCK_STREAM,0
mov     S1, eax
mov     Sin1.sin_family, AF_INET
invoke  htons, 23
mov     Sin1.sin_port, ax
invoke gethostbyname, addr ServerIPAddress
mov     eax,[eax+12]
mov     eax,[eax]
mov     eax,[eax]
mov     Sin1.sin_addr, eax

invoke  connect, S1, addr Sin1, sizeof Sin1
invoke send, S1, addr SendBuff, sizeof SendBuff, 0

ret
end start