Results 1 to 5 of 5

Thread: [SRL(OSR)] Sockets & IRC

  1. #1
    Join Date
    Nov 2013
    Posts
    7
    Mentioned
    0 Post(s)
    Quoted
    6 Post(s)

    Default [SRL(OSR)] Sockets & IRC

    Hi all,

    I'm going to create an interaction between IRC <-> RS client using SRL and the socket module. I'm pretty familiar with sockets and have been using them in many languages. I now just need some details to implement them on the correct way using the Socket modole which is in the SRL package. So far, this is my code (excuse me for the hard coding of the sockets, it's fine for now);

    Code:
    program new;
    {$i SRL-OSR/srl.simba}
    
    function ConnectIRC(server, port : String, timeout : Integer) : Integer
      var
        ssid : Integer;
      begin
        //Create socket, connect to socket and set a specified timeout
        ssid := CreateSocket;
        ConnectSocket(ssid, server, port);
        SetSocketTimeout(ssid, timeout);
        //Wait for the connection and after that send first IDENT respnse
        Wait(5000);
        SendSocket(ssid, 'USER doornder 8 * :doornder' + (#13#10));
        SendSocket(ssid, 'USERHOST doornder 8 * :doornder' + (#13#10));
        SendSocket(ssid, 'NICK doornder' + (#13#10));
        Wait(1000);
        WriteLn(RecvSocket(ssid));
        Result := ssid;
      end
    
    procedure JoinChan(ssid: Integer, channel : String)
      begin
        SendSocket(ssid, 'JOIN '+ channel + (#13#10));
      end
    
    procedure Loop(ssid : Integer)
      var
        active : Boolean;
        data : String;
    
      begin
        active := True;
    
        repeat
          //All handling for PING, PONG, incoming message for IRC here..
          Wait(200);
          //Try to read data and check if empty??..
          data := RecvSocket(ssid);
    
        until active = false;
      end
    
    var
      socketid = Integer;
    begin
      socketid := ConnectIRC('irc.freenode.net', '6667');
      JoinChan('#simbabot');
      Loop(socketid);
    end.
    Now I need to both interact with the IRC server and with the client of RS. Since there is no multithreading/asynchronous approach (yet?) I have to think about something else. For people not knowing the IRC protocol; the only real requirement of IRC is to react on PING send by the server. Currently I don't really have an idea about how to do this.. I was thinking of about looping every 200ms (just using a repait + wait(x)) and then using RecvSocket (which doesn't block right? no data -> empty string?) to check if there is data. If there is no I don't need to bother with it. Is this a good strategy? Or do you people have any other ideas how to approach this problem? Last but not least, are there any good string handling modules for Pascal/LAPE? (Tried google, no results) I'm looking for functions such as Split(delimeter).

    Thank you in advance!

    wptmdoorn

  2. #2
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    995
    Mentioned
    145 Post(s)
    Quoted
    596 Post(s)

    Default

    RecvSocket (which doesn't block right? no data -> empty string?)
    How is that supposed to work? It has to block, else you will loose data.

    Pumbaa has a few string commands, including such as split(delimiter) (explode in pumbaa).. see: http://github.com/Janilabo/pumbaa/tr...ter/src/string

    You could try writing the irc-part in Free Pascal, using a second thread to constantly fetch the data from irc, and store it in a string. Connect a few functions to it so you can later on from Simba read and process the received input. And generate a response based on it, which you would pass back to the plugin.
    !No priv. messages please

  3. #3
    Join Date
    Nov 2013
    Posts
    7
    Mentioned
    0 Post(s)
    Quoted
    6 Post(s)

    Default

    Quote Originally Posted by warpie View Post
    How is that supposed to work? It has to block, else you will loose data.

    Pumbaa has a few string commands, including such as split(delimiter) (explode in pumbaa).. see:

    You could try writing the irc-part in Free Pascal, using a second thread to constantly fetch the data from irc, and store it in a string.
    Connect a few functions to it so you can later on from Simba read and process the received input. And generate a response based on it, which you would pass back to the plugin.
    Then I didn't read the documentation properly, excuse me. So within Simba there is no possibility of non-blocking I/O? Thank you, I will read upon that topic and hopefully I'll find an approach.

  4. #4
    Join Date
    Oct 2011
    Posts
    805
    Mentioned
    21 Post(s)
    Quoted
    152 Post(s)

  5. #5
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    995
    Mentioned
    145 Post(s)
    Quoted
    596 Post(s)

    Default

    Quote Originally Posted by wptmdoorn View Post
    Then I didn't read the documentation properly, excuse me. So within Simba there is no possibility of non-blocking I/O? Thank you, I will read upon that topic and hopefully I'll find an approach.
    I did not say it didn't work the way you need it to work. I just implied that it probably don't.
    It has to somehow continiously read the buffer, and never take a break.
    !No priv. messages please

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •