From: io_x on
do you like my hobby work of the day?
not tested, it is so because it has to deal only one connection
in one tread of the program
it has only one parameter [a pointer that is one array of parametres]

there is someone understand it?

align 4
tcpServerUno_m:
<b,c,r,i,j,k
s-=256
<< nPort=0, nomeF=4, argf=8, eventU=12, sockfp=4, server=16
<< client=40, hThread=64, lpThreadId=72, fd=16
<< Nerrori=128
k=1|j=*s+284 |j==0#.2
D*j+nPort<=0?#.2|D*j+nomeF ==0#.2
D*j+argf ==0 #.2|D*j+eventU==0#.2|^Nerrori=0|#.4
; trattamento degli errori
..1: closesocket(i)
..2: a=k
..e: stc|##.f
..4: k=3|D[_socketSta]#.4a|OpenSocket_m()|jc .2
..4a: k=4|socket(AF_INET,SOCK_STREAM,0)|a==IVA_#.2|i=a
a=*j+nPort|a>=0FFFFh#.1|htons(a) |b=&^server
[b + sin_port ]= ax
htonl(INADDR_ANY)| [b + sin_addr]=a
W[b + sin_family]= AF_INET ; b=server struct,
j=socket
D[b + sin_zero ]= 0| D[b+sin_zero+4]=0 ; i=fd
k=5|bind(i, b,16)|a#.1
b=*j+8
k=6|listen(i, 1) |a#.1
..c0: a=&^client |^lpThreadId=16|r=&^lpThreadId
k=6|^sockfp=Faccept_m(i, a, r, (-1), 5)|jc .1 ; 5 secondi di
timeout
; -1 timeout client
a==0#.5a ; se nessuna connessione solo timeout vai a vedere
l'evento
a=^sockfp |r=*j+nomeF|k=7|*b=a
r(b)|a!=0!#.5|++^Nerrori
..5: a=^sockfp |k=8|FcloseSocket_m(a)|jc .1 ; e interrompe il server
..5a: a=*j+eventU|WaitForMultipleObjects(1, a, 0, 0)|a==&WAIT_FAILED#.1
a==&WAIT_OBJECT_0#.7 ; se l'evento termine vai alla fine
..6: #.c0
..7: k=10|closesocket(i)|a#.2
a^=a
..f:
>> nPort, nomeF, argf, eventU, sockfp, server
>> client, hThread, lpThreadId, fd
>> Nerrori
s=&*s+256
>b,c,r,i,j,k
ret 4


From: io_x on
Re: the general serve

^^^^^

it is server

"io_x" <a(a)b.c.invalid> ha scritto nel messaggio
news:4c1fc7e0$0$18991$4fafbaef(a)reader5.news.tin.it...

> do you like my hobby work of the day?
> not tested, it is so because it has to deal only one connection
> in one tread of the program
> it has only one parameter [a pointer that is one array of parametres]
>
> there is someone understand it?
>
> align 4
> tcpServerUno_m:
> <b,c,r,i,j,k
> s-=256
> << nPort=0, nomeF=4, argf=8, eventU=12, sockfp=4, server=16
> << client=40, hThread=64, lpThreadId=72, fd=16
> << Nerrori=128
> k=1|j=*s+284 |j==0#.2
> D*j+nPort<=0?#.2|D*j+nomeF ==0#.2
> D*j+argf ==0 #.2|D*j+eventU==0#.2|^Nerrori=0|#.4
> ; trattamento degli errori
> .1: closesocket(i)
> .2: a=k
> .e: stc|##.f
> .4: k=3|D[_socketSta]#.4a|OpenSocket_m()|jc .2
> .4a: k=4|socket(AF_INET,SOCK_STREAM,0)|a==IVA_#.2|i=a
> a=*j+nPort|a>=0FFFFh#.1|htons(a) |b=&^server
> [b + sin_port ]= ax
> htonl(INADDR_ANY)| [b + sin_addr]=a
> W[b + sin_family]= AF_INET ; b=server struct,
> j=socket
^^^^^^^^^^^^
this comment is wrong



