Socket closes after data transmission

Hi all,

I am using TCP socket to transmitt the data to server from Wismo.

I set the parameters and call the ed_SocketSetConfig() function. And then I start the socket by

result = ed_SocketTCPStart(ED_ID_TCPSOCKET_1, 0, SocketRspCbk, SocketDataHnd, SocketDataRequest);

now when I send the data, it trasmits correctly but after transmission the socket closes.

Could it be because of the Server closing the socket. Or some problem my side. [I do not have access to the server to check and correct anything]

Thanks for any help,
-J-

Hello -J-,

If your code doesn’t crash and if you get the correct ResponseCode value in your callback routine (SocketRspCbk(…)), then it seems likely that the session is closed by remote server.

The correct ResponseCode value should be:

ED_ERR_DISTANT_TCP_CLOSED_BY_PEER

if the session is closed by remote server.

You could also test the server with a PC tool like a telnet link to the address and port of your server or by using “TCP Test Tool” from http://www.simplecomtools.com, just to see how the servers behaves.

I use this tool myself and I find it very useful.

/Snoooze

Thanks snooze,

Actually i get this message :

ED_OK_TCP_CLOSED

Do you think its a problem with initialization??

-Jiten.

Dont know if this will help my code is as follows (and it does work)

return = ed_SocketTCPStart(ED_ID_TCPSOCKET_1, 0, &tcpResponseHandler, &tcpDataHandler, & tcpDataRequestHandler)

where the functions are declared as follows

void tcpResponseHandler(s32, TeDHandle)
u16 tcpDataHandler(u16, u8 *, TeDHandle)
void tcpDataRequestHandler(u16, TedHandle)

Hi Jiten9,

Could you please check if the third parameter in ed_SendDataExt () function is set to TRUE or FALSE. This is becuase, if you set the third parameter of ed_SendDataExt function to TRUE, then the socket will close after sending the specified data. Only, if you set it to FALSE will the socket remain open after sending the data.

Regards,
OpenAT_Fan.

delene,

I tried this but no change :frowning:

OpenAT_Fan,

This is my code for sending the data thorugh socket:

result = ed_SendDataExt(buffer,bufferLen,FALSE,ED_ID_TCPSOCKET_1);

So this should be fine but it doesnt work.

Actually what I do is I send data thorough sockect on Port 80 which is HTTP protocol based. So could this be a problem like socket closes after data received ?

Thanks again,
-Jiten.

Hi,

I once had the same problem. A web server was closing the port on my request without sending an answer. It turned out that the server didn’t like the formatting of my request. I used \n as line breaks and not \r\n… If you are using unix style line ends (\n) try to use \r\n instead. Maybe this helps…

Best Regards,
Jan

Hi Jiten,
I agree with the point raised by jan. In case, the web server you are trying to send the HTTP request, does not recognise the request (due to incorrect format of request), it (the web server) will close the socket.
You can check the format of request sent by you to the web server.

Regards,
OpenAT_Fan.

Yes I think thats the problem.

I will have to figure it out on the server I use and modify my code as well.

Thanks guys for all the help :slight_smile:

-Jiten.