Click here to Skip to main content
15,896,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello
With very low knowledege in server Client program and 
in server client program which was posted in codeproject 
<a href="https://www.codeproject.com/Articles/1415/Introduction-to-TCP-client-server-in-C"></a>

i could not run this program ,look at those notes
1 - Both programs are run in same machine(64 bit),.NET  FrameWork 4.5 window 10
2- I have got the address from my computer using Ms Dos command=ipconfig/all from
   Ethernet adapter vEthernet (Default Switch)
   the IPv4 address = 172.31.57.17
   i have made minor change to the program that listed in the above link
3 - to make my question clear
    using CONTROL PANEL in NETWORK CONNECTION ,i noticed that i have 4 icons 
    one for Ethernet,one for vEthernet(Default Swith) ,one for vEthernet (default switch)2 and last one for wirless
after running the program Client i have got his message 
(No connection could be made because the target machine actively refused it 172.31.57.17:8001)
need help

What I have tried:

<pre lang="
/////Server ///////////////////////////////
    public partial class Form1 : Form
    {
        IPAddress ipAd;
        TcpListener myList;
        public Form1()
        {
            InitializeComponent();
        }
        private void FormLoad(object sender, EventArgs e)
        {
            //ipAd = IPAddress.Parse("172.21.5.99");// as written see the link
            ipAd = IPAddress.Parse("172.31.57.17");//i have tried this
            //ipAd = IPAddress.Parse("172.31.57.18");// and this
            myList = new TcpListener(ipAd, 8001);
        }

        private void StartServerClick(object sender, EventArgs e)
        {
                myList.Start();
                Console.WriteLine("The server is running at port 8001...");
                Console.WriteLine("The local End point is  :" + myList.LocalEndpoint);
                Console.WriteLine("Waiting for a connection.....");

                Socket s = myList.AcceptSocket();
                Console.WriteLine("Connection accepted from " + s.RemoteEndPoint);

                byte[] b = new byte[100];
                int k = s.Receive(b);
                Console.WriteLine("Recieved...");
                for (int i = 0; i < k; i++)
                    Console.Write(Convert.ToChar(b[i]));

                ASCIIEncoding asen = new ASCIIEncoding();
                s.Send(asen.GetBytes("The string was recieved by the server."));
                Console.WriteLine("\nSent Acknowledgement");
                s.Close();
                myList.Stop();
        }
    }

		///////////////////////////Client //////////////////////////////////////////////////
	    TcpClient tcpclnt;
        public Form1()
        {
            InitializeComponent();
        }

        private void FormLoad(object sender, EventArgs e)
        {
            tcpclnt = new TcpClient();
        }
        
        private void StartClient(object sender, EventArgs e)
        {
			Console.WriteLine("Connecting.....");
             tcpclnt.Connect("172.31.57.17", 8001); // use the ipaddress as in the server program
            //tcpclnt.Connect("172.31.57.18", 8001);

			Console.WriteLine("Connected");
			Console.Write("Enter the string to be transmitted : ");
			
			String str=Console.ReadLine();
			Stream stm = tcpclnt.GetStream();
						
			ASCIIEncoding asen= new ASCIIEncoding();
			byte[] ba=asen.GetBytes(str);
			Console.WriteLine("Transmitting.....");
			
			stm.Write(ba,0,ba.Length);
			
			byte[] bb=new byte[100];
			int k=stm.Read(bb,0,100);
			
			for (int i=0;i<k;i++)
				Console.Write(Convert.ToChar(bb[i]));
			
			tcpclnt.Close();
    	}
    }
">
Posted
Updated 19-Mar-18 22:29pm
v3
Comments
Engineer khalid 20-Mar-18 3:32am    
i tried to connect one computer(window 7) and another computer using window 10 on wirless net and i wrote an ip address in both computer
(same address) ,still does not work
then i connect both computer useing cat6 cable and lan net still does not works

1 solution

See TcpListener.AcceptTcpClient[^] for sample server code. You could also try asking the person who wrote the article.
 
Share this answer
 
Comments
Engineer khalid 20-Mar-18 7:35am    
one big mistake i made console program in windowform !the program in msdn looks good
i need hint
should i connect the two computers using wire or wirless ?
Richard MacCutchan 20-Mar-18 10:33am    
It does not matter whether you use wired or wireless. At the TCP/IP level both function exactly the same.
Engineer khalid 20-Mar-18 7:36am    
do i need hardware other than the internetcard ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900