I want to get a test server going. The client will recv an xml file from one socket. When the that is read in it then sends an xml to a receiving socket. These two sockets have different ports but should be the same address. So far the sending works but the revcing seems to not get anything. Any ideas?
#!/usr/bin/perl -w use strict; use IO::Socket; use File::Slurp; use threads; my $socket=new IO::Socket::INET->new(PeerPort=>12345,Proto=>'udp',Peer +Addr=>'localhost'); print "This is a test Sending Server\n"; my $capxml = read_file("C:\\Users\\deadpickle\\Desktop\\UAS\\GRRUVI_1. +60\\test xml\\capabilities.xml"); my $recv = threads->new(\&recvxml); my $send = threads->new(\&sendxml); while(1){ } sub sendxml{ my $socket=new IO::Socket::INET->new(PeerPort=>12345,Proto=>'udp', +PeerAddr=>'localhost'); while (1) { #send capabilities every 10 seconds $socket->send($capxml); print "Sending Capabilities\n"; sleep 10; } } sub recvxml{ my $xml; my $socket=new IO::Socket::INET->new(PeerPort=>56789,Proto=>'udp', +PeerAddr=>'localhost'); while(1) { print "Waiting for meassage\n"; $socket->recv($xml,3000); print "Recieved Message: $xml\n"; } }
with the section of the client that sends the xml file(the real program is 2000+ lines, not forum friendly):
sub sendxml { $SIG{PIPE} = "IGNORE"; $\="\n"; ##variables my $subscribe; my $count = 29; my $waypoints; my $path; my $xmlcoords; #my $send_client = IO::Socket::INET->new( PeerAddr => $sendnode, P +roto => 'tcp') or $error = 4; my $send_client = new IO::Socket::INET->new(LocalPort=>56789,Proto +=>'udp') or $error = 3; #for testing if ($send_client){ print "$subflag $planflag $verify"; if ($subflag == 3) { $astream = 'Telemetry'; #for testing $subscribe = <<XML; <?xml version="1.0" encoding="UTF-8"?> <StreamSubscribe xsi:schemaLocation="http://StreamSubscribe.CUIntegrat +ion.com stream_subscription.xsd" xmlns="http://StreamSubscribe.CUInte +gration.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <VehicleID>$vid</VehicleID> <System> <ID>Autopilot</ID> <Stream>$astream</Stream> <Action>Subscribe</Action> </System> </StreamSubscribe> XML print "Subscribe: $subscribe\n"; #$send_client->send($subscribe); $send_client->send($subscribe,0,'localhost:56789'); #for + testing $subflag = 4; } if ($verify == 4) { my @handlecoords = split(/\n/,$coords); foreach my $kid(@handlecoords) { $count++; print "$kid\n"; my @split = split(/,/,$kid); #$xmlcoords.="\n" if $count > 31; $xmlcoords.=" <Waypoint Latitude=\"$split[0]\" Longi +tude=\"$split[1]\" SequenceNumber=\"$count\"/>\n"; } $path = 'Loiter' if $count == 30; $path = 'Path' if $count >= 31; my $waypoints = <<XML; <?xml version="1.0" encoding="UTF-8"?> <Task xmlns="http://Task.CUIntegration.com" xmlns:xsi="http://www.w3.o +rg/2001/XMLSchema-instance" xsi:schemaLocation="http://Task.CUIntegra +tion.com Task.xsd "> <ID>ID</ID> <Type>$path</Type> <Destination>$vid</Destination> $xmlcoords </Task> XML print "$waypoints\n"; $send_client->send($waypoints); $count_waypoint = $count_waypoint + 0.1; $verify = 0; } if ($planflag == 2) { $astream = 'Flight Plan'; #for testing $subscribe = <<XML; <?xml version="1.0" encoding="UTF-8"?> <StreamSubscribe xsi:schemaLocation="http://StreamSubscribe.CUIntegrat +ion.com stream_subscription.xsd" xmlns="http://StreamSubscribe.CUInte +gration.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <VehicleID>$vid</VehicleID> <System> <ID>Autopilot</ID> <Stream>$astream</Stream> <Action>Subscribe</Action> </System> </StreamSubscribe> XML print "Subscribe: $subscribe\n"; #$send_client->send($subscribe); $send_client->send($subscribe,0,'localhost:56789'); #for + testing $planflag = 3; #exit; } } undef $send_client; }

In reply to UDP recv by deadpickle

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.