Hello, i have done a simple TCP Client - Server

In my local PC it work but i dont know if i run TCPServer on other pc, it will receive messages from client?
i tryed it with my bro but nothing, i also open and ports... maby isp dont allow open ports (mobile internet)

well can someone try this one plz for and tell me if work...

TCPClient here

        static void Main(string[] args)
        {
            Flood("Your IP", 12345);
        }

        private static void Flood(string IP, int Port)
        {
            // Create Socket
            TcpClient Client = new TcpClient();

            Console.WriteLine("Connecting...");
            Client.Connect(IPAddress.Parse(IP), Port);

            Console.WriteLine("Write your message.");
            Console.WriteLine("---------------------------------");

            while (Client.Connected)
            {
                String Message = Console.ReadLine();
                Stream Stre = Client.GetStream();

                ASCIIEncoding AEncod = new ASCIIEncoding();
                Byte[] Buff = AEncod.GetBytes(Message);

                // Kernel - Sending packets to TARGET
                Stre.Write(Buff, 0, Buff.Length);

            }
            //Close TCP
            Client.Close();   
        }

And TCPServer here...

        static void Main(string[] args)
        {
            Start("IP Here", 12345);
        }

        static void Start(string IP, int Port)
        {
            TcpListener Listener = new TcpListener(IPAddress.Parse(IP), Port);

            Console.WriteLine("Server is starting...");
            Listener.Start();

            Socket socket = Listener.AcceptSocket();
            Console.WriteLine("Connection Accepted!");
            Console.WriteLine("---------------------------------");

            Byte[] Buff = new Byte[1024];

            while (true)
            {
                int ReceivedMessage = socket.Receive(Buff);
                for (int i = 0; i < ReceivedMessage; i++)
                {
                    Console.Write(Convert.ToChar(Buff[i]));
                }
                Console.Write("\n");
            }
        }

I tested it and it worked. Server on Windows 7 x64, IP 192.168.1.50, Client on Virtualbox Guest Windows XP IP 192.168.1.51

I haven't tested it yet using my router's external IP address. I'm not at home right now, and I can't access the router I'm currently using, so I can't port forward 12345 to my laptop. :) I'll be testing it once I get home.

What IP are you using to connect? You will need to make sure you use the external ip of the remote endpoint's computer, not the internal NAT IP, then make sure the port gets forwarded to the right computer in the router settings.

I Have Vodafone Mobile Internet, i also have try to setup NO-IP Servers i had problem with ports
I think providers dont accept connections in custom ports, there are only few opened ports (web/ftp/mail..)

But how i can use Skype?, skype use port 80, i have try my program in port 80 and it does not work...

damn:/ confused..., As ip i add my internet IP "whatismyip.com"

Damn, in server i use my ip to listener OMG :/ so it accept connection only from same IP :D it should be (IPAddress.Any) (Thats why it worked in your Virtual windows, because same computer same line same ip)

Here is new one, not tested yet but i guess it work... i will try it after

        static void Main(string[] args)
        {
            Start(12345);
        }

        static void Start(int Port)
        {
            TcpListener Listener = new TcpListener(IPAddress.Any, Port);

            Console.WriteLine("Server is starting...");
            Listener.Start();

            Socket socket = Listener.AcceptSocket();
            Console.WriteLine("Connection Accepted!");
            Console.WriteLine("---------------------------------");

            Byte[] Buff = new Byte[1024];

            while (true)
            {
                int ReceivedMessage = socket.Receive(Buff);
                for (int i = 0; i < ReceivedMessage; i++)
                {
                    Console.Write(Convert.ToChar(Buff[i]));
                }
                Console.Write("\n");
            }
        }

What ip are you trying to connect to, can you show a screen shot of all the errors that occur?

As ip you will use IP of computer were is TCPServer.exe,
So, if you have TCPServer.exe in your friend computer, then in your TCPClient(from your pc) you must insert as ip your friend IP

Here is final code

Client
http://pastebin.com/diZnmCen

Server
http://pastebin.com/WsC5bK6b

YG: If you want to use Flood then you should edit this line

String Message = new String('*', 9)

This line parameters ('an character', repeats)
In this example Message = "*********"

Spaming server with this length of message, you can just spam it with 2/3 KB/S , so i guess you should use about 1000+

But if you try send big messages then server will interupt you, so you can't take down servers with this ;p, you should make a party with your friends and make a massive attack , many ppls maby...

YG2: TCPClient, work like client and like spammer,
in CMode you can simply send messages to TCPServer
in Flood Mode you can just spam packet to an IP

TCPClient::Flood function have some problems :/ dont work for now :/ , i get disconect from server...

Waiting for feedback, someone can try it with his friend?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.