I’ve moved this post to my new blog.
http://fpgentil.github.io/2012/simple-chat-application-using-asynchronous-communication-and-udp-in-csharp/
I’ve moved this post to my new blog.
http://fpgentil.github.io/2012/simple-chat-application-using-asynchronous-communication-and-udp-in-csharp/
Works better than the MSN itself
indeed!
Hi, what modifications do i need to add in order to make it work with multiple clients. I have created different application for server/client but how do i make the server to accept more connections?
Hello Adi,
Well, you can either use one different port to each client you have.
Since UDP is conectionless, you do not have to worry about handshaking or other stuff like that, just “copy/paste” your clients and connect them to your sever.
Let me know if this was helpful.
Regards,
Felipe
Hey i m new in c# can you explain brefly how to check this code i want to build server client windows application what should i do can you bullet a procedure in proper flow
Hello Ammad,
You can check the entire application by downloading it from this link: http://dl.dropbox.com/u/5986982/AsyncComm.rar
You can check my code and if there’s any kind of trouble, let me know.
Regards,
Felipe
This works great on a local network but I am wondering how it could be changed so that I can use across the internet?
Hello Mike,
Well I believe If you setup your external IP adress it should work as well, shouldn’t it?
I haven´t tried yet, but the principles are the same!
Regards,
Felipe
I have been trying for the last little while with no luck. If I put my external ip in the friend field and forward the ports on the router, i still get nothing. 😦
You can send an email to me directly if you prefered to discuss what I am trying to do. (bergsma@gmail.com)
Hi Mike,
Already sent you an email.
Regards,
Felipe
Hey fpgentil You Have Done Awesome I have Checso ked Your Application I Already Built an c# application BY using Your tutorial
Now I want to Convert this application so that multiples clients can connect to single server
and then onwards i want make application just like a yahoo server means i m making an environment over Lan same as yahoo chat
means
A single server
and
Multiples can connect to that server
and Do chat with server
means all persons who are connected to that server will receive messages which a single client send to server
i hope u got my meaning these are my objectives
simply now
i want to convert this (which i have developed) application (Based on TCP protocol)
so thats multiples clients can to single server
Nice.
please tell me how i can get the sender and receiver port no?
Hello Raza,
Do you mean the receiver get the sender port number?
If so, all you have to do is, in your private void OperatorCallBack(IAsyncResult ar) you add those lines below
IPEndPoint auxIP = (IPEndPoint) epRemote;
string senderIP = auxIP.Address.ToString();
Hope it helps!
Regards,
Felipe
hi
Im just working on three components client, cache and server
Server will allow the user to browse and download file
cache will cache the previous downloaded files by client
Client will interact with server through cache
Will the above method is similar as I am working?
How to develop it in simple?
Hello,
Basically server and cliente will communicate by packages, so its similar.
You can base your code in mine, implement cache, it should’n be that hard.
Anything I can help, let me know 🙂
Regards,
Felipe
Hello.
i want to connect multiple clients to 1 server. The clients only send messages to server. How can i do this. How can i connect multiple clients to the server whitout knowing the ip adress of each client?
Hello Sebastian,
Well, i’ve never done anything like that, although I believe one possible solution is to implement a server with a list of sockets, each one will be connected to client, still you have only one server but multiple sockets. I don’t know if this is the best solution but I think it’s worth a try 🙂
Regards,
Felipe
@fpgentil Nice work man ….You made my day ……I have just tried multiple clients …..working fine….. …..i have also completed file transfer with the help of code project and google…….Now i want to implement voice chat…..Do you have any idea about that…sry about my poor english:)
Hello,
Thank you so much for the feedback 🙂
About the voice chat, I have never worked with anything like that, but I would love to help and understand more about it.
If you’d like to discuss, you can add me on skype or facebook.. i could at least help you finding out the solution
Regards,
Felipe
OK fine now i am on my way to build a voice chat app ….i think it will complete with in 2 days ….if i have any doubts i will contact u
Alright!
Good luck.
Regards,
Felipe
hey can u send code for multiple clients………plz send me code on jprabhat19@gmail.com
thanks in advance
Hello i would like to know if it was possible that with the same principle as sending a text message like this i could send commands like adding stuff to a database or returning stuff from it.. and if it cant what would be the best way to do it.
Anyways Thanks! Simple and easy to understand code!
Hello Nuno,
Well, I believe the principle is the same, so you could as well send commands within UDP packages.. The only thing that would matter in this case it would be how you handle this command when it arrives from network.
For example, to add stuff to database, you could build your sql query and send it thru network, receive on the server side and execute it.
I don’t know if it was clear enough, I think it depends on what kind of commands you want to use.
Feel free to talk to me about it, i’d love to help 🙂
Regards,
Felipe
Got it! Thanks
You’re welcome 🙂
Hi fpgentil,
You do a great job. I want to develop a student management system for my former high school. I want to use visual c#.net and sql/mysql database server to store all the information. Client-server application is the way to go so that teachers and administrators can login to the system from their PCs and do their job. I will be contacting you on a few tips on the same.
Thanks in advance.
Hello Jangu,
Thanks for the feedback and please feel free to contact me and hope I may help you.
Good luck and regards,
Felipe
Thanks.
That’s a great tutorial. Thanks!
hi sir how are you .
sir this is do the on the same project on the same computer,diferent computer
Hello golmal,
It works both in same computer and in different computers, I have tested already.
Regards,
Felipe
hi
sir when we run the project only only one window show ,,,,and what is the port number …sir plz help me bz this is my semester project
Hello golmal,
Can you please be more specific? I didn’t understand your question properly.
Regards,
Felipe
sir plz send me your email beacuse we take snapshot of the error .then mail to to u sir plz help me
Hello,
You can send to cdigentil@gmail.com.
Regards,
Felipe
hello fpgentil i have send (error message) to your email ok read it and then guaid me ok sir
Already answered, golmal.
Regards,
Felipe
hello fpgentil
can we make an application where messages from all the clients go through the server
but they should be able to chat privately as well as an option to chat in group??
if u have any code like this can u please mail it to me??
Hello mayur,
Actually I dont have any code like this.
To chat in group the application needs to be redesigned, I haven’t thought about it yet but if you want to talk about it you can add me on Skype at gen7il.
I’m sorry that took so long, I was on vacation.
Regards,
Felipe
Hello!
Why this is not working in my computer.
It I click on Start button it is done. But when I click on Send button it shows me an error message which is given below:-
System.Net.Sockets.SocketException(0x80004005): An existion connection was
forcibly closed by the remote host
at System.Net .Sockets.Socket.EndReceiveFrom(IAsyncResult asyncResult,
EndPoint& endPoint)
at AsyncComm.Form1.OperatorCallBack(IAsyncResult ar) in
c:\Users\Hitesh\Desktop\AsyncComm\AsyncComm\AsyncComm\Form1.cs:line
67
Please help it out…
Hello Hitesh,
Did you follow the tutorial properly? Can I see your code?
Regards,
Felipe
hello dear thank u so much…..
now can u tell me how we can send image and text both on client computer…
any help will be appreciate
Hello prabhat,
To send an image all you have to do is convert that into a byte array and then the same to “reconstruct” it on the other side.
Tell me if you have any problems with it.
Regards,
Felipe
can u send me code for multiple client communicate to each other….on jprabhat19@gmail.com
thanks in advance
Hello,
I don’t have the code here with me, have you tried the solution I suggested above and implement a list of Sockets?
Regards,
Felipe
hey can u tell me …suppose that i have 5 computer and i want that every user can send data to each other…then i have to make 5 socket connection or not??? i am sending my code on ur mail id….plzzz give a look on dis and give me solution ..thanks
Hello there,
Well, if you have 5 computers then each one should be one socket. I’ll take a look on your code and answer you there.
Regards,
Felipe
Hello sir , I really need help in this code , if you don’t mind could i have your email …
Sure, my email is cdigentil at gmail 🙂
Regards,
Felipe
hello fpgentil!
i want to develop a “auto emoticon chat application” . its a simple chat app with a feature of automatically attachment of emoticon with the chat message by detection of user face expression.
i had developed the face dedection and recognition part in “open cv ” and integrate it with c#.
can you help me to make a chat app with above feature i.e automatically attachment of emoticon?
Hello Asan,
That sounds like an amazing app, I sure would like to help you. My email is cdigentil at gmail or if you prefer add me on Skype, my nickname is gen7il.
Regards,
Felipe
hello!
I have just copied and paste all of this in my visual studio, but i dont know how to work on it, an d when i click on start button, an exception for ip address comes out, and that is incorrect format for ip addresses written in text boxes, help needed, i need that urgently plz…..
plz mail me the working template on mh.anjum90@gmail.com
that would be so nice of you
BEST REGARDS
Anjum
Hello Anjum,
Can you give me the exactly error that you’re getting?
Regards,
Felipe
Very nice man, I see a Portuguese Firewall notification on your windows, you is brazilian? 😀
See you soon!
Thanks, man 🙂
Yes I’m brazilian!
Regards,
Felipe
Awesome, you have a good English, I’m beginner in both, Programmation and English. I’m brasilian too. 😀 Bye!
Thanks again, man 🙂
Wish you luck in this new path (both of them :P)
Cheers,
Thanks men! in both, I really hope, and in a million others, success for you!
Cheers
Hey Felipe, i’m trying to make a software to communicate with another computer, kinda the same way as the chat, but we need internet communication.
so here’s the scenario:
two computers, A and B, in different networks.
they have IP A and B.
And there’s a special problem here: both computers are in a network with more than one computer, hooked up with a router.
For example computer A has a computer C in the same network, by a router, which means their external IP Address are the same.
so the problem is: How do I make A and B communicate via UDP or TCP via internet (not local network)?
– I have tried before:
– UdpClient (class) says it’s listening to the IP and Port but never gets an answer
– TcpClient says it’s not a valid IP in its context ( something like that)
I ran out of ideas how to make it work, and even researching about it, they all show how to do it locally only.
Can you help me out here ? 🙂
Thank you
Hello Lucas,
Man that is clearly a nice problem 🙂
I have never implemented anything like that before, would you mind adding me on Skype (gen7il) or Facebook (felipe.gentil) so we could talk about it?
Cheers,
Felipe
Hello Sir ,you run app on same machine but if we have two different machines then how to get ip of the machine connected through lan cable i,e the other computer ip? reply early please
Hello sunny,
Well, i have tested this application using 2 apps running on the same computer, over the network and the internet, and they all worked well for me.
You have only to pay attention on the IP that you are using and windows firewall.
Regards,
Felipe
hello fpgentil
i have tested this code on same computer its works fine but if i work on A LAN network its not working properly as it work on independent machine.
bye the way its really a nice article . thanks a lot sir
Hello sir,
Are you getting any error while testing this code on LAN? I’m pretty sure I’ve tested once and it worked for me.
Thanks for the commend and feedback 🙂
Regards,
Felipe
Hi I get this error:
A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call)
no address was supplied
the error comes from here:
System.Text.ASCIIEncoding enc =
new System.Text.ASCIIEncoding();
byte[] msg = new byte[1464];
msg = enc.GetBytes(txtChat.Text);
sckCommunication.Send(msg);
lbChat.Items.Add(UserInfo.UserName + txtChat.Text);
txtChat.Clear();
Hello Connor,
Probably the socket is not connected to anything. You must provide a target to the socket before calling the send method.
Regards,
Felipe
hi fpgentil
i want to make this for multi clients user, how to do this?
is there is tutorial you recommend to me to do this!
Hello Sarah,
Have you tried to connect your clients to individual ports in your server? I believe it would work well.
Cheers,
Felipe
Can this application be used as a local client server and/or two computers in the same room?
Hello Rush,
Yes, it’d perfectly work 🙂
Cheers,
Felipe
What are you corresponding with “Items”?
Hello Rush,
By “Items” I’m adding the message into the ListBox.
Cheers,
Felipe
@fpgentil, THANK YOU SO MUCH!
Hello fpgentil,
What if i want multiple clients on one server ? They´re all gonna use different ports ? Sorry if it´s already been ansewred but i do not had the time to read all answers.
Hello Narciso,
Yes, indeed! If you want multiple clients to connect to one server, each client should have its own port 🙂
Cheers,
Felipe
Hi again fpgentil,
are you brazilian ? Can we communicate through emails ? Because I have an error using your code but the error is in portuguese.
Thanks in advance.
Narciso.
Yes I’m brazilian.
My email is cdigentil at gmail, feel free to add me on Hangout as well 🙂
Cheers,
Felipe
Amazing Work, Thx a ton .
Can you please look into the mail. I have some doubts. It will be really great if you can help.
I’m looking at your email right now 🙂
Cheers,
Felipe
Hey felipe i have used your above in my project and it was working fine thanks..
You’re welcome 🙂 thanks for the comment.
hi i want to implement this chat as a web application.Is that possible?
Well, I haven’t tried with ASP.NET, but I believe it should work the same way.