Forum Discussion
tse transmission get hanged in TCP protocal
Hello,everyone!
I want to transfer data between my laptop(the OS is windows XP) and my Stratix III 3sl150 board through ethernet wire. I'm using the hardware and software design found here: stratixiii_3sl150_dev_tse_sgmii_v1.zip (http://www.alteraforum.com/forum/attachment.php?attachmentid=1233&d=1246537769), the mode is "10/100/1000mac wtih 1000 base -x/sgmii"(1000Mbps & full Duplex mode). When using this design, the simple socket sever exmaple works well. Afterward, I changed the software design to test the stability of the connection, in TCP protocal. I use my Stratix III board as server, and my laptop as client. And made a for loop in both end to send and receive data: stratix iii, receive 1, send 2; laptop, send 1, receive 2. So, if the connection is stable, the loop will never be stop. But practically, the loop get hanged after some time, and I don't know why. Should it be a hardware problem(timing problem) or I do not write the software code right? Can anyone help me please?16 Replies
- Altera_Forum
Honored Contributor
Here is my changed simple_socket_sever.c
# include <stdio.h> # include <string.h> # include <ctype.h> # include "includes.h" # include "simple_socket_server.h" # include "alt_error_handler.h" # include "ipport.h" # include "tcpport.h" void sss_reset_connection(SSSConn* conn) { memset(conn, 0, sizeof(SSSConn)); conn->fd = -1; conn->state = READY; conn->rx_wr_pos = conn->rx_buffer; conn->rx_rd_pos = conn->rx_buffer; return; } void sss_handle_accept(int listen_socket, SSSConn* conn) { int socket, len; struct sockaddr_in incoming_addr; alt_u8 sendBuf; alt_u8 *send_ptr = sendBuf; len = sizeof(incoming_addr); if ((conn)->fd == -1) { if((socket=accept(listen_socket,(struct sockaddr*)&incoming_addr,&len))<0) { alt_NetworkErrorHandler(EXPANDED_DIAGNOSIS_CODE, " accept failed"); } else { (conn)->fd = socket; //sss_send_menu(conn); send_ptr += sprintf(send_ptr,"Connected OK!\n\r"); send_ptr += sprintf(send_ptr,inet_ntoa(incoming_addr.sin_addr)); send_ptr += sprintf(send_ptr,"\n\r"); send(conn->fd, sendBuf, send_ptr-sendBuf, 0); printf(" accepted connection request from %s\n", inet_ntoa(incoming_addr.sin_addr)); } } else { printf(" rejected connection request from %s\n", inet_ntoa(incoming_addr.sin_addr)); } return; } void sss_handle_receive(SSSConn* conn) { char Buf; memset(Buf,0,10); //OSTimeDlyHMSM(0,0,1,0); recv(conn->fd,Buf,2,0); printf("%s\nrecieved OK!\n\n",Buf); //OSTimeDlyHMSM(0,0,1,0); send(conn->fd,"2",2,0); printf("2 sent OK!\n\n"); return; } void SSSSimpleSocketServerTask() { int fd_listen, max_socket; struct sockaddr_in addr; static SSSConn conn; fd_set readfds; if ((fd_listen = socket(AF_INET, SOCK_STREAM, 0)) < 0) { alt_NetworkErrorHandler(EXPANDED_DIAGNOSIS_CODE," Socket creation failed"); } addr.sin_family = AF_INET; addr.sin_port = htons(SSS_PORT); //SSS_PORT=30 (simple_socket_server.h) addr.sin_addr.s_addr = INADDR_ANY; if ((bind(fd_listen,(struct sockaddr *)&addr,sizeof(addr))) < 0) { alt_NetworkErrorHandler(EXPANDED_DIAGNOSIS_CODE," Bind failed"); } if ((listen(fd_listen,1)) < 0) { alt_NetworkErrorHandler(EXPANDED_DIAGNOSIS_CODE," Listen failed"); } sss_reset_connection(&conn); printf(" Simple Socket Server listening on port %d\n", SSS_PORT); int cnt=0; sss_handle_accept(fd_listen, &conn); while(1) { sss_handle_receive(&conn); printf("cnt=%d\n\n",++cnt); } /* while(1) */ } - Altera_Forum
Honored Contributor
The laptop client is written under VC++ 6.0.
Note: If don't comment the line"Sleep(100);", the loop will not get hanged, but this will cause time loss, and I can't understand why it should be like this.# include <Winsock2.h> # include <stdio.h> void main() { WORD wVersionRequested; WSADATA wsaData; int err; fd_set rfd,wfd; struct timeval timeout; wVersionRequested = MAKEWORD( 1, 1 ); err = WSAStartup( wVersionRequested, &wsaData ); if ( err != 0 ) { return; } if ( LOBYTE( wsaData.wVersion ) != 1 || HIBYTE( wsaData.wVersion ) != 1 ) { WSACleanup( ); return; } char recvBuf; memset(recvBuf,0,100); char sendbuf; memset(recvBuf,0,100); SOCKET sockClient=socket(AF_INET,SOCK_STREAM,0); SOCKADDR_IN addrSrv; addrSrv.sin_addr.S_un.S_addr=inet_addr("169.254.228.120"); addrSrv.sin_family=AF_INET; addrSrv.sin_port=htons(30); connect(sockClient,(SOCKADDR*)&addrSrv,sizeof(SOCKADDR)); recv(sockClient,recvBuf,100,0); printf("%s\n\n",recvBuf); int cnt=0; while(1){ cnt++; send(sockClient,"1",2,0); printf("1 sent OK!\n\n"); //Sleep(100); recv(sockClient,recvBuf,2,0); printf("%s\nrecieved OK!\ncnt=%d\n\n",recvBuf,cnt); } closesocket(sockClient); WSACleanup(); } - Altera_Forum
Honored Contributor
Probably FIFO buffers are filled up... Nios is VERY slow doing ethernet data transmissions, especially when You use InterNiche and RTOS. Don't expect anything more than 10-15Mbps.
- Altera_Forum
Honored Contributor
--- Quote Start --- Probably FIFO buffers are filled up... Nios is VERY slow doing ethernet data transmissions, especially when You use InterNiche and RTOS. Don't expect anything more than 10-15Mbps. --- Quote End --- Thank you for your reply, Socrates. For me,10-15Mbps is enough, but the speed is much slower than 1Mbps.(I'm using 1000Mbps & full Duplex mode). I ported Benchmark example in AN440 to this hardware design, and found the transmit speed is just 19k/s using TCP. And the transmission can not always get done(sometimes there is send() error). - Altera_Forum
Honored Contributor
Well... did You turn on optimization for Nios in compile parameters?
- Altera_Forum
Honored Contributor
--- Quote Start --- Well... did You turn on optimization for Nios in compile parameters? --- Quote End --- If you mean "-O3", yes , I turned it on. - Altera_Forum
Honored Contributor
The best would be -Os, but still, should be fine... Anyway, I see that You're doing TCP connections, when I remembered, that I've tested UDP streams, when reached ~10Mbps. I'd say that it's just too slow to handle such speeds. What's the Nios CPU frequency and how many MIPS does it show?
- Altera_Forum
Honored Contributor
--- Quote Start --- The best would be -Os, but still, should be fine... Anyway, I see that You're doing TCP connections, when I remembered, that I've tested UDP streams, when reached ~10Mbps. I'd say that it's just too slow to handle such speeds. What's the Nios CPU frequency and how many MIPS does it show? --- Quote End --- The Nios CPU frequency is 62.5Mhz; for "many MIPS does it show", I don't know where to check it. I intend to transmit bmp pictures(about 225kb for each picture), I think it will be cut into smaller packets when transmitting through the net wire, so I choose TCP to guarantee the integrity of the data. By the way, you mentioned "Probably FIFO buffers are filled up...", in my case, do I need a FIFO buffer larger than 225k(currently, my buffer size is 2048 bytes)? - Altera_Forum
Honored Contributor
No, because IP packet size is way much smaller, than 225k.The FIFO is inside TSE MAC. Why don't You use UDP? That's a common protocol for image/video streaming.
- Altera_Forum
Honored Contributor
--- Quote Start --- No, because IP packet size is way much smaller, than 225k.The FIFO is inside TSE MAC. Why don't You use UDP? That's a common protocol for image/video streaming. --- Quote End --- Because I think when using UDP, it's not guaranteed that every small packet will be received, and also the data received may not be correct.