Note that there are some explanatory texts on larger screens.

plurals
  1. POTesting of socket communication program
    primarykey
    data
    text
    <p>Am starting with socket programming with a simple UDPClient program to send some data. The large code snippet is below:</p> <pre><code>using System; using System.Text; using System.Net; using System.Net.Sockets; using System.Threading; class ShowIP { public static void Main(string[] args) { string name = Dns.GetHostName(); //name = "GSL1460"; name = "GSL1296"; try { IPAddress[] addrs = Dns.GetHostEntry(name).AddressList; foreach (IPAddress addr in addrs) Console.WriteLine("{0}/{1}", name, addr); Console.WriteLine("Started listening"); Thread listenerThread = new Thread(new ThreadStart(StartListeningUDP)); listenerThread.Start(); Console.WriteLine("Started sending"); for (int counter = 0; counter &lt;= 3; counter++) { Thread.Sleep(1000); Console.WriteLine("Sending {0} time", counter.ToString()); StartSendingUDP(addrs[0]); } Console.ReadLine(); } catch (Exception e) { Console.WriteLine(e.Message); } } private static void StartListeningUDP() { UdpClient udpListener = null; IPEndPoint nwPoint = new IPEndPoint(IPAddress.Any, 12345); while (true) { try { udpListener = new UdpClient(12345); Console.WriteLine("Waiting to receive"); Byte[] receivedBytes = udpListener.Receive(ref nwPoint); string receivedData = Encoding.ASCII.GetString(receivedBytes); Console.WriteLine("Data received : " + receivedData); } catch (Exception e) { Console.WriteLine(e.Message); } finally { udpListener.Close(); } } } private static void StartSendingUDP(IPAddress clientAddress) { UdpClient udpSender = new UdpClient(); try { Byte[] sendBytes = Encoding.ASCII.GetBytes("Say HI to Papa..."); Console.WriteLine("Data Sent : Say HI to Papa..."); udpSender.Send(sendBytes, sendBytes.Length, new IPEndPoint(clientAddress, 12345)); } finally { udpSender.Close(); } } } </code></pre> <p>The sample works fine on local machine, but am not able to send data to another machine on the intranet. </p> <p>During testing </p> <ul> <li>Am uncommenting the appropriate code to send data to his machine</li> <li>Am running the Receiver bit on his machine</li> <li>Have checked that the required port is open on his machine</li> </ul> <p>Am I missing something? Please suggest.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload