[Libwebsockets] Hello andy or anyone i am in need of help.

Andy Green andy at warmcat.com
Tue Jan 27 13:19:42 CET 2015



On 27 January 2015 08:40:16 GMT+08:00, "Genusis Andrew ." <lordsatin at hotmail.com> wrote:
>> Subject: Re: Hello andy or anyone i am in need of help.
>> From: andy at warmcat.com
>> Date: Tue, 27 Jan 2015 08:13:26 +0800
>> To: lordsatin at hotmail.com; libwebsockets-owner at ml.libwebsockets.org;
>libwebsockets at ml.libwebsockets.org
>> 
>> 
>> 
>> On 27 January 2015 06:16:01 GMT+08:00, "Genusis Andrew ."
><lordsatin at hotmail.com> wrote:
>> >not sure what email to send this to but i am currently having issues
>> >sending data to a web server i am connecting too. I do not know what
>> >kind of socket the web server uses but apparently im having issues
>> >sending and receiving anything bigger than a ping. I have tried
>several
>> 
>> So you can establish a websocket connection okay... that's something.
>> 
>> >methods shown in tutorials etc none of them work. Currently i am
>trying
>> >to connect to hitbox.tv to make a chat bot for them and they require
>> >the use of a web socket so i decided to use yours however i can't
>get
>> >it to fully work..... maybe you can review my code and tell me what
>i
>> >need to do to properly send data and act as a client to their web
>> >server which sends and receives data via port 80.
>> >
>> >http://pastebin.com/jdHbicUi
>> >
>> >this is the above libwebsockets code i am using which is not working
>> >correctly. Hopefully you can help me so i can get this bot up and
>> >running as i'm converting this down from a C# bot which can't handle
>> >the load.
>> >
>> >Please let me know if you can help me =[.
>> 
>> Look again at the test client main loop.
>> 
>> After you initialize the context, you must sit in a "service loop" to
>make lws work.
>> 
>> Actually when you ask for the client connection, it returns after
>starting the connection process.  You don't become connected until
>later, in the service loop, and the various callbacks occur from the
>service loop.
>>  		 	   		   		 	   		  
>> You don't seem to have any service loop.
>> 
>> -Andy
>
>#include <socket.h>
>#include <channels.h>
>#include <swift/time.h>
>#include <signal.h>
>
>static int force_exit;
>
>static void sighandler(int sig)
>{
>    force_exit = 1;
>}
>
>int main(void)
>{
>    mb_socket_t test;
>
>    fprintf(stderr,
>      ":::::MeowBot Kicking ass since when dinasuars laid eggs::::\n");
>
>    signal(SIGINT, sighandler);
>
>    if (!mb_init_socket(&test)) {
>        fprintf(stderr, "socket did not work\n");
>        swift_timed_wait(SWIFT_TIME(.s = 25));
>        return 1;
>    }
>
>    while (mb_update_socket(&test) >=0 && !force_exit);
>
>    fprintf(stderr, "meowbot exited cleanly\n");
>    mb_unload_socket(&test);
>    swift_timed_wait(SWIFT_TIME(.s = 25));
>    return 0;
>}
>
>this is the main c file that calls the socket protocols. if you see
>anything wrong let me know? but i think what you ment was 
>   while (mb_update_socket(&test) >=0 && !force_exit);
>
>which called mb_update_socket(&test) which has
>
>int mb_update_socket(mb_socket_t *sock){        struct timeval tv;     
>static int rate_us = 250000;        static unsigned int oldus = 0;     
>gettimeofday(&tv, NULL);         if (((unsigned int)tv.tv_usec - oldus)
>> rate_us) {               
>libwebsocket_callback_on_writable_all_protocol(&proto[0]);         

This bit looks copied from the test server, he will force all the connections to get a WRITABLE callback at 4Hz or as close to that as they actually become writeable.

It it's what you want then fine.
    
>oldus = tv.tv_usec;        }         return
>libwebsocket_service(sock->context, 10);}
>
>so i have no idea what im doing wrong....
>
>Currently the socket is only receiving 1:: and 2:: it hasn;t gotten
>anything else and it should have sent out the json file as it says it
>sent 256bytes of data after the write was called..

I think I'd use tcpdump to check what's going out (transmitted ws data is munged with an XOR key though).

If you control the server you're connecting to, make him dump what he receives, and check what your lws client does in the dumps compared to the old client.

-Andy

>
> 		 	   		   		 	   		  




More information about the Libwebsockets mailing list