Question

I am working on a small assignment and am stuck on a step. I have successfully written a small tcp server/client, but I have to register it in our directory server. In order to do so, I need to send a message to the DS which will reply with "200 Success."

When I do this with telnet in terminal, I connect to the server, pass my message, and terminal spits back "200 Success." Now when I do this in Perl, I open a socket (succesfully) and send my message as (where $reg is my socket name).

print $reg "Message goes here";

I tried adding:

print <$reg>;

to get the server reply with no luck. I am a little stuck as I am unsure of how to get this message back, and am unsure if it is sending correctly. Here is my socket, with the leading sub call before it:

# Server registration
print &register . "\n";

sub register {
my $reg = IO::Socket::INET->new (
    PeerHost    =>  "server goes here",
    PeerPort    =>  port goes here,
    Proto       =>  $protocol
) or die "Failed to make socket for directory registration: $!\n";
print $reg "Register <my name> $ipaddr $port" . '\r'; #with required carriage return, this works in telnet too
my $msg = <$reg>;
print $msg;

}

Was it helpful?

Solution

The problem was that my message did not have the right syntax. When using telnet I was passing \r at the end, when I hit return it added the \n which is what the server needed. In Perl I only passed the \r. Since no \n was added, and no return key entered in my keyboard, the server was simply refusing the message.

Thank you to those that helped me!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top