• 2013-09-05

    A 150 lines comet server written in C

    Views: 8040 | 8 Comments

    Comet is a web application model that used to “push” data to web page(browser), which can be used in applications like Web Chat, News Feed, Stock Market, even Web Game.

    There are many opensourced comet servers, but most big companies develope their own comet server. As we know, Facebook’s comet server is built on Mochiweb, an opensourced Erlang Web server.

    Nginx’s module nginx-push-stream is another solution, but it is suitable for small system, it can not handle 100K+ connections, according to our experiences. A comet should be able to handle 1 million connections.

    Many companies develope their own comet server, for performance, and for integration with existing systems.

    Writing a comet server is very easy with libevent, the famous network library. The simple C comet server is only 150 lines of code, can be down load from here: https://github.com/ideawu/icomet

    Posted by ideawu at 2013-09-05 21:56:21
  • 2013-08-26

    SSDB provided flushdb command

    Views: 7737 | 3 Comments

    SSDB now provided flushdb command, which is used to delete all data in SSDB server. This command is dangerous, so you need to type ‘yes’ on command prompt. This command is implemented via ssdb-cli.

    You can flush only kv, hash, or zset data, with flushdb kv, flushdb hash, flushdb zset.

    There is no need to recompile or restart the SSDB server.

    Posted by ideawu at 2013-08-26 19:14:36
  • 2013-08-15

    Why should I type the full QUIT word to quit a cli application?

    Views: 9256 | No Comments

    Many command-line application ask the user to type in every character of the word “quit” and press Enter to quit the application. But I want to ask the reason why? Why can’t I just type in only the character ‘q’ and press Enter, or press ESC key to quit?

    Actually, many cli application like redis-cli said it received a bad command when user type in ‘q’ and press Enter. So, the ‘q’ command doesn’t map to any other operation. So it is available to map ‘q’ to the quit operation.

    As for the convienience of users, ssdb-cli allow user to type in ‘q’ to quit the application.

    Posted by ideawu at 2013-08-15 14:00:09
  • 2013-08-06

    WebRTC C++ audio recording example

    Views: 23103 | 1 Comment

    The WebRTC project included a voice engine(GIPS, Global IP Solutions), here is an example to show how you can use the voice engine to record audio from microphone.

    #include <stdio.h>
    #include <stdlib.h>
    #include <assert.h>
    #include "webrtc/modules/audio_device/include/audio_device.h"
    #include "webrtc/common_audio/resampler/include/resampler.h"
    #include "webrtc/modules/audio_processing/aec/include/echo_cancellation.h"
    
    class AudioTransportImpl: public webrtc::AudioTransport
    {
    private:
        
    public:
        AudioTransportImpl(webrtc::AudioDeviceModule* audio){
        }
        
        ~AudioTransportImpl(){
        }
    
        virtual int32_t RecordedDataIsAvailable(
            const void* audioSamples,
            const uint32_t nSamples,
            const uint8_t nBytesPerSample,
            const uint8_t nChannels,
            const uint32_t samplesPerSec,
            const uint32_t totalDelayMS,
            const int32_t clockDrift,
            const uint32_t currentMicLevel,
            const bool keyPressed,
            uint32_t& newMicLevel)
        {
            printf("record %d %d %d %d %d %d %d %d\n", nSamples,
                nBytesPerSample, nChannels,
                samplesPerSec, totalDelayMS,
                clockDrift, currentMicLevel, keyPressed);
            // now you have the audioSamples...
            return 0;
        }
    };
    
    
    int main(int argc, char **argv){
        webrtc::AudioDeviceModule *audio;
        audio = webrtc::CreateAudioDeviceModule(0, webrtc::AudioDeviceModule::kPlatformDefaultAudio);
        assert(audio);
        audio->Init();
        
        int num;
        int ret;
        
        num = audio->RecordingDevices();
        printf("Input devices: %d\n", num);
        for(int i=0; i<num; i++){
            char name[webrtc::kAdmMaxDeviceNameSize];
            char guid[webrtc::kAdmMaxGuidSize];
            int ret = audio->RecordingDeviceName(i, name, guid);
            if(ret != -1){
                printf("    %d %s %s\n", i, name, guid);
            }
        }
        
        audio->SetRecordingDevice(0);
        audio->InitRecording();
        
        AudioTransportImpl callback(audio);
        audio->StartRecording();
    
        getchar();
    }
    

    For more webrtc demos, visit: https://github.com/ideawu/webrtc-demo

    Posted by ideawu at 2013-08-06 23:08:32 Tags: ,
  • 2013-07-18

    SSDB now provides very detailed API doc

    Views: 6429 | No Comments

    The new detailed SSDB PHP Client API Documentation is now available. It is at this link: http://www.ideawu.com/ssdb/docs/php/.

    The document looks like this

    zsize
    
    Description
    
    Return the number of pairs of a zset.
    
    Parameters
    
        name - The name of the zset
    
    Return Value
    
    false on error, otherwise an integer of the zset, 0 if the zset does not exist.
    
    Example
    
    $ssdb->zsize('z');
    

    The document is also available in github repository.

    Posted by ideawu at 2013-07-18 21:25:03
|<<<456789101112>>>| 8/19 Pages, 91 Results.