1
Network / Re: How to create a UDP "chat"
« on: December 28, 2012, 11:47:41 am »
I nerver said that I want a finished code.
I chose UDP because I thought it was a bit simpler than TCP. I am a newbie in network programming, so I want to learn the basics first (using that example).
So yes, I am doing that program because I just want to experiment.
On the other hand, I want to make a simple communication between the server and the client.
More exactly: the server and the client must have the sending and receiving properties so that the server can receive messages from the client and to send messages too, as same as the client.
I am stuck in the following situation: the server must receive messages (as it does in the code below) but it also has to send messages. Now, I don't know how to make a kind of algorithm which knows when to send the messages at the appropriate time (if I type something in the server - application and I hit enter, the client should see my message in his application; but what if the client is typing in the same time I hit enter? does he receive my message?); the same situation is in the client - application. In some way, both applications must wait for the message or...someting like that.
I've seen that chat - application made using TCP sockets but it was a bit hard to understand for me because I don't know many things about threads and mutex or whatever.
I want something as simple as possible.
Thank you respectfully.
I chose UDP because I thought it was a bit simpler than TCP. I am a newbie in network programming, so I want to learn the basics first (using that example).
So yes, I am doing that program because I just want to experiment.
On the other hand, I want to make a simple communication between the server and the client.
More exactly: the server and the client must have the sending and receiving properties so that the server can receive messages from the client and to send messages too, as same as the client.
I am stuck in the following situation: the server must receive messages (as it does in the code below) but it also has to send messages. Now, I don't know how to make a kind of algorithm which knows when to send the messages at the appropriate time (if I type something in the server - application and I hit enter, the client should see my message in his application; but what if the client is typing in the same time I hit enter? does he receive my message?); the same situation is in the client - application. In some way, both applications must wait for the message or...someting like that.
I've seen that chat - application made using TCP sockets but it was a bit hard to understand for me because I don't know many things about threads and mutex or whatever.
I want something as simple as possible.
Thank you respectfully.