Mac miniで恋するプログラム 邪道編
とりえず邪道編ということでMac miniのほかにWindowsもつかいます。(爆
#! ruby -Ks
require 'unmo'
require 'socket'
def prompt(unmo)
return unmo.name + ':' + unmo.responder_name + '> '
end
Morph::init_analyzer
proto = Unmo.new('proto')
port = 7123 #1
gs = TCPServer.open(port) #2
while true #3
ns = gs.accept #4
p ns.peeraddr
Thread.start(ns) do |s| #5
#printf("> ")
while input = s.gets
#s.write input;
break if /^q/i =~ input
input.chomp!
break if input == ''
printf( "I get :%s\n", input)
response = proto.dialogue(input)
#puts(prompt(proto) + response)
s.write prompt(proto) + response + "\n"
printf('I say :' + response + "\n")
end
s.close
printf("close\n");
@eflag = true;
proto.save
end
break if @eflag == true;
end
use strict;
use encoding 'utf8';
binmode(STDERR, ':raw :encoding(utf8)');
use Encode;
use FileHandle;
use Socket;
use LWP::Simple;
my $remoteHost="192.168.0.2";
my $port = 7123;
my $ip = inet_aton $remoteHost;
my $proto = getprotobyname 'tcp';
socket S, PF_INET, SOCK_STREAM, $proto or
die "socket: $!";
connect S, sockaddr_in($port, $ip)
or die "connect: $!";
S->autoflush(1);
STDOUT->autoflush(1);
#print S "q\n";
my $contents = get('http://updates.cocolog-nifty.com/status/updates.rdf');
my @contents = split /\n/, $contents;
foreach my $text (@contents) {
my $textU = decode('utf8', $text);
#print STDOUT "I say :$textU";
print S encode('shiftjis',"$textU\n");
my $ans = <S>;
print STDOUT decode('shiftjis',$ans);
}
print S "q\n";
print while <S>;
close S or
die "close: $!";
exit;
実はUTF8なFC3でしか動かしてなかったりします。。。