langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
|
|
@ -0,0 +1,23 @@
|
|||
open Printf
|
||||
|
||||
let create_logger () =
|
||||
def log(text) & logs(l) =
|
||||
printf "Logged: %s\n%!" text;
|
||||
logs((text, Unix.gettimeofday ())::l) & reply to log
|
||||
|
||||
or search(text) & logs(l) =
|
||||
logs(l) & reply List.filter (fun (line, _) -> line = text) l to search
|
||||
in
|
||||
spawn logs([]);
|
||||
(log, search)
|
||||
|
||||
def wait() & finished() = reply to wait
|
||||
|
||||
let register name service = Join.Ns.register Join.Ns.here name service
|
||||
|
||||
let () =
|
||||
let log, search = create_logger () in
|
||||
register "log" log;
|
||||
register "search" search;
|
||||
Join.Site.listen (Unix.ADDR_INET (Join.Site.get_local_addr(), 12345));
|
||||
wait ()
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
open Printf
|
||||
|
||||
let ns_there = Join.Ns.there (Unix.ADDR_INET (Join.Site.get_local_addr(), 12345))
|
||||
|
||||
let lookup name = Join.Ns.lookup ns_there name
|
||||
|
||||
let log : string -> unit = lookup "log"
|
||||
let search : string -> (string * float) list = lookup "search"
|
||||
|
||||
let find txt =
|
||||
printf "Looking for %s...\n" txt;
|
||||
List.iter (fun (line, time) ->
|
||||
printf "Found: '%s' at t = %f\n%!" (String.escaped line) time)
|
||||
(search txt)
|
||||
|
||||
let () =
|
||||
log "bar";
|
||||
find "foo";
|
||||
log "foo";
|
||||
log "shoe";
|
||||
find "foo"
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
#import <Foundation/Foundation.h>
|
||||
// our protocol allows "sending" "strings", but we can implement
|
||||
// everything we could for a "local" object
|
||||
@protocol ActionObjectProtocol
|
||||
- (NSString *)sendMessage: (NSString *)msg;
|
||||
@end
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
#import <Foundation/Foundation.h>
|
||||
#import "ActionObjectProtocol.h"
|
||||
|
||||
@interface ActionObject : NSObject <ActionObjectProtocol>
|
||||
// we do not have much for this example!
|
||||
@end
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
#import <Foundation/Foundation.h>
|
||||
#import "ActionObject.h"
|
||||
|
||||
@implementation ActionObject
|
||||
-(NSString *)sendMessage: (NSString *)msg
|
||||
{
|
||||
NSLog(@"client sending message %@", msg);
|
||||
return @"server answers ...";
|
||||
}
|
||||
@end
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
#import <Foundation/Foundation.h>
|
||||
#import "ActionObject.h"
|
||||
|
||||
int main (void)
|
||||
{
|
||||
NSAutoreleasePool *pool;
|
||||
ActionObject *action;
|
||||
NSConnection *connect;
|
||||
NSSocketPort *port;
|
||||
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
action = [[ActionObject alloc] init];
|
||||
|
||||
port = (NSSocketPort *)[NSSocketPort port];
|
||||
// initWithTCPPort: 1234 and other methods are not supported yet
|
||||
// by GNUstep
|
||||
connect = [NSConnection
|
||||
connectionWithReceivePort: port
|
||||
sendPort: port]; // or sendPort: nil
|
||||
|
||||
[connect setRootObject: action];
|
||||
|
||||
/* "vend" the object ActionObject as DistributedAction; on GNUstep
|
||||
the Name Server that allows the resolution of the registered name
|
||||
is bound to port 538 */
|
||||
if ([connect registerName:@"DistributedAction"
|
||||
withNameServer: [NSSocketPortNameServer sharedInstance] ] == NO)
|
||||
{
|
||||
NSLog(@"can't register the server DistributedAction");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
NSLog(@"waiting for messages...");
|
||||
|
||||
[[NSRunLoop currentRunLoop] run];
|
||||
|
||||
[pool release];
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
#import <Foundation/Foundation.h>
|
||||
#import "ActionObjectProtocol.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
NSAutoreleasePool *pool;
|
||||
NSArray *args;
|
||||
id <ActionObjectProtocol> action;
|
||||
NSString *msg, *backmsg;
|
||||
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
action = (id <ActionObjectProtocol>)
|
||||
[NSConnection
|
||||
rootProxyForConnectionWithRegisteredName: @"DistributedAction"
|
||||
host: @"localhost"
|
||||
usingNameServer: [NSSocketPortNameServer sharedInstance] ];
|
||||
|
||||
if (action == nil)
|
||||
{
|
||||
NSLog(@"can't connect to the server");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
args = [[NSProcessInfo processInfo] arguments];
|
||||
|
||||
if ([args count] == 1)
|
||||
{
|
||||
NSLog(@"specify a message");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
msg = [args objectAtIndex: 1];
|
||||
|
||||
// "send" (call the selector "sendMessage:" of the (remote) object
|
||||
// action) the first argument's text as msg, store the message "sent
|
||||
// back" and then show it in the log
|
||||
backmsg = [action sendMessage: msg];
|
||||
NSLog("%@", backmsg);
|
||||
|
||||
[pool release];
|
||||
return 0;
|
||||
}
|
||||
40
Task/Distributed-programming/Oz/distributed-programming.oz
Normal file
40
Task/Distributed-programming/Oz/distributed-programming.oz
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
declare
|
||||
functor ServerCode
|
||||
export
|
||||
port:Prt
|
||||
define
|
||||
Stream
|
||||
Prt = {NewPort ?Stream}
|
||||
thread
|
||||
for Request#Reply in Stream do
|
||||
case Request
|
||||
of echo(Data) then Reply = Data
|
||||
[] compute(Function) then Reply = {Function}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
%% create the server on some machine
|
||||
%% (just change "localhost" to some machine
|
||||
%% that you can use with a passwordless rsh login
|
||||
%% and that has the same Mozart version installed)
|
||||
RM = {New Remote.manager init(host:localhost)}
|
||||
|
||||
%% execute the code encapsulated in the ServerCode functor
|
||||
Server = {RM apply(ServerCode $)}
|
||||
|
||||
%% Shortcut: send a message to Server and receive a reply
|
||||
fun {Send X}
|
||||
{Port.sendRecv Server.port X}
|
||||
end
|
||||
in
|
||||
%% echo
|
||||
{System.showInfo "Echo reply: "#{Send echo(hello)}}
|
||||
|
||||
%% compute
|
||||
{System.showInfo "Result of computation: "#
|
||||
{Send compute(fun {$} 8 div 4 end)}}
|
||||
|
||||
%% shut down server
|
||||
{RM close}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
: >/tmp/buffer
|
||||
tail -f /tmp/buffer | nc -l 127.0.0.1 1234 | sh >/tmp/buffer 2>&1
|
||||
|
|
@ -0,0 +1 @@
|
|||
nc 127.0.0.1 1234
|
||||
Loading…
Add table
Add a link
Reference in a new issue