I'm creating multiplayer server - client using UDP method. In UDP, there is only one way to receive every packet which is socket.receive(packet). If there are many clients send data at the same time, how can one socket.receive(packet) can handle it all and fast? Thankyou
Related
I want to write a program in java that handles two way communication between server and client using udp.Most of the sources online specify only one way,that is from client to server.I want the server to be able to send messages to the client as well.
If you cannot use TCP, you can still achieve the same behaviour with UDP.
There are three aspects to consider.
First, that you mentioned: you want to communicate both ways. You can do that by running a sender and a listener thread on both the client and the server.
Second: UDP packets are not guaranteed to arrive. You have to implement an ACK logic in your application layer.
Third: UDP packets are not guaranteed to arrive in order. You have to implement some kind of ordering in your application layer.
UDP is a connection-less protocol on top of IP. This just means that there is no established connection you receive on the other end, you just receive packets of data. To answer back, you have to send a packet "back" to the client.
For this the client needs to be reachable however. This might or might not work through firewalls. Usually firewalls get "punched through" if the client initiates the conversation, but there is no guarantee.
Note also, that UDP packets may arrive out of order, duplicated or not at all. You have to be ready for all. If you send bigger (than MTU) packets, they may have a higher chance of not arriving due to splitting.
I am learning about UDP client server where the communication is one way from Server to Client. Server will send UDP packets to Client.
I want to to make it dual communication where Server and Client can send UDP packets to each other.
Do I need to make another Datagram socket for Client Server to make it dual communication or can I use my existing Datagram socket to do the job. If I dont need another Datagram Socket , I would appreciate if you can show me how it is done
I would appreciate if you can point me to relevant resources on dual commuication for Client Server
Yes, you can use the existing DatagramSocket.
Take a look at example in this link:
http://phoenix.goucher.edu/~kelliher/s2011/cs325/feb25.html
Its upon you how to use the send and receive methods of a socket depending on your needs.
I want to create a voice chat application in pure java socket programming.
I used UDP protocol to transfer recorded voice from one client to another but when i test it over the internet voice is not comming continuously.
As i am new to this voice chat application, someone may suggest what should i do for getting continuous voice.
The Scenario is like this.
Flow of voice chat as this shows only one way communication-
FLOW of data
Client1------------------------------>> Server ------------------------------------>>Client2
Client1:
Reading 1KB voice buffer from TargateDataLine then create a voice packet and sent to server.
Server: Receive from client1 and then send to client2.
Client2: Receive the UDP packet and get voice data then play.
Also facing the bandwidth up and down problem.
What should be the minimum bandwidth to use voice chat. Ex- skype required 30KBPS udloading/downloading speed.
Thanks in advance.
In order to establish a connection between two or more users for peer-to-peer communication you need a signaling server as well as STUN/TURN servers.
You can code your own ones or use a ready backend solutions like ConnectyCube and concentrate on client-side implementation. Here are some WebRTC video chat code samples for your reference as well.
You should send the packets directly between the clients. The relaying of packets through the server is adding more delay to it. Simply send it from client1 to client2.
The Answer is pretty simple you should use tcp protocol. Coz udp sends the packet but doesn't ensure that the packet was received by the target. but tcp protocol ensures it and you will get a stable connection with cost of some speed reduced in transfer of data.tcp vs udp
I am just fiddling around with making a UDP chat program that simply allows messages to be sent between two clients. I am using the DatagramSocket and DatagramPacket classes. The issue that I'm running into is when one client is waiting to receive a Datagram from the other client, using receive, then I can't send any messages with that client as its I/O is blocked, so my current version only allows one message back and forth at a time. What I'm trying to accomplish it to allow the receive method to listen and run separately from the sending portion of the code so that the users can send as many messages as they want without waiting for a reply. Any advice for examples would be greatly appreciated. Thanks.
You'll need two threads at each end, one to receive messages (and display them), and another to receive user input and send those messages.
I want to program a game that involves a client-server option for a network.
For this, I need to be able to get a list of all people that are hosting a server on their computer but the Socket class requires a name of the computer. Is it possible to get this list and if so, then how?
Thanks you very much
You could use a MulticastSocket on the client to listen for broadcast UDP packets from the server. See Broadcasting to Multiple Recipients and have your server send one out every few seconds.