[問題] 請問一下Server-Client的問題
其實我是完完全全的新手
底下只要看的到的程式都是改編自版主的XD (版主歹是 喔 囧)
話說我想要做的是這樣
Server提供一個可寫入的陣列(整數~size=10)
Client可以讀也可以寫
但是一次只能有一個寫入~讀取可以有多個
其實我也不知道我在寫啥XD
但是東拼西湊出來的東西如下
但是似乎就是沒有辦法去確認Server是不是正確的讀取了Client的東西
還是只是client print自己的array :(
#!/usr/bin/perl
#Server
use threads;
use IO::Socket;
my $server = IO::Socket::INET->new(
LocalPort => 8088,
Type => SOCK_STREAM,
Listen => 32,
Reuse =>1
);
my @array = ();
while(my $client = $server->accept() ) {
threads->create( "client_handler", $client);
}
sub client_handler {
my $client = shift;
while(<$client>) {
push( @array, $_ );
}
print $client foreach( @array );
$client->shutdown(1);
$client->close();
}
#!/usr/bin/perl
#Client
use IO::Socket;
my $client = IO::Socket::INET->new(
PeerAddr => "127.0.0.1",
PeerPort => 8088);
my @array = ();
my $element = 0;
while( $element != 10 ){
for ( 1 .. 10 ) {
push( @array, $element ); }
$element++;
}
print "$_\n" foreach( @array );
print $client foreach( @array );
while(<$client>) { print;}
$client->close();
因為完全不會寫程式
所以這段話有點不懂
Each read/write thread should perform a busy loop
incrementing a local variable from 0 to 2,000,000
before actually doing the reading or the writing of the
shared array. Make sure that you put this loop inside
the critical section of the thread. This simulates longer
service and will therefore introduce more contention for
the resource.
busy loop 是啥米??
好像是很重要的一段話
但是怎麼也看不懂:(
要儲存離開又不自覺的按下esc 然後 : 然後 wq! 了
那ㄟ安ㄋㄟ?!
--
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 211.72.195.107
推
04/13 19:46, , 1F
04/13 19:46, 1F
推
04/13 19:46, , 2F
04/13 19:46, 2F
推
04/13 19:47, , 3F
04/13 19:47, 3F
推
04/13 19:48, , 4F
04/13 19:48, 4F
推
04/13 19:48, , 5F
04/13 19:48, 5F
推
04/13 19:49, , 6F
04/13 19:49, 6F
推
04/13 19:51, , 7F
04/13 19:51, 7F
推
04/13 19:51, , 8F
04/13 19:51, 8F
推
04/13 19:52, , 9F
04/13 19:52, 9F
→
04/13 19:59, , 10F
04/13 19:59, 10F
討論串 (同標題文章)
完整討論串 (本文為第 1 之 3 篇):
Perl 近期熱門文章
PTT數位生活區 即時熱門文章