I have a form with a richtextbox (my chat box) and two textboxes (one for message one for username)
now I need to understand how I can send a message from the one textbox to the richtextbox while other users who is also logged on
also gets the message. I do unfortunately not have any idea in how to do this. so can anyone be so kind and send me in the right direction? And sorry for my spelling mistakes.

Recommended Answers

All 8 Replies

how was you tried?

what framework are u using?

.net framework 4.5 if thats is what youre asking for

I havent tried to do anything yet because I dont know where to start and so on

I looked a bit more into it today but yet again found nothing
all I want is have a client connect to a webiste ip if possible and legal
then I want to send receive messages from that ip

I think you should clarify what you want. As in, do you want to connect to any website regardless of whether or not it's controlled by you, or, would this website be yours and provided for the purpose/support of your chat application?

I want it to connect to my website, I have IP and port on it.
because the tutorials I have seen wants me to make a server and then I'm only able to interact with the other clients as long as the server is running.
I've never tried much with programming with network so not everything makes sense.

could I make client1 start a server if no server was found?
then when client2 starts it will connect to that server.

well for a simple example. This will be a server/client program

Below is for the server...Use threading for get the stream from client...I will not implant that code.

using System.IO;
using System.Net;
using System.Net.Sockets;

namespace server
    class Program
        private static TcpListener Server;
        private static TcpClient client;
        private static StreamWriter writer;

        static void Main(string[] args)
            server = new TcpListener(IPAddress.Any, 8888); 
            server.Start();//Start the server

            Console.WriteLine("Waiting for a Client...");
            Console.WriteLine(" ");

            //When a user connect this will repeat it self
            while (true)
                client = Server.AcceptTcpClient;



Using System.Net;
Using System.Net.Sockets;
Using System.IO;

namespace client
    class Program
        private static TcpClient client;
        private static StreamReader reader;
        private static SreamWriter writer;

        static void Main(string[] args)
            Console.WriteLine("Press Enter to Connect");
            client = new TcpClient("", 8888);

Please note that you need to use threading(there is another way but I haven't used it) in both apps. Use streamreader to read incoming, and streamwriter for to send strings.etc..

well to work this, you need a static ip. i'm not quite sure what you want to acheive, my example is not the most effecient one, I just pointed you there cause it's the simple way to make a chat program.

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.