Tcp client cant read block of data

Well I ve got an issue when I click the button to get the block of data of the network stream.

Every time I create the tcp client from the pc that is also the receiver it works just fine.

When I use another pc it freezes and says that my program is not responding so I have to exit the program

namespace WindowsFormsApp23
{
    public partial class Form1 : Form
    {
        TcpListener tcpListener = null;

        TcpClient sendClient = null;

        TcpClient receiveClient = null;

        public Form1()
        {
            InitializeComponent();

            tcpListener = TcpListener.Create(25);
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (tcpListener.Pending())
            {
                receiveClient = tcpListener.AcceptTcpClient();

                tcpListener.Stop();

                timer1.Stop();

                receiveClient.GetStream().Write(Encoding.ASCII.GetBytes("Hello daddy"), 0, 9);
            }
            else
            {
                label1.Text = "No connections found.Waiting for new incoming connections...";
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            tcpListener.Start(1);

            timer1.Start();


        }

        private void button2_Click(object sender, EventArgs e)
        {
            tcpListener.Stop();

            timer1.Stop();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            byte[] buffer = new byte[9];

            sendClient.GetStream().Read(buffer, 0, 9);

            label1.Text = Encoding.ASCII.GetString(buffer);


        }

        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                sendClient = new TcpClient("idea-PC", 25);
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
            }
        }
    }
}

Open in new window


Any help very appreciated.
LVL 1
Max DestinyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nociSoftware EngineerCommented:
did you open the firewall for port 25?....
(btw. port 25 is normally used for SMTP, so be prepared to fend off some queer strangers (If you are not building a mail server/client).

And starting the server part on a system that also runs a mailserver will obviously fail. as the port 25 is already busy.
0
Max DestinyAuthor Commented:
yes I have opened the firewall for port 25 and where can I check if a system  runs a mailserver at port 25?
0
nociSoftware EngineerCommented:
Windows:
netstat -antb 

Open in new window

Unix:
netstat -antp | grep :25

Open in new window

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Max DestinyAuthor Commented:
what are these?
0
Max DestinyAuthor Commented:
oh wait I can do this programmatically
0
nociSoftware EngineerCommented:
netstat show network information
netstat -a ( all info) -n (no number ->name translation) -t (tcp only) -b  (show process info).

On linux -p shows process info, and grep :25 shows only  line where port 25 is shown.  

So that Checks for something using port 25...

For windows systems also check the winows firewall  and on linux system check iptables, as well as intermediate routers....
It may happen that special rules are set for mail traffic (and thus port 25....) maybe try port 1025 instead, less/no chance to hit a mail policy.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.