Hello, powerfull monks.

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:

$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);
Client prog:

$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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.