From what i have understood , by reading your question is that you need to maintain number of clients connected to a server , right ?
But you are using UDP Protocol , which is connection less protocol , i think it is not a wise choice to use UDP , if you need to keep record of the connections you should TCP protocol.
The following link can help you use TCP protocol for communication
just let me know if TCP suits your requirement , we can move ahead , with the actual question , we can maintain the count if we use TCP , i am not sure how to do it by using UDP , The logic say we cannot do it , as it is a connection less protocol
The only idea that come to my mind is
we will maintain of connect client (in a list object) , when ever a client tries to connect we will call a function (implementation on the function is as given below ), which will a loop through the list and use the connected property to find if the client is still connected , the implementation of the function goes like this
Private Function NumberOfClientConnected() As Integer
Dim tempclient As TcpClient
Dim totalClientConnected As Integer
totalClientConnected = 0
For Each tempclient In connectedClients
If tempclient.Connected Then
totalClientConnected = totalClientConnected + 1
for this you have to declare a Module level variable of type list , remember its a module level variable.
Dim connectedClients As New List(Of TcpClient)
Also there is a small change in the previous code after
Dim tcpClient As TcpClient = tcpListener.AcceptTcpClient()
we need to add the following line
Also before Dim tcpClient As TcpClient = tcpListener.AcceptTcpClient()
We need to add a if condition
If NumberOfClientConnected() > <maxclientallowe> then
So the summary is
1) We maintain a list to TCPClient Connected
2) Then we loop through the list and check for still connected client by using the Connected property
3) If the server has not reached the maximum number of client connected , we accept the connection and add it to the list..
I hope it is helpful , i am sorry if there are any build error , i have not tried it in the IDE , i dont have one installed right now , i am i hurry right now , need to go .........
Thanks very Much for your Valuable Response and time.
The above code was what something i was looking for, Thank you very much.
I have tried the code in a small application and the problem i am facing now is as below,
I can Connect to the Server and everything works fine.
But the problem is in receiving data.
I send a string say "HELLO" as a byte array which is of length 5, but when i receive it on the server, the length of the receieved data in array shows as 8193, i don't understand from where the extra bytes are coming.
And because of these extra bytes my string doesn't match with HELLO.
I have written the same code.
Please having Any Idea.
Also, I want to know how to disconnect the client. It is actually like if the data sent by client doesn't match with that in the server, then i need to disconnect the client and doesn't allow the client Software to run.
Please i am sorry i am asking a lot of Queries.
Thank you again for your code atleast i have got a direction.
I have defined an arraylist with I have populated with objects BIRDS ( the class _birds has only string variabels, with contains information about birds)
ArrayList birdArray = new ArrayList();
loop to populate the birdarray while ((line = sr.ReadLine()) != null) birdArray.Add(new Bird(temptext)); // temptext contains data, which is then parsed into member vars.
This loop fills my ListBox with the german names of the birds in the birdarray, however unsorted
foreach (Bird Vogel in birdArray)
Also I have no idea to retrieve the selected object Vogel, if the user select the german name in the ListBox. Does anybody has a solution how to populate the listbox with a property of objects and then retrieve the objects for further processing. Maybe the arraylist concept is wrong.
Thats like saying "I have no idea about engineering, but I'm good at designing bridges".
In the real world that means "Your bridge will look cool on paper, but it will fall down". Perhaps if you are good at coming up with things that look cool on paper and are unworkable in the real world you should consider changing major to arts?
I am using Visual Studio c# to make a sample application to send an email from the website.
Now I have query about the web.config file when specifying the host address.
If it is your own, lets say its the local server, whereabouts do you find it?