I am trying to write little server that I want to control with telnet.I have searched the board and read Thomas's tutorial bu still cant make it work.I want my server to reply every request like WebServer.Thomas's one didnt worked with telnet( works with putty) and only supports one connection at a time.
I want to control server with basic commands and each command is ended with NEWLINE.Here is non working code that I copied from Cinchy server



WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.IF uMsg==WM_DESTROY
invoke closesocket,hSocket
invoke PostQuitMessage,NULL
.ELSEIF uMsg==WM_CREATE
invoke WSAStartup,0101h,ADDR wsaData
INVOKE socket,PF_INET,SOCK_STREAM,IPPROTO_TCP
mov hSocket,eax ;Configure listening socket
mov SA.sin_family,AF_INET
mov SA.sin_addr.S_un.S_addr,INADDR_ANY
INVOKE htons,23
mov SA.sin_port,ax
INVOKE WSAAsyncSelect,hSocket,hWnd,WM_SOCKET,FD_ACCEPT
INVOKE bind,hSocket,offset SA,sizeof SA
INVOKE listen,hSocket,5 ;Listen for connections
.ELSEIF uMsg==WM_SOCKET ;thread finished
mov eax,lParam
and eax,0FFFFh
.IF ax==FD_ACCEPT
INVOKE accept,hSocket,0,0
INVOKE WSAAsyncSelect,eax,hWnd,WM_SOCKET,FD_READ or FD_CLOSE
.ELSEIF ax==FD_READ
INVOKE recv,wParam,offset RSBuf,1024,0
movzx ecx,byte ptr[RSBuf+eax]
cmp ecx,0ah ;newline ?
jnz @F
invoke MessageBox,0,addr RSBuf,0,MB_OK ;show message
@@:
.ELSEIF ax==FD_CLOSE
INVOKE closesocket,wParam
.endif
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF
xor eax,eax
ret
WndProc endp
Posted on 2003-09-12 22:14:09 by LaptoniC
If you call recv with a buffer 1024 bytes long, the system wait until the buffer is full.
invoke ioctlsocket, hSocket, FIONREAD, addr DataLen

hSocket : Socket handle
DataLen : dword that will contain the size of the data available in the network buffer
Posted on 2003-09-13 01:16:07 by greenant
recv doesnt wait untill buffer is full.For example when I write xxxxxxxxA messagebox shows.I want to get messagebox after each line ie

Telnet
--------
command1

Server
MsgBox command1
Posted on 2003-09-13 07:17:51 by LaptoniC
You are right.
Every time you press a key, telnet will send you a char.
So you have to build a loop



loop:
invoke recv, hSocket, addr buffer, 1, 0
check if byte ptr [buffer] is cr (or lf, i don't know wich come first)
.if yes
process the message
.else
append the char to a buffer
.endif
jmp loop
Posted on 2003-09-13 10:17:29 by greenant