[zeromq-dev] [NEWBIE] Delphi wrapper for zeromq and some other issue...

Daniele Teti d.teti at bittime.it
Sun Jul 19 22:54:25 CEST 2009


Sure!

This is my Delphi Test project.

In the attached test I cannot read any data in the queue...

I dont know if problem is in my implementation or in my Delphi wrapper, 
so I'm build a similar project in C# (Wrapper is already here 
http://svn.fastmq.org/svn/zeromq/branches/v1.0.0/libclrzmq/zmq.cs).

This is my C# Code:

SENDER:
        static void Main(string[] args)
        {
            Zmq zmq = new Zmq("localhost");   
            int ex = 
zmq.CreateExchange("E",Zmq.SCOPE_GLOBAL,"*",Zmq.STYLE_DATA_DISTRIBUTION);    
       
            int i = 0;       
            while (true)
            {
                string data = "Hello World";
                Console.WriteLine("sending {0}",data);
                zmq.Send(ex, StrToByteArray(data), false);
                Thread.Sleep(1000);
                i++;
            }
        }

        static byte[] StrToByteArray(string str)
        {
            System.Text.ASCIIEncoding encoding = new 
System.Text.ASCIIEncoding();
            return encoding.GetBytes(str);
        }


RECEIVER:
        static void Main(string[] args)
        {
            Zmq zmq = new Zmq("localhost");           
            zmq.CreateQueue("MyQueue", Zmq.SCOPE_GLOBAL, "*", 
Zmq.NO_LIMIT,Zmq.NO_LIMIT,Zmq.NO_SWAP);
            zmq.Bind("E","MyQueue","","");
           
            while (true)
            {   
                byte[] barray = null;
                int atype;
                zmq.Receive(out barray,out atype, false);
                Console.WriteLine("Readed {0}", 
ByteArrayToStr(barray));  //dont print "Hello Word" but an empty string :-(
                Thread.Sleep(1000);               
            }
        }

        static string ByteArrayToStr(byte[] str)
        {
            System.Text.ASCIIEncoding encoding = new 
System.Text.ASCIIEncoding();
            return encoding.GetString(str);
        }



I'm on Windows Vista and run zmq_server.exe without parameters, but 
cannot read any data... :-(

Thanks for your help.



Logo bitTime* Daniele Teti
/R&D Director & Educational
/*/mobile: +39 349 6626822/
*
bit Time Software S.r.l.
*Embarcadero Representative in Italy

--------------------------------------------------------------------------
Via Matteotti, 18,  00044 -- Frascati (RM)
Tel : +39 06 97245050  Fax: +39 06 97245050
http://www.bittime.it <http://www.bittime.it/>  http://www.codegear.it 
<http://www.codegear.it/>



Marcelo Campos Rocha wrote:
>
> Hi Daniele,
>
> You can submit your Delphi Wrapper, so we make sure it is correct?
>
> Marcelo
>
> 2009/7/17 Daniele Teti <d.teti at bittime.it <mailto:d.teti at bittime.it>>
>
>     Hi all,
>
>
>     I'm a zeromq newbie.
>
>     When I start zmq_server.exe (windows Vista or XP) I cannot see any
>     info from the server.
>     Where are the server logs?
>     I've written a small delphi wrapper for zeromq, but client raise
>     an Access Violation.
>
>     I really need use zeromq from Delphi.
>
>     Can someone help me? How I can do some server side debug? and from
>     client side?
>      
>     This is my delphi code
>
>     program Test0MQ;
>
>     {$APPTYPE CONSOLE}
>
>     uses
>       SysUtils,
>       ZMQ in 'ZMQ.PAS';
>
>     var
>       _object, data: Pointer;
>       message: Pointer;
>       msg: string;
>       message_size: Int64;
>       eid, qid: Integer;
>       outtype: UINT32_T;
>     begin
>       try
>         _object := zmq_create('10.5.1.91:5682');
>         eid := zmq_create_exchange (_object, 'E', ZMQ_SCOPE_LOCAL, '',
>     ZMQ_STYLE_DATA_DISTRIBUTION);
>         zmq_bind (_object, 'E', 'Q', nil, 'MyQueue');
>         message_size := 4;
>         message := GetMemory(message_size);
>         StrCat(message, 'ciao');
>         zmq_send (_object, eid, message, message_size, ZMQ_TRUE);
>         FreeMem(message);
>         zmq_destroy(_object);
>         WriteLn('Memoria liberata');
>       except
>         on E:Exception do
>           Writeln(e.Message);
>       end;
>
>       Write('Reading...');
>       try
>         _object := zmq_create('10.5.1.91:5682');
>         qid := zmq_create_queue (_object, 'Q', ZMQ_SCOPE_GLOBAL, '*',
>     ZMQ_NO_LIMIT, ZMQ_NO_LIMIT, ZMQ_NO_SWAP);
>         zmq_bind (_object, 'E', 'Q', 'MyQueue', nil);
>         message_size := 0;
>         message := GetMemory(message_size);
>         data:=nil;
>         zmq_receive(_object, data, message_size, outtype, ZMQ_TRUE);
>         FreeMem(message);
>         zmq_destroy(_object);
>         WriteLn('Memoria liberata');
>       except
>         on E:Exception do
>           Writeln(e.Message);
>       end;
>       Write('Fine...');
>
>
>
>       readln;
>     end.
>
>
>
>
>     Thanks a lot
>
>
>     -- 
>     Daniele Teti
>     R&D Director & Educational
>     bit Time Software
>     www.bittime.it <http://www.bittime.it>
>     www.danieleteti.it <http://www.danieleteti.it>
>     www.codegear.it <http://www.codegear.it>
>
>
>     _______________________________________________
>     zeromq-dev mailing list
>     zeromq-dev at lists.zeromq.org <mailto:zeromq-dev at lists.zeromq.org>
>     http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20090719/498bf982/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/gif
Size: 1279 bytes
Desc: not available
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20090719/498bf982/attachment.gif>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: DelphiZeroMQTest.zip
Type: application/zip
Size: 2063 bytes
Desc: not available
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20090719/498bf982/attachment.zip>


More information about the zeromq-dev mailing list