I want my server to listen, when someone connects to it.. show a msg then close, at the bottom it listens, it even connects but it won't send the msg unless I put a Sleep command or msgbox (anything to make it halt), is it closing the program too fast to send the data or something? anyway to check if the data is sent so I know the exact amount of time to wait before ending the server?



.386
.model flat, stdcall ;flat model memory
option casemap:none

include \masm32\include\windows.inc

include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib

include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib

include \masm32\include\ws2_32.inc
includelib \masm32\lib\ws2_32.lib

wsprintfA PROTO C :DWORD,:VARARG
wsprintf equ <wsprintfA>
SockErr PROTO :DWORD, :DWORD
CreateSocket PROTO
cleanup PROTO

.data
sockErr db "Socket error", 0
AppName db "winsock console project",0
format db "%u", 0
ffcaused db " error was caused by function ",0
ffsocket db "socket()",0
ffstart db "WSAStartup()",0
ffaccept db "accept()",0
ffsend db "send()",0
fflisten db "listen()",0
intro db "oh shit, it works?",0

.data?
wsaData WSADATA <?>
sockVersion word ?
Lsock dd ?
buffer db 256 dup(?)
servInfo sockaddr_in <?>
clientInfo sockaddr_in <?>
msg MSG <?>
client dd ?
temp dd ?

.code
start:
invoke WSAStartup, 101h,offset wsaData
invoke socket, AF_INET, SOCK_STREAM, 0
mov Lsock, EAX
invoke SockErr, EAX, offset ffstart

invoke CreateSocket
invoke bind, Lsock, addr servInfo, sizeof sockaddr_in
invoke SockErr, EAX, offset ffsocket

invoke listen, Lsock, 10
invoke SockErr, EAX, offset fflisten

mov eax, sizeof sockaddr_in
mov temp, eax
invoke accept, Lsock, addr clientInfo, addr temp
mov client, EAX
invoke SockErr, EAX, offset ffaccept

invoke send, client, addr intro, sizeof intro, 0
invoke SockErr, EAX, offset ffsend
invoke Sleep, 2000
;invoke MessageBox, 0, addr AppName, addr AppName, 0
invoke cleanup
invoke ExitProcess, 0

cleanup proc
;invoke closesocket, client
;invoke closesocket, Lsock
invoke WSACleanup
ret
cleanup endp

CreateSocket proc
mov servInfo.sin_family, AF_INET
mov servInfo.sin_addr, 0
invoke htons, 1016
mov servInfo.sin_port, AX
ret
CreateSocket endp

SockErr proc ErrorYN:DWORD, lpFunc:DWORD
.if ErrorYN==INVALID_SOCKET
invoke WSAGetLastError
invoke wsprintf, offset buffer, offset format, EAX
invoke lstrcat, offset buffer, offset ffcaused
invoke lstrcat, offset buffer, lpFunc
invoke MessageBox, 0, addr buffer, addr AppName, 0
invoke WSACleanup
.endif
ret
SockErr endp
end start
Posted on 2003-06-16 21:51:55 by KewLexX
Just enable the closesocket calls again and it should work.

Thomas
Posted on 2003-06-17 03:46:30 by Thomas
hah, I was using RadASM and had the proc's folded (not collapsed). Thanks for pointing it out.
Posted on 2003-06-17 07:13:46 by KewLexX