hello everyone,
I am trying to make 2 different applications on 2 different computers respectively. Moreover i want these applications to communicate over ethernet cable.
The code for receiver application is guven below and unfortunately it is not working. Instead i am getting some error i.e.
"The requested address is not valid in its context"
Making improvements in this code will be prefered instead of links to other sites.
- public sealed partial class MainPage : Page
- {
- public MainPage()
- {
- this.InitializeComponent();
- }
- TcpListener Listener;
- IPAddress localAddr = IPAddress.Parse("192.168.x.xx");
- Int32 port = Int32.Parse("5001");
- private void Recieve_Click(object sender, RoutedEventArgs e)
- {
- Listener = new TcpListener(localAddr,port);
- Listener.Start();
- Byte[] bytes = new Byte[256];
- String data = null;
- while (true)
- {
- IP.Text = "Waiting for a connection... ";
-
-
- TcpClient client = Listener.AcceptTcpClient();
- IP.Text = "Connected!";
-
- NetworkStream stream = client.GetStream();
- int i;
-
- while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
- {
-
- data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
- IP.Text = data;
-
- data = data.ToUpper();
- byte[] msg = System.Text.Encoding.ASCII.GetBytes(data);
-
- stream.Write(msg, 0, msg.Length);
-
- }
-
- client.Close();
- }
- }
- }
- }