HI guys

I am need to connect my pc with the PLC on the Ethernet Connection and I don't know about socket programing,
I have very search for this work and find any code in this site and usage then.
but have a some problem.

this is my usage code:

    private void timer1_Tick(object sender, EventArgs e)
        IPAddress ipAd = IPAddress.Parse("");
        TcpListener newList = new TcpListener(ipAd, 2000);
        newList.Start();/////  *****
        Socket s = newList.AcceptSocket();
        byte[] b = new byte[100];
        int k = s.Receive(b);
        textBox1.Text = k.ToString();
        ASCIIEncoding asen = new ASCIIEncoding();


I don't know this code is right, pls tell me that code is true or not?
and when run this code show this error as *** line:
" The requested address is not valid in its context"

detaile of this connection:
Pc IP:
Port: 2000

Pls help me

and I use a another code like this:

private void timer1_Tick(object sender, EventArgs e)
           IPEndPoint m_IpEndPoint = new IPEndPoint(IPAddress.Parse(""), 2000);
            Socket m_Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            NetworkStream m_Stream = new NetworkStream(m_Socket);
            m_Stream.Write(System.Text.Encoding.ASCII.GetBytes("Hello world!"), 0, 12);
            byte[] read_buffer = new byte[4096];
            m_Stream.Read(read_buffer, 0, 4096);
            textBox1.Text = read_buffer.ToString(); 

but when connected line showes this error:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond


pls help me

This article has been dead for over six months. Start a new discussion instead.