Solved

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

Posted on 2010-11-10
6
705 Views
Last Modified: 2012-08-13
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++ :)
0
Comment
Question by:Billetkontoret
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 32

Accepted Solution

by:
phoffric earned 500 total points
ID: 34105312
0
 
LVL 2

Author Comment

by:Billetkontoret
ID: 34105396
When you say unix and windows, you mean Mac OS X as well?
0
 
LVL 32

Expert Comment

by:phoffric
ID: 34105644
"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.
0
 
LVL 12

Expert Comment

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



[1] http://netcat.sourceforge.net/
0
 
LVL 40

Expert Comment

by:evilrix
ID: 34824133
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.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question