using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
namespace NetworkProgramming
{
public class IPEndPointSample
{
public static void Main()
{
IPAddress host = IPAddress.Parse("149.6.43.235");
IPEndPoint hostep = new IPEndPoint(host, 443);
Socket sock = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
try
{
sock.Connect(hostep);
}
catch (SocketException e)
{
Console.WriteLine("Problem connecting to host");
Console.WriteLine(e.ToString());
sock.Close();
return;
}
try
{
sock.Send(Encoding.ASCII.GetBytes("testing"));
}
catch (SocketException e)
{
Console.WriteLine("Problem sending data");
Console.WriteLine(e.ToString());
sock.Close();
return;
}
sock.Close();
}
}
}
I want to make a live radio using the ip and port information in this xml
https://github.com/learnergthb/TcpUdpProtocolsConnection-XmlFileRead/blob/main/XMLFile1.xml
string HostName = Dns.GetHostName();
Console.WriteLine("Host Name of machine =" "21303.live.streamtheworld.com");
IPAddress[] ipaddress = Dns.GetHostAddresses("21303.live.streamtheworld.com");
Console.WriteLine("IP Address of Machine is");
foreach (IPAddress ip in ipaddress)
{
Console.WriteLine(ip.ToString());
}
I converted 21303.live.streamtheworld.com <-149.6.43.235->.
When I run it it gives no results no error. What should I do for the radio to work? THANKS EVERYONE:)
CodePudding user response:
Following will get the URLs of the stream. You can put the URL into a browser URL to hear the results so you can test that it works. Then write c# code. If you replace the HTTP with HTTS you will get the port 443 instead of 80/3690:
using System;
using System.Linq;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using System.IO;
namespace ConsoleApp2
{
class Program
{
const string URL = "http://playerservices.streamtheworld.com/pls/METRO_FM.pls";
static void Main(string[] args)
{
WebRequest request = HttpWebRequest.Create(URL);
request.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla / 5.0(Windows NT 10.0; Win64; x64) AppleWebKit / 537.36(KHTML, like Gecko) Chrome / 103.0.0.0 Safari / 537.36");
request.Headers.Add(HttpRequestHeader.Accept, "text/html,application/xhtml xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
request.Headers.Add(HttpRequestHeader.AcceptLanguage, "en-US,en;q=0.9");
WebResponse response = request.GetResponse();
Stream stream = response.GetResponseStream();
StreamReader sReader = new StreamReader(stream);
List<string> urls = new List<string>();
string line = "";
while((line = sReader.ReadLine()) != null)
{
line = line.Trim();
if (line.StartsWith("File") && line.Contains("="))
{
string[] splitLine = line.Split(new char[] { '=' });
urls.Add(splitLine[1]);
Console.WriteLine(splitLine[1]);
}
}
Console.ReadLine();
}
}
}