From: Nathan Baker on

"io_x" <a(a)b.c.invalid> wrote in message
news:4c1fc7e0$0$18991$4fafbaef(a)reader5.news.tin.it...
> do you like my hobby work of the day?
> not tested, it is so because it has to deal only one connection
> in one tread of the program
> it has only one parameter [a pointer that is one array of parametres]
>
> there is someone understand it?
>

Looks a bit messy. Here is a simple "echo server" that accepts multiple
connections.

%include '..\..\..\inc\nasmx.inc'
%include '..\..\..\inc\win32\windows.inc'
%include '..\..\..\inc\win32\kernel32.inc'
%include '..\..\..\inc\win32\user32.inc'
%include '..\..\..\inc\win32\wsock32.inc'

entry echosrv

%define hton(x) ((x & 0xFF000000) >> 24) | ((x & 0x00FF0000) >> 8) | ((x &
0x0000FF00) << 8) | ((x & 0x000000FF) << 24)
%define htons(x) ((x >> 8) & 0xFF) | ((x & 0xFF) << 8)
svrip equ hton(7f000001h)
svrport equ htons(27015)

section .bss
hsock resd 1
tid resd 1
buff resb 1

section .data
echo_sa istruc sockaddr_in
at sockaddr_in.sin_family, dw 2
at sockaddr_in.sin_port, dw svrport
at sockaddr_in.sin_addr, dd svrip
at sockaddr_in.sin_zero, dd 0, 0
iend

mywsadata istruc WSAdata
iend

greet db 'ASM Server v0.003', 13, 10
greet_len equ $ - greet

section .text
proc echosrv
invoke WSAStartup, 0x101, mywsadata
invoke socket, 2, 1, 0
mov [hsock], eax
invoke bind, [hsock], echo_sa, 20
invoke listen, [hsock], 5 ;number of connections
again:
invoke accept, [hsock], 0, 0
;;returns new socket handle in EAX
;;we pass it as the thread parameter
invoke CreateThread, 0, 0, sockthread, eax, 0, tid
add esp, 4
jmp again

endit: ;never gets here
;invoke closesocket, [hsock]
;invoke WSACleanup
;invoke ExitProcess, 0

sockthread:
push ebp
sub esp, 4
mov ebp, esp
mov ebx, [esp+12] ;retrieve thread parameter
mov [ebp], ebx ;store in easily ref'd place
invoke send, [ebp], greet, greet_len, 0
back:
invoke recv, [ebp], buff, 1, 0
mov al, byte [buff]
cmp al, 'q'
je disconnect
invoke send, [ebp], buff, 1, 0
jmp back

disconnect:
invoke closesocket, [ebp]
add esp, 4
pop ebp
invoke ExitThread, 0

When you get it running, just open another CLI window and type "telnet
127.0.0.1 27015" to connect. Do that again in another CLI window for each
additional connection you desire. Type "q" in the telnet session to
disconnect.

Nathan.



From: Nathan Baker on

"Nathan Baker" <nathancbaker(a)gmail.com> wrote in message
news:weednWbHbo1BjrnRnZ2dnUVZ_rydnZ2d(a)giganews.com...
>
> invoke CreateThread, 0, 0, sockthread, eax, 0, tid
> add esp, 4
> jmp again
>

Forgot to delete the "add esp, 4" there....


From: io_x on

