I have a problem connecting to a socket.
It's a server program and client.
Don't complain on the code, I'm just beginer.
Server prog:
Client prog:$line = "Hello, world!\n"; $port = 2000; while (getservbyport ($port, "tcp")) { $port++; } ($d1, $d2, $prototype) = getprotobyname ("tcp"); ($d1, $d2, $d3, $d4, $rawserver) = gethostbyname("silver"); $serveraddr = pack ("Sna4x8", 2, $port, $rawserver); socket (SSOCKET, 2, 1, $prototype) || die ("No socket"); bind (SSOCKET, $serveraddr) || die ("Can't bind");<br> listen (SSOCKET, 1) || die ("Can't listen"); ($clientaddr = accept (SOCKET, SSOCKET)) || die ("Can't accept"); select (SOCKET); $| = 1; print SOCKET ("$line\n"); close (SOCKET); close (SSOCKET);
$port = 2000; while (getservbyport ($port, "tcp")) { $port++; } ($d1, $d2, $prototype) = getprotobyname ("tcp"); ($d1, $d2, $d3, $d4, $rawclient) = gethostbyname ("mercury"); ($d1, $d2, $d3, $d4, $rawserver) = gethostbyname ("silver"); $clientaddr = pack ("Sna4x8", 2, 0, $rawclient); $serveraddr = pack ("Sna4x8", 2, $port, $rawserver); socket (SOCKET, 2, 1, $prototype) || die ("No socket"); bind (SOCKET, $clientaddr) || die ("Can't bind"); connect (SOCKET, $serveraddr); $line = <SOCKET>; print ("$line\n"); close (SOCKET);
When I run server then client prog, server waits for client
, but client print the null line.
Can anybody tell me why it can't connect to the server
programe.
Thanks for any help.(I'm just a biginer)
em.
In reply to problem with SOCKET by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |