Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Transmit file over socket

by Roger (Parson)
on Jan 20, 2004 at 07:17 UTC ( [id://322524]=note: print w/replies, xml ) Need Help??


in reply to Transmit file over socket

I think your server has a logic error. Consider your code:
... print "Got: $in\n"; if ($in =~ /#:#$/) { ... } elsif ($in =~ /_$/) { ... } elsif ($in =~ /__END$/) { ... } else { ... # save file }
For the following input data:
Got: X-Call~4.xml#:#380_<?xml version="1.0"?>
Your logic will never get to the save file bit correctly, it will (almost) always fall inside the $in =~ /_$/ block and not saving the xml header correctly.


You probably want something like this instead:
if ($in =~ /__END$/) { # close previous file } else { ($filename, $filesize) = $in =~ /^([^#]+)#:#(\d+)_/; if ($filename) { # create new file } # proceed with saving the file }

Replies are listed 'Best First'.
Re: Re: Transmit file over socket
by AcidHawk (Vicar) on Jan 20, 2004 at 07:27 UTC

    I will look into this - thank you. However, for the first file the filename and size are seperate (which is what I was looking for.. only for the second and following files that get processed are the filename and size and first line concatonated onto the same line. I suspect some kind buffering issue..?

    -----
    Of all the things I've lost in my life, its my mind I miss the most.
      Could be. Thinking about the client/server program again, I would probably use the Net::TCP::Server module to implement the server. Much easier.
      use strict; use warnings; use Net::TCP::Server; # create listener my $lh = 'Net::TCP::Server'->new(8000) or die; while (my $sh = $lh->accept) { defined(my $pid=fork) or die "fork: $!\n"; if ($pid) { # parent doesn't need client fh $sh->stopio; next; } # child doesn't need listener fh $lh->stopio; # do per-connection stuff here # read from the socket exit; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://322524]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-04-25 09:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found