Re: Re: [lwip-users] Struggleing to build a TCP echo server
From:
Chen
Subject:
Re: Re: [lwip-users] Struggleing to build a TCP echo server
Date:
Thu, 05 Feb 2009 08:53:07 -0500
Simon,
Thanks to your reply, I am so new to the forum, I am not sure if this the
right way to to reply on the forum.
<<There is an example (very simple) HTTP server for the raw API in
the contrib module (there is also a port for unix and win32 for easy
development/debugging). The contrib module for lwIP 1.3.0 is availaible
in the download section at savannah or via CVS.>>
Could you show me how to get to the download section?
<<As you mentioned you used ATMEL sample projects: be aware ATMEL
could have an older version of lwIP, which is not really supported on
this list. Oh, and when using the raw API: be aware the functions may
only be called from one thread, the lwIP core is NOT thread safe (use
sockets/netconn if you want that).>>
ATMEL also has a working HTTP sample which I believed is based on lwIP
version 1.3 , but I just can't figure out how to extract the pieces to
construct a telnet server from it.
Based on my previous experience with Dynamic C (see the end of this email
for the example), I assume I could build something similar from lwIP
(btw, I still couldn't find any sample using tcp_* under lwIP).
Based on your suggested reading, I struggle to come up something like
this. When running, it acted like a TCP black hole: I can open connection
to port 23 once, JUST ONCE, and type until the socket is closed due to
time out.
Problem:
1) From Ethereal, it accepted Telnet connection with SYN, ACK, and after
that it does nothing, never ACK to the incoming data anymore
2) I have no idea how to test number of data in the receive buffer
3) The state machine doesn't totally agree with Dynamic C's and I have no
clue how to deal with them due to lack of documentation
Could you be so kind to give me some pointers on this?
Thank you very very much for your time!
Regards,
Chen
>>>>>> My unsuccessful try under lwIP
>>>>>> int len; int
i; struct
netbuf *buf; struct
lwip_socket *sock;
>>>>>>>>>A working TCP Echo Server from Dynamic C>>>>>>>>>>>>>
#define VS_INIT0/* closed or never opened */
#define VS_LISTEN1/* waiting for a connection */
#define VS_OPENING2/* wait while we open a connection */
#define VS_OPEN3/* we have a connection */
#define VS_WAITCLOSE4/* wait for the connection to be torn down */
typedef struct
{ int state; tcp_Socket socket;
} VsState;
switch(state->state) { case VS_INIT: tcp_listen(socket,TCP_PORT,0,0,NULL,0); state->state=VS_LISTEN; break;
case VS_LISTEN: case VS_OPENING: if(sock_established(socket)) { state->state=VS_OPEN; sock_mode(socket,TCP_MODE_BINARY); } break;
case VS_OPEN: iread=sock_dataready(socket); //iread bytes are ready to read
...
i=sock_read(socket, input, x ); //read x bytes to input[]
...
j=sock_tbleft(socket); //j bytes available on output buffer
...
sock_fastwrite(socket,buffer, y); //transmit y bytes from buffer[]
break;
case VS_WAITCLOSE: break;
default: state->state=VS_INIT; break; }
}
void main()
{ sock_init(); vs_init(&vs_state);
while (1) { tcp_tick(NULL); //this is similar to tcp_tmr in lwIP, I think vs_handler(&vs_state); }
}