socket comunication

davcaw
06-25-2004, 06:02 PM
I am very new to sockets in vb .net. I need to convert some perl code to vb that uses sockets. First I need to encode some data base64. Then i need to establish a socket connection to "dyn.everydns.net" Then i need to send the encoded information through the socket and get a response.
Here is the perl code if you need it:


$target = "dyn.everydns.net";
$version = "0.1";
$pass = MIME::Base64::encode_base64("$username:$password");
$sock = new IO::Socket::INET(
PeerAddr => "$target",
PeerPort => 'http(80)'
);

if (!$sock) {
print "Connect failed\n\n";
exit(1);
}

$sock->autoflush(1);

$sock->print("GET $url HTTP/1.0\r\n");
$sock->print("User-Agent: eDNS.pl $version\r\n");
$sock->print("Host: $target\r\n");
$sock->print("Authorization: Basic $pass\r\n\r\n");

@result = $sock->getlines();


Thanks

StUnT10011
06-25-2004, 09:54 PM
ummm, wow, i know no perl but you can start here...
System.Net.Sockets Namespace (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemNetSockets.asp)
if you know any vb.net converting that code shouldnt be too much of a problem.

davcaw
06-25-2004, 10:32 PM
I know perl, and I looked at the documentation for sockets, but I have never done any work with sockets before and I don't know how I am supposed to use them.

Sidewinder
11-15-2004, 03:45 PM
I know perl, and I looked at the documentation for sockets, but I have never done any work with sockets before and I don't know how I am supposed to use them.

Good, because I need major-league helpage with Perl sockets. I'm trying to accomplish my first ever network-related coding - so it's just a practice thing really. I have a Cisco router that might, say, spit some ping packets into my laptop via Ethernet. I want my Perl script to sit there and then, when the ping packets start coming in, print "I am being pung by a.b.c.d" (where a.b.c.d is the IP address of the router (I actually have five routers even on one Ethernet segment)).

I've tried an accept() function, and Perl warns "Accept() on opened socket." So I tried and "open (SOCKAGE);" to create the filehandle (apparently sockets need filehandles), and I got a "bad file descriptor." Yes, OK, the open() function requires me to name a file, even though I ain't trying to put anything into a disk file.

It ended up like this:

open(SOCKAGE, "C:\Stupidsocketfile");

accept(SOCKAGE, GENERIC_SOCKET);


And now it complains that GENERIC_SOCKET is the unopened socket. Well DUH; doesn't the second argument to the "accept" function refer to whatever settings you want applied to a socket that comes in after the first socket (SOCKAGE, in my example) is opened?

I'm starting to think I'll have to learn assembly language or Unix internals just to understand this.

davcaw
11-15-2004, 06:53 PM
Good, because I need major-league helpage with Perl sockets. I'm trying to accomplish my first ever network-related coding - so it's just a practice thing really. I have a Cisco router that might, say, spit some ping packets into my laptop via Ethernet. I want my Perl script to sit there and then, when the ping packets start coming in, print "I am being pung by a.b.c.d" (where a.b.c.d is the IP address of the router (I actually have five routers even on one Ethernet segment)).

I've tried an accept() function, and Perl warns "Accept() on opened socket." So I tried and "open (SOCKAGE);" to create the filehandle (apparently sockets need filehandles), and I got a "bad file descriptor." Yes, OK, the open() function requires me to name a file, even though I ain't trying to put anything into a disk file.

It ended up like this:

open(SOCKAGE, "C:\Stupidsocketfile");

accept(SOCKAGE, GENERIC_SOCKET);


And now it complains that GENERIC_SOCKET is the unopened socket. Well DUH; doesn't the second argument to the "accept" function refer to whatever settings you want applied to a socket that comes in after the first socket (SOCKAGE, in my example) is opened?

I'm starting to think I'll have to learn assembly language or Unix internals just to understand this.

ok to start you can open a socket like this, it creates a new instance of the io socket class:
$mysock = new IO::Socket::INET(
PeerAddr => "remoteaddresshere",
PeerPort => 'remoteporthere'
);

to get information from a socket you can use this:
@result = $sock->getlines();

it will get all the lines from the socket and store them the array result
perl cant run indefinatly though, when the script is executed it will end, so you cant really have a perl script that just sits and listens on a port

Sidewinder
11-17-2004, 04:20 PM
ok to start you can open a socket like this, it creates a new instance of the io socket class:
$mysock = new IO::Socket::INET(
PeerAddr => "remoteaddresshere",
PeerPort => 'remoteporthere'
);

to get information from a socket you can use this:
@result = $sock->getlines();

it will get all the lines from the socket and store them the array result
perl cant run indefinatly though, when the script is executed it will end, so you cant really have a perl script that just sits and listens on a port

Thank you for that; thought it did merely confirm what I suspected: THIS IS WAY OVER MY HEAD!!! I only know from Clinton Pierce's Teach Yourself Perl in 24 Hours, so this "new" function and the double-colons and the => operator are all Greek (well, Perl) to me. I don't even have a good understanding of what instances or classes are (and I come from a VMS background, so double-colons mean nodenames to me).

But, about the script not being able to sit and listen - aren't there cases where a Perl script will just hang while it's waiting for input (such as into the <STDIN> filehandle)? Or, couldn't I just put a REDO in there so the script is constantly looping while waiting for the port?

elnerdo
11-23-2004, 05:34 PM
that sounds like it would take quite a lot of your processor.

excaliber
11-27-2004, 11:24 AM
Well, I don't know Perl (nor do I wish to), so I can't comment on that.

I would recommend to not use sockets in VB.Net though. What you are doing/requesting can be done with a much higher level object: HTTPWebRequest and HTTPWebResponse

Google for it, check MSDN, and search this forum. It will allow you to do what you want much easier.

EDIT: Webclient might also be a reasonable class for you to use (but is slightly more limiting):

http://www.xtremevbtalk.com/showthread.php?t=192940

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum