Jump to content


Photo

Is there any example using eSocket in a client side


  • Please log in to reply
9 replies to this topic

#1 hyperonex

  • Senior Member
  • 82 posts

+7
Neutral

Posted 26 April 2011 - 23:45

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.

Re: Is there any example using eSocket in a client side #2 Sjaaky

  • Senior Member
  • 7,443 posts

+41
Good

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?

Re: Is there any example using eSocket in a client side #3 hyperonex

  • Senior Member
  • 82 posts

+7
Neutral

Posted 27 April 2011 - 09:38

I'm programming for enigma1.
By the way I have tried with shutting down the socket but i face the same problem !!!

Re: Is there any example using eSocket in a client side #4 pieterg

  • PLi® Core member
  • 32,766 posts

+245
Excellent

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 pieterg

  • PLi® Core member
  • 32,766 posts

+245
Excellent

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 ;)

Re: Is there any example using eSocket in a client side #6 hyperonex

  • Senior Member
  • 82 posts

+7
Neutral

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 !!!

Re: Is there any example using eSocket in a client side #7 pieterg

  • PLi® Core member
  • 32,766 posts

+245
Excellent

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.


Re: Is there any example using eSocket in a client side #8 hyperonex

  • Senior Member
  • 82 posts

+7
Neutral

Posted 27 April 2011 - 12:34

Thanks pieterg. just one last question please can you give me the path of the OSD implementation!

Re: Is there any example using eSocket in a client side #9 pieterg

  • PLi® Core member
  • 32,766 posts

+245
Excellent

Posted 27 April 2011 - 14:31

from what I remember from enigma(1), 'everything' is in enigma_main.cpp, so start there...

Re: Is there any example using eSocket in a client side #10 hyperonex

  • Senior Member
  • 82 posts

+7
Neutral

Posted 28 April 2011 - 08:36

Thanks


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users