flat assembler
Message board for the users of flat assembler.
Index
> Windows > Winsock Send Help. |
Author |
|
Picnic 10 Sep 2010, 14:29
Hi,
If accept() succeeds, the return value is a new socket created on the server side. therefore it would be better: Code: invoke accept, [server], saddr, saddrlen mov [client],eax invoke send,[client],welcome,2,0 Close sockets and cleanup. Code should work now. closesocket() WSACleanup() |
|||
10 Sep 2010, 14:29 |
|
Nameless 10 Sep 2010, 14:37
but i think accept is non-blocking API? am i right? that means it needs to be inside a loop
|
|||
10 Sep 2010, 14:37 |
|
Overflowz 10 Sep 2010, 14:39
Hi, I understand now whats problem but I have bit problem. when I'm calling WSACleanup, the same problem are occuired. here's code. Thanks.
Code: format PE console 4.0 entry main include 'WIN32AX.INC' .data server dd ? client dd ? welcome db "Hi",0 saddrlen dd sizeof.sockaddr_in saddr sockaddr_in wsaData WSADATA PORT = 23 .code main: invoke WSAStartup,0202h,wsaData invoke WSASocket, AF_INET, SOCK_STREAM, 6, 0, 0, 0 mov [server], eax mov [saddr.sin_family], AF_INET invoke htons, PORT mov [saddr.sin_port], ax invoke htonl, 0 mov [saddr.sin_addr], eax invoke bind, [server], saddr, saddrlen invoke listen, [server], 1 invoke accept, [server], saddr, saddrlen mov [client],eax invoke send,[client],welcome,2,0 invoke closesocket,client invoke closesocket,server invoke WSACleanup invoke ExitProcess,0 data import library kernel32,'kernel32.dll',ws2_32,'ws2_32.dll' include 'API\KERNEL32.INC' include 'API\WS2_32.INC' end data |
|||
10 Sep 2010, 14:39 |
|
Nameless 10 Sep 2010, 15:02
ive nothing to test on here, but its up to u now
here is what i wrote so far Code: _data rb 1024 ........... .accept_loop: invoke accept, [server], saddr, saddrlen cmp eax, -1 je .accept_loop mov [client], eax ;if it reached this line, it means that we have a new connection jmp .recv_loop ;take that new socket to the receiving loop .recv_loop: xor eax, eax mov dword [_data], eax invoke recv, [client], _data, 1024, 0 cmp eax, 0 je .end_recv_loop ;add one more compare of eax, is its -1, re-initialize all ur sockets again jmp .process_data .end_recv_loop: ;Connection Closed, Get Back to listening for new connection invoke closesocket, [client] jmp .accept_loop .process_data: ;Process ur data received here |
|||
10 Sep 2010, 15:02 |
|
Overflowz 10 Sep 2010, 15:10
Oh Thanks. BTW I'm trying to figure out how to do like send and recv functions both, like telnet chat ? I know Netcat using that function. with this command nc -L -v -p 23 and when connected I can write something and data are transfered to remote and reverse. How can I do that ? Thanks.
|
|||
10 Sep 2010, 15:10 |
|
Nameless 10 Sep 2010, 15:21
i dont really know what netcat traffic looks like, but here is the simplest way i can think of to process commands
Code: .process_data: ;Process ur data received here invoke StrCmpI, _data, "COMMAND1" je .process_command1 invoke StrCmpI, _data, "COMMAND2" je .process_command2 jmp .recv_loop ;no commands found, re-do the recv loop incase we got something to recoginize .process_command1: ;Do whatever function u want here ;and to send() invoke send, [client], _data , 1024, 0 ;data or whatever other variable that holds the data u want to send jmp .recv_loop ; must do this after each command, to receive the queued data .process_command2: ;bla bla bla jmp .recv_loop ;exactly as the previous one StrCmpI EDIT: oops, forgot to say that the _data is the variable that holds the received data from the connection, as it was done in my previous post |
|||
10 Sep 2010, 15:21 |
|
Overflowz 10 Sep 2010, 15:46
Ah I got it. thanks. And, Is there any other way to do without StrCmpI? I mean without using library. Is that like cmp in asm language ?
|
|||
10 Sep 2010, 15:46 |
|
Picnic 10 Sep 2010, 17:30
Overflowz wrote: Hi, I understand now whats problem but I have bit problem. when I'm calling WSACleanup, the same problem are occuired. Code: invoke closesocket,[client] invoke closesocket,[server] Nameless wrote: but i think accept is non-blocking API? am i right? that means it needs to be inside a loop A socket it is automatically set to be blocking so accept() actually blocks until a connection request comes. |
|||
10 Sep 2010, 17:30 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.