Avatar of Billetkontoret
Billetkontoret
 asked on

C++ send lines of text to an UDP-server

Hi guys. I have created this php-script:
<?php
$user_name1 = 3064;
$ip_adr = "192.168.50.64";
$sip_port = 2058;
$message = $argv[1];
$length = strlen($message);

$sippacket = "MESSAGE sip:$user_name1@$ip_adr:$sip_port SIP/2.0
Via: SIP/2.0/UDP 192.168.50.2:47942;branch=z9hG4bK.1a041dd5;rport;alias
To: sip:$user_name1@$ip_adr:$sip_port
Call-ID: 751288264@192.168.50.2
CSeq: 1 MESSAGE
Content-Type: text/plain
Max-Forwards: 70
User-Agent: PHP script
From: sip:phpscript@192.168.50.2:2057;tag=2cc7bfc8
Content-Length: $length

$message";

$fp = fsockopen("udp://$ip_adr", $sip_port, $errno, $errstr);
if (!$fp) {
   echo "ERROR: $errno - $errstr<br />\n";
} else {
   fwrite($fp, $sippacket);
   fclose($fp);
}
?>

Open in new window


...which sends these lines of text:
MESSAGE sip:$user_name1@$ip_adr:$sip_port SIP/2.0
Via: SIP/2.0/UDP 192.168.50.2:47942;branch=z9hG4bK.1a041dd5;rport;alias
To: sip:$user_name1@$ip_adr:$sip_port
Call-ID: 751288264@192.168.50.2
CSeq: 1 MESSAGE
Content-Type: text/plain
Max-Forwards: 70
User-Agent: PHP script
From: sip:phpscript@192.168.50.2:2057;tag=2cc7bfc8
Content-Length: $length

$message

Open in new window


... to 192.168.50.64 UDP port 2058. How can I accomplish this with C++ in a Mac OS X environment? I am using netbeans as IDE and please note that some of the values in the text are variables.

I am totally new to C++ :)
C++

Avatar of undefined
Last Comment
evilrix

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
phoffric

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Billetkontoret

ASKER
When you say unix and windows, you mean Mac OS X as well?
phoffric

"Mac OS X is a series of Unix-based operating systems and graphical user interfaces developed, marketed, and sold by Apple Inc."
    http://en.wikipedia.org/wiki/Mac_OS_X

So, I would expect that if you review the unix-based links, then you will be close to what your Mac OS X documentation provides.
HappyCactus

If you can use a command line tool instead of a c++ compiled program, you could see netcat[1]



[1] http://netcat.sourceforge.net/
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
evilrix

This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.