"Nathan Baker" <nathancbaker(a)gmail.com> ha scritto nel messaggio
news:weednWbHbo1BjrnRnZ2dnUVZ_rydnZ2d(a)giganews.com...
>
> "io_x" <a(a)b.c.invalid> wrote in message
> news:4c1fc7e0$0$18991$4fafbaef(a)reader5.news.tin.it...
>> do you like my hobby work of the day?
>> not tested, it is so because it has to deal only one connection
>> in one tread of the program
>> it has only one parameter [a pointer that is one array of parametres]
>>
>> there is someone understand it?
>>
>
> Looks a bit messy. Here is a simple "echo server" that accepts multiple
> connections.
>
> %include '..\..\..\inc\nasmx.inc'
> %include '..\..\..\inc\win32\windows.inc'
> %include '..\..\..\inc\win32\kernel32.inc'
> %include '..\..\..\inc\win32\user32.inc'
> %include '..\..\..\inc\win32\wsock32.inc'
>
> entry echosrv
>
> %define hton(x) ((x & 0xFF000000) >> 24) | ((x & 0x00FF0000) >> 8) | ((x &
> 0x0000FF00) << 8) | ((x & 0x000000FF) << 24)
> %define htons(x) ((x >> 8) & 0xFF) | ((x & 0xFF) << 8)
> svrip equ hton(7f000001h)
> svrport equ htons(27015)
>
> section .bss
> hsock resd 1
> tid resd 1
> buff resb 1
>
> section .data
> echo_sa istruc sockaddr_in
> at sockaddr_in.sin_family, dw 2
> at sockaddr_in.sin_port, dw svrport
> at sockaddr_in.sin_addr, dd svrip
> at sockaddr_in.sin_zero, dd 0, 0
> iend
>
> mywsadata istruc WSAdata
> iend
>
> greet db 'ASM Server v0.003', 13, 10
> greet_len equ $ - greet
>
> section .text
> proc echosrv
> invoke WSAStartup, 0x101, mywsadata
> invoke socket, 2, 1, 0
> mov [hsock], eax
> invoke bind, [hsock], echo_sa, 20
> invoke listen, [hsock], 5 ;number of connections
> again:
> invoke accept, [hsock], 0, 0
> ;;returns new socket handle in EAX
> ;;we pass it as the thread parameter
> invoke CreateThread, 0, 0, sockthread, eax, 0, tid
> add esp, 4
> jmp again
>
> endit: ;never gets here
> ;invoke closesocket, [hsock]
> ;invoke WSACleanup
> ;invoke ExitProcess, 0
>
> sockthread:
> push ebp
> sub esp, 4
> mov ebp, esp
> mov ebx, [esp+12] ;retrieve thread parameter
> mov [ebp], ebx ;store in easily ref'd place
> invoke send, [ebp], greet, greet_len, 0
> back:
> invoke recv, [ebp], buff, 1, 0
> mov al, byte [buff]
> cmp al, 'q'
> je disconnect
> invoke send, [ebp], buff, 1, 0
> jmp back
>
> disconnect:
> invoke closesocket, [ebp]
> add esp, 4
> pop ebp
> invoke ExitThread, 0
>
> When you get it running, just open another CLI window and type "telnet
> 127.0.0.1 27015" to connect. Do that again in another CLI window for each
> additional connection you desire. Type "q" in the telnet session to
> disconnect.
>
> Nathan.

the exercise i think is this:

i have one function that
1) has to see if one button is push
if it is push it has to send to socket one string
gets to one window
2) has to see if another button is push
if it is push it has to exit
3) has to see if socket receive one string
and if receive has to print it in another window

how i can manage all that, with select?
With WaitForMultipleObject?

if say the true i thought about this function
it is call from the CreateThread fucntions
and has all information

one function that
..a: open one subthread
.1: that subthread use select for read-write
if the socket has data to read
use one semaphore for use the socket
read the socket
print it in a windows
check if events exitFunction, exitServer, are set
if set exit thread
else goto .1
..b: wait for exitsubtread, sendData, exitFunction, exitServer, events
if exitsubtread event
exit of the function
if sendData event
gets from the windows the data
use one semaphore for use the socket
write the socket
goto .b
if exitFunction, exitServer, events
use one variable to know this operation is one time only
use one semaphore for use the socket
write the socket \0
goto .b



 |  Next  |  Last
Pages: 1 2 3 4
Prev: Delphi 2007 move routine flawed ?
Next: what timer?