🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: aus.computers.linux
Article #1099

Re: socket programming

#1099
From: James C
Date: Fri, 11 Apr 2008 00:16
38 lines
2189 bytes
On 10/04/08 23:01, Andrew Rich wrote:
> Any one good at socket programming ?
> 
> I am trying to UDP some hex characters.
> 
> Something so simple is turning out to be hard to find.
> 
> Here is how to do it as a string, I just want to send hex instead
> 
> #!/usr/bin/perl -w
> # clientIO.pl - a simple client using
> # IO::Socket
> use strict;
> use IO::Socket;
> my $host = shift || 'localhost';
> my $port = shift || 30003;
> my $sock = new IO::Socket::INET(
>                    PeerAddr => $host,
>                    PeerPort => $port,
>                    Proto    => 'udp');
> $sock or die "no socket :$!";
> foreach my $i (1..10) {
>     print $sock "hello, world: $i\n";
> sleep 1;
> }
> close $sock; 
> 

If you mean to send each char in the string as a 2 hex chars for its 
ASCII code, use "ord" to find the ASCII code and "printf '%02x' to 
convert that to hex.

Quick demo (1-line shell command) :-

  perl -e '$a = join(" ",
                     map { sprintf("\%02x", ord($_)) }
                         split(//, "hello, world"));
           print "$a\n"'
Technical Details
Message-ID: <65yLj.387$ko5.348@news-server.bigpond.net.au>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!lon-transit.news.telstra.net!lon-in.news.telstra.net!news.telstra.net!news-server.bigpond.net.au!53ab2750!not-for-mail
References: <47fe0fa1$1_2@news.peopletelecom.com.au>

Show Full Headers
Complete Article Headers
X-Google-Thread: 102983,512bafda2340d247
X-Google-Attributes: gid102983,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!lon-transit.news.telstra.net!lon-in.news.telstra.net!news.telstra.net!news-server.bigpond.net.au!53ab2750!not-for-mail
From: James C <enough.already@no.more.spam.please>
User-Agent: Thunderbird 2.0.0.12 (X11/20080227)
MIME-Version: 1.0
Newsgroups: aus.computers.linux
Subject: Re: socket programming
References: <47fe0fa1$1_2@news.peopletelecom.com.au>
In-Reply-To: <47fe0fa1$1_2@news.peopletelecom.com.au>
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 38
Message-ID: <65yLj.387$ko5.348@news-server.bigpond.net.au>
Date: Fri, 11 Apr 2008 00:16:02 GMT
NNTP-Posting-Host: 121.210.121.182
X-Complaints-To: abuse@bigpond.net.au
X-Trace: news-server.bigpond.net.au 1207872962 121.210.121.182 (Fri, 11 Apr 2008 10:16:02 EST)
NNTP-Posting-Date: Fri, 11 Apr 2008 10:16:02 EST
Organization: BigPond Internet Services