socket comunication
socket comunication
socket comunication
socket comunication
socket comunication
socket comunication socket comunication socket comunication socket comunication socket comunication socket comunication socket comunication socket comunication
socket comunication socket comunication
socket comunication
Go Back  Xtreme Visual Basic Talk > > > socket comunication


Reply
 
Thread Tools Display Modes
  #1  
Old 06-25-2004, 07:02 PM
davcaw's Avatar
davcaw davcaw is offline
Centurion
 
Join Date: Mar 2004
Location: Cedarburg, WI, USA
Posts: 138
Default socket comunication


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:

Code:
$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
Reply With Quote
  #2  
Old 06-25-2004, 10:54 PM
StUnT10011's Avatar
StUnT10011 StUnT10011 is offline
Freshman
 
Join Date: Jun 2004
Location: Florida
Posts: 47
Default

ummm, wow, i know no perl but you can start here...
System.Net.Sockets Namespace
if you know any vb.net converting that code shouldnt be too much of a problem.
__________________
Q: Did God really create the world in seven days?
A: He did it in six days and nights while living on cola and
candy bars. On the seventh day he went home and found out his
girlfriend had left him.
Reply With Quote
  #3  
Old 06-25-2004, 11:32 PM
davcaw's Avatar
davcaw davcaw is offline
Centurion
 
Join Date: Mar 2004
Location: Cedarburg, WI, USA
Posts: 138
Default

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.
Reply With Quote
  #4  
Old 11-15-2004, 04:45 PM
Sidewinder's Avatar
Sidewinder Sidewinder is offline
Junior Contributor
 
Join Date: Jul 2002
Location: California
Posts: 241
Default

Quote:
Originally Posted by davcaw
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:

Code:
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.
Reply With Quote
  #5  
Old 11-15-2004, 07:53 PM
davcaw's Avatar
davcaw davcaw is offline
Centurion
 
Join Date: Mar 2004
Location: Cedarburg, WI, USA
Posts: 138
Default

Quote:
Originally Posted by Sidewinder
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:

Code:
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
Reply With Quote
  #6  
Old 11-17-2004, 05:20 PM
Sidewinder's Avatar
Sidewinder Sidewinder is offline
Junior Contributor
 
Join Date: Jul 2002
Location: California
Posts: 241
Default

Quote:
Originally Posted by davcaw
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?
Reply With Quote
  #7  
Old 11-23-2004, 06:34 PM
elnerdo's Avatar
elnerdo elnerdo is offline
Contributor
 
Join Date: Jul 2004
Location: Northern New Jersey
Posts: 490
Default

that sounds like it would take quite a lot of your processor.
__________________
nerds unite!
Reply With Quote
  #8  
Old 11-27-2004, 12:24 PM
excaliber's Avatar
excalibersocket comunication excaliber is offline
Senior Contributor

* Expert *
 
Join Date: Nov 2002
Location: Ohio, USA
Posts: 1,828
Default

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):

HttpWebRequest
__________________
RandomIRC - Your neighborhood's friendly IRC channel (irc.randomirc.com - #code)

"Perl - The only language that looks the same before and after RSA encryption."

Last edited by excaliber; 11-27-2004 at 12:46 PM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
socket comunication
socket comunication
socket comunication socket comunication
socket comunication
socket comunication
socket comunication socket comunication socket comunication socket comunication socket comunication socket comunication socket comunication
socket comunication
socket comunication
 
socket comunication
socket comunication
 
-->