I'm using the following code to send the current service name to a remote server :
-------------------------------------------------------------------------------------------------------------
while(true){
eDVBServiceController *sapi=eDVB::getInstance()->getServiceAPI();
if (sapi)
{
eService *current=eDVB::getInstance()->settings->getTransponders()->searchService(sapi->service);
if (current){
result = current->service_name.c_str();
if(strcmp(result.c_str(),lastService.c_str())){
lastService = result;
int SocketFD = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
memset(&stSockAddr, 0, sizeof(stSockAddr));
stSockAddr.sin_family = AF_INET;
stSockAddr.sin_port = htons(1100);
Res = inet_pton(AF_INET, "192.168.1.100", &stSockAddr.sin_addr);
if(Res<=0){
close(SocketFD);
}
if (-1 == connect(SocketFD, (struct sockaddr *)&stSockAddr, sizeof(stSockAddr)))
{
close(SocketFD);
}
char buf[20];
strcpy(buf,result.c_str());
write(SocketFD,buf,strlen(buf));
shutdown(SocketFD, SHUT_RDWR);
close(SocketFD);
}
}
}
usleep(10000);
}
-------------------------------------------------------------------------------------------------------------------
After receiving the first data my dreambox becomes not stable. Is there any mistakes within this code or should I use the eSocket API instead. In this case please point me to a sample using this API in the client side.
Is there any example using eSocket in a client side
Started by hyperonex, 26 Apr 2011 23:45
9 replies to this topic
Re: Is there any example using eSocket in a client side #2
Posted 27 April 2011 - 08:23
You are convinced a service_name is never longer than 20 chars? (That might be only I don't know).
You shouldn't shutdown a socket before you close it. You probably shouldn't shutdown the connection at all.
A good guide to networking: http://beej.us/guide...ml#simpleclient with answers to all your all your questions .
Are you programming for enigma1 or enigma2?
You shouldn't shutdown a socket before you close it. You probably shouldn't shutdown the connection at all.
A good guide to networking: http://beej.us/guide...ml#simpleclient with answers to all your all your questions .
Are you programming for enigma1 or enigma2?
Re: Is there any example using eSocket in a client side #3
Re: Is there any example using eSocket in a client side #4
Posted 27 April 2011 - 10:04
You shouldn't shutdown a socket before you close it. You probably shouldn't shutdown the connection at all.
you should not have to indeed.
shutdown is normally only useful for half-close (to trigger the peer to send its reply).
But it does not hurt to call shutdown, even with RDWR.
If a socketdescriptor has been cloned (by fork for example), and you want to make sure the connection is closed, you have to call shutdown before you close (your copy of) the socket. (as close would only lower the refcount, and not actually close the TCP connection)
But this is not related to your problem I guess
Re: Is there any example using eSocket in a client side #5
Posted 27 April 2011 - 10:12
-you should handle EINPROGRESS errno on connect (it will certainly occur, when connecting to anything but your own machine)
-you should break out of the loop when an error occurred (and you closed the socket descriptor)
-what context is this code running? It is normally not a good idea to start an endless loop in somebody else's context
-you should break out of the loop when an error occurred (and you closed the socket descriptor)
-what context is this code running? It is normally not a good idea to start an endless loop in somebody else's context
Re: Is there any example using eSocket in a client side #6
Posted 27 April 2011 - 11:30
I'm programming a plugin for an enigma1 box (dm500).
1- Can you please tell me how to handle this EINPROGRESS errno (Should I test on the retuned value of the connect function As I do with the -1 returned value ?)
2- I want to remove the endless loop, indeed, by performing sending data when the user sap into another service? How to do it !!!
1- Can you please tell me how to handle this EINPROGRESS errno (Should I test on the retuned value of the connect function As I do with the -1 returned value ?)
2- I want to remove the endless loop, indeed, by performing sending data when the user sap into another service? How to do it !!!
Re: Is there any example using eSocket in a client side #7
Posted 27 April 2011 - 11:47
1. if connect returns < 0, check errno.
However, I now see you have a blocking socket, so connect will not return EINPROGRESS in your case. (only disadvantage is that with a blocking connect you have no control over the connect timeout, so you might end up blocking for 5 minutes)
2.it has been a while since I worked with enigma. But I'm quite sure there are examples of connecting a signal to a service started event or something similar.
Check the osd code for instance; several osd fields are updated when the current service changes.
However, I now see you have a blocking socket, so connect will not return EINPROGRESS in your case. (only disadvantage is that with a blocking connect you have no control over the connect timeout, so you might end up blocking for 5 minutes)
2.it has been a while since I worked with enigma. But I'm quite sure there are examples of connecting a signal to a service started event or something similar.
Check the osd code for instance; several osd fields are updated when the current service changes.
Re: Is there any example using eSocket in a client side #8
Re: Is there any example using eSocket in a client side #9
Re: Is there any example using eSocket in a client side #10
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users