SRL Archive - OSR Help

[SRL(OSR)] Sockets & IRC


wptmdoorn

2013-11-09 04:40:45

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

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

slacky

2013-11-09 05:09:17

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/tree/master/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.

wptmdoorn

2013-11-09 05:54:30

From: warpie
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.

bg5

2013-11-09 08:33:42

I'm looking for functions such as Split(delimeter)


http://docs.villavu.com/simba/scriptref/string.html#explode

slacky

2013-11-09 20:25:02

From: wptmdoorn
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.