Solved

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

Posted on 2010-11-10
6
699 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
Comment Utility
0
 
LVL 2

Author Comment

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

Expert Comment

by:phoffric
Comment Utility
"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
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

743 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now