I made a simple chat system that connects to a server with a client one on one. I'm not really sure how to get multiple clients with the server so that you can see everyone's messages. Here is the source code. The Server only accepts one client at a time. how can I fix this?
Thanks,
Kevin
In keeping with what you have done so far, here are a few tips to get you started. First, when the client receives a connection it stops listening for new connections.
TCPL.Start()
TCPL.BeginAcceptTcpClient(AddressOf OnConnect, Nothing)
Calling these two lines after one client connects will allow another client to connect. Second, the client should not be responsible for starting the server. By doing this each client has it's own server. The clients will never be able to send a message that is displayed on other clients when they each have their own server. Third, I would move server.vb into it's own project. That way the two are not coupled. These steps will allow the server to accept multiple clients. At this point multiple clients will be able to connect and the server will see the messages from each client, but the clients will not be able to see each other's messages. I will leave the last hurdle to you.
Related
We use a provider of global TURN servers (Xirsys). When establishing a connection between peers, each peer first identifies the closest TURN server to their location, then fetches credentials for that server. The peers then exchange ICE candidates, including their respective TURN server URLs.
If those peers are in different regions, they will propose different TURN servers. According to the accepted answer to this question: TURN-Server for RTCConfiguration the respective TURN servers will connect to each other to relay streams from Peer1 <> TURN1 <> TURN2 <> Peer2. However, I have been unable to get this to work. Forcing TURN in the clients (i.e. no direct p2p connections), and attempting to establish a peerConnection using a TURN server in e.g. the United States to one in Brazil, negotiation always fails.
Is this because the servers require credentials that are not passed in the ICE candidates? Or perhaps it's a Xirsys-specific problem? Or should it actually work fine and we're doing something else wrong?
No it's not going to be because of the credentials. They are used between the client and its TURN server. The connection between the TURN server and remote end point doesn't use any authentication.
In fact each TURN server should be blissfully unaware that the remote party is even another TURN server. As far as they are concerned they forward packets to the remote end point just the same no matter whether it's a browser, another TURN server or some other application.
So, while working through two TURN servers is possible, it's definitely not easy. The reason is that the first TURN server will generate an allocation with a given port. The second TURN server will need to send data to this port. However, how does the first TURN server know where to send that data? The second TURN server will not yet have an allocation!
Typically, WebRTC applications use a singular TURN server. If you want to use two, it means having control of the allocation generation and massaging of the SDP.
So I am playing around in Visual Basic and I'm making a chat client and server. I already did both and tested it on local machine and works. Server listens to connection and records all activities. This is reflected in chat client.
Here's the line of code that I use in order to connect to the "chat server" on same computer.
Dim clientSocket As New System.Net.Sockets.TcpClient()
clientSocket.Connect("127.0.0.1", 8888)
Anyone know what kind of settings I would need in order to connect remotely to another computer that has the chat server running?
The short answer is that you need to change the IP. But the real question is how do you get the IP?
Now if this is just for fun or something, you could just PING the computer if you know the name or walk over to that computer and run something like IPCONFIG on it.
But, in the real world, with a real chat, when a client launches, you would then grab the IP programmatically and post it along with some other info, like the User Name, to a database or web service (which you also created) so other clients would know it is online. You would also need to remove that record or update it with an offline flag or something as well as handle cases where the client looses network connectivity or ends unexpectedly. You can see where I am going with this...
The point is, this needs to be the IP of the client you want to talk to. 127.0.0.1 always refers to the local computer or device.
I have a simple TCP server and client working but can only communicate from client to server, i would like to know how to forward all incoming messages to all clients, when the client connects they would have to be stored, not sure how to do this, thanks in advance.
The code does not use Winsock control!
The examples are on the microsoft website, http://msdn.microsoft.com/en-us/library/w89fhyex(v=vs.110).aspx
Keep a list of Sockets in your application. Whenever a client connects add it to this list, and remove it when it disconnects. Whenever you receive a message just loop through this list and resend the message to each client, optionally ignoring the client that originally sent the message. I really can't get more specific without knowing exactly where you intend to take the design.
I am going to develop a chat application, I am confused which way I choose. Below are the option, please suggest me which/why is the best way to create a chat application.
WCF Duplex chat
Socket
XMPP
Thanks
Anuj
if you are going for a client server style of chat then ive always found using sockets to be a simple way to do it. If you create the server and add the socket you want it to be listening at.
Create a client that will then connect to the server for this you will enter the ip of the server and the socket. The client then connects to the server and the server will add the client to the client list. When the client sends a message to the server the server will then use a loop the send the message to all the clients in the list.
You will need to make this multi threaded as the clients will always need to be listening for new messages being sent from the server while still allowing the user to send new messages to the server. Its not very complicated at all a quick google and you will find all the code you could ever need for it
I am publically distributing an application which can be installed on users PC. Client will periodically communicate with the server to send information from the client. Server have to acknowledge the successful receipt of the information. Occasionally, server will do an one way communication with the client. My question is what is the best/failproof/recommended way to do client-server communication when client is massively distributed? I am currently focusing on self-hosted service to do the communication. What precaution should i take if the clients ip address change frequently?
My suggestions are:
Use HTTP or HTTPS on default ports. By massively I understand you will have no control over the network restrictions, firewalls, NAT traversal, etc. Using HTTP(S) and initiating the connections from the clients with simple web requests will save you a lot of trouble.
Use polling at regular/smart intervals to solve your occasional server initiated data transfer. Clients running on workstations wont have a public IP address, let alone a fixed one.