Solved

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

Posted on 2010-11-10
6
701 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
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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 goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

810 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