hi all.i am a newbie of win32asm from china.
i want to make a simple server,a part of codes:

invoke accept,listensock,offset remote,sizeof remote
invoke GetErrorString,addr ErrorString
invoke MessageBox, hwnd , offset ErrorString, offset ERR_TITLE, MB_OK
jmp @startret

mov remotesock,eax
invoke lstrlen,offset reponseHeader
invoke send,remotesock,offset reponseHeader,eax,0
invoke closesocket,remotesock
invoke WSACleanup

when i start server,it told me "accept error...",
who can help me?
my mail : xqterry@yeah.net
Posted on 2001-12-26 10:39:07 by xqterry
invoke accept,listensock,offset remote,sizeof remote

The last parameter is a *pointer* to a dword variable containing the size of a sockaddr_in struct, not the size itself. Use this:

sizeSockAddr dd SIZEOF sockaddr_int[/b]
invoke accept,listensock,offset remote, [b]addr sizeSockAddr[/b]

Posted on 2001-12-26 16:41:10 by Thomas

thank you.yes,now it works.

and i have a question,
i want to know how the server can recv an inconstant lenth buffer,for example, when ie browser send a request header to a httpserver, how can the server know lenth of request and get it correctly?
i know if the server send data to browser before finish recv request and the browser hasn't flush send buffer, the browser will do nothing but say "server not found".:(
i tried to recv request from browser, there's problem:
@how to catch the end of buffer, i always made a deadloop.

i'm glad to recv your reply.
be regards
Posted on 2001-12-26 22:43:28 by xqterry
That's what protocols where designed for. Search www.rfc-editor.org for RFC 2616, which is the full description of the HTTP protocol. That's the protocol used for the www.
A request (from the browser) looks like this:

GET /folder/filename HTTP/1.1
Host: [url]www.somehost.com[/url]
Accept: */*
Connection: close

The protocol itself is in plain text. The request consists of a request line (the first line), 0 or more optional headers (each one on a seperate line in the form headername: data, and finally a *blank line* which indicates the end of the request.
You need to parse this somehow and detect the blank line at the end.

Posted on 2001-12-27 10:48:08 by Thomas

yes, i know rfc about http.
thanks anyway

and what i said means if the client(browser) hasn't flush the header,server begin to write to client and close socket then client will say "server not found".

i referenced some samples about server side code. now it could work.:)
i wanted to use thread for server designed.i planed a application create a server thread when recv startserver msg,then server loop at accept.when new client connect,server create a thread for client.i tried to do follow my plan,but i could not deal recv from client correctly,:( the samples i ref all use asyn-select and use main process msg-loop to deal recv and send,and i had to edit my plan and use asyn-select too.:tongue:
i tried to create server thread in this way but i can not make it loop at accept,you know.sigh~

by the way,my english is poor,i am sorry for it,:tongue:
and i am not a asm programmer,maybe i make you trouble.
anyway,i am glad to know you.
be regards
Posted on 2001-12-27 12:25:17 by xqterry
Well you could do this:
- create one main socket to accept connections. Use wsaasyncselect to setup the notifications.
- when a client connects, accept the connection (you'll get a new socket then, the client socket).
- Create a new thread for each client and pass the right client socket handle to it.
- Find a way to tell the thread events that happen. You could use event objects for example, and wait for them in the thread (WaitForSingleObject).

Posted on 2001-12-27 17:10:14 by Thomas