Simple program to send socket stream data to text file  
Author Message
GerryArmstrong





PostPosted: .NET Framework Networking and Communication, Simple program to send socket stream data to text file Top

Dear all,

I am new to this so please be patient with me.... I am trying to find a way to capture all data that is being streamed from a PBX on a specific socket to a test file. The PBX is not expecting any responses, all it does is send the data stream out the specified socket at the completion of a call so all I need it a program that will listen on that socket ond record any data to a text file.

I have found various samples that connect to sockets etc but have not figured out a way to have this information then saved to a file. Any suggestion welcomed!



.NET Development11  
 
 
Mike Flasko





PostPosted: .NET Framework Networking and Communication, Simple program to send socket stream data to text file Top

Once you grab the data from the socket in the byte array use the FileStream class to write the data to a file. The pseudo code would be:

Socket s = new Socket (...);

//Create the file.

FileStream fs = File.Create(path);

byte[ ] bytes = new byte[1024];

int bytesRead = s.Read(bytes, ...);
while (bytesRead != 0){

// write the data received from the socket to the file

fs.Write(...);
bytesRead = s.Read(bytes, ...);

}



 
 
GerryArmstrong





PostPosted: .NET Framework Networking and Communication, Simple program to send socket stream data to text file Top

Thanks for the reply, I got it figured out now and am able to save all data in the stream to a text file!


 
 
Fadi Naffah





PostPosted: .NET Framework Networking and Communication, Simple program to send socket stream data to text file Top

Hi Gerry,

I know this is an old thread for you, But I am in ur status now,

I am new to .Net and i wantt o connect to a PBX and obtain it's data out but i don't now where ti start,

so i f u could plese give me some hints.

"

Thanks in advance.

Regards.