Click here to Skip to main content
15,900,378 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi every one this code to
send
C#
TcpClient tcpclnt = new TcpClient("localhost", 8001);

          NetworkStream mynetsream = tcpclnt.GetStream();
          StreamWriter myswrite = new StreamWriter(mynetsream);
          myswrite.WriteLine("Your Message senaadss");
          myswrite.Close();
          mynetsream.Close();
          tcpclnt.Close();
          Console.Write(tcpclnt .Connected .ToString ());
          Console.Read();


and this to receive

C#
            mylistener = new TcpListener(8001);

             mylistener.Start();
             System.Timers.Timer aTimer = new System.Timers.Timer();
             aTimer.Elapsed += new ElapsedEventHandler(x);
             // Set the Interval to 5 seconds.
             aTimer.Interval = 5000;
             aTimer.Enabled = true;
           Console.Read();
static void x(object source, ElapsedEventArgs e)
       {


           Socket mysocket; StreamReader str;

           while (true)
           {
               mysocket = mylistener.AcceptSocket();
               myntl = new NetworkStream(mysocket);
               str = new StreamReader(myntl);
               Console.WriteLine(str.ReadToEnd());
               Console.Read();
           }

       }

is working in local network
but i want publish on internet and when repalce localhost to IP
i have error
this

o connection could be made because the target machine actively refused it and my ip:port so ?
thanks for any help
PS> i don't have real ip
Posted
Updated 11-Sep-11 22:58pm
v3
Comments
Prerak Patel 12-Sep-11 4:53am    
Added pre tags
Timberbird 12-Sep-11 5:14am    
Could you elaborate your question a bit? Explain network structure: from where and to where you are trying to connect (for example: is you server behind a router? and is your client machine behind a router?)

1 solution

You cannot just connect to any remote system unless that system is setup to receive communications from you on the relevant port number. Most systems have security specifically to protect against this sort of thing.
 
Share this answer
 
Comments
Mostafa Elsadany 12-Sep-11 5:10am    
pleaseeeee more explain or change in code

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