|
Hi Vikas,
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
http://www.eggheadcafe.com/articles/20020323.asp
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
-Regards
Bharat Jain
Phisys Software Solutions Pvt. Ltd.
bharat.jain.nagpur@gmail.com
|
|
|
|
|
Thanks Bharat for your post.
OK After writing the above code, i have created a variable which i increment after the AcceptClient statement.
But After that suppose a new client sends request then how to check whether the previously connected clients are still connected or no.
Again Thanks for your reponse.
|
|
|
|
|
Hi Vikas ,
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
Else
connectedClients.Remove(tempclient)
End If
Next
Return totalClientConnected
End Function
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
connectedClients.Add(tcpClient)
Also before Dim tcpClient As TcpClient = tcpListener.AcceptTcpClient()
We need to add a if condition
If NumberOfClientConnected() > <maxclientallowe> then
Exit sub
End If
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 .........
Let me know if it was ok or not
-Regards
Bharat Jain
bharat.jain.nagpur@gmail.com
|
|
|
|
|
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.
|
|
|
|
|
Hi , sorry for late response , but i was not able to get the problem , the code seems to be working fine for me , if possible send me the code you are using , i will check that out
-Regards
Bharat Jain
bharat.jain.nagpur@gmail.com
|
|
|
|
|
A Newbie question.
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)
{
listBoxBird.Items.Add(Vogel.German);
}
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.
|
|
|
|
|
First ,
You can use arraylist.But its better if you use generics like List<Bird>.
You can bind the arralist as datasource direcltly so you don't have to add items one by one.You can do it as
listBoxBird.DataSource = birdArray();
Second,
You can retrieve the selecteditem or selecteditems as
listBoxBird.SelectedItem/listBoxBird.SelectedItems
Cheers!!
Brij
|
|
|
|
|
Any pointers to developing an Input Method Editor ?
Even I am confused to choose the technology for this project !!
Regards,
Prasad
|
|
|
|
|
iprasad007 wrote: Even I am confused to choose the technology for this project !!
Then why you posted over here!!
cheers,
Abhijit
|
|
|
|
|
>>Then why you posted over here!!
Don't get frustrated buddy !!
Someone else may know
------------
Moderators please suggest me right forum on codeproject for this.
Thanx
Prasad
|
|
|
|
|
iprasad007 wrote: Any pointers to developing an Input Method Editor ?
Even I am confused to choose the technology for this project !!
Google is always there buddy
Cheers!!
Brij
|
|
|
|
|
hi...
i'm doing my engineering final year ... i need to do a project in my final semester... can someone help me out with some good topics... would be grateful for your help....
|
|
|
|
|
How about using a topic you have experience in?
|
|
|
|
|
Dave Kreskowiak wrote: a topic you have experience in
you mean spam?
Happy 2009.
|
|
|
|
|
Zing.......happy new year.
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
i'm not so good in coding....
i'm good in designing....
any suggestions??
|
|
|
|
|
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?
|
|
|
|
|
Mark Churchill wrote: 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?
Or marketing?
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
...
Blog link to be reinstated at a later date.
|
|
|
|
|
i'm soory for having done that... 
|
|
|
|
|
Hello All,
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?
Cheers & Happy New Year
|
|
|
|
|
The local machine's host address is always 127.0.0.1
|
|
|
|
|
m developing a windows based application in vb.net 2005
what i want to do is to match/compare the data in the database table with the data typed in the textfile,kindly help me...............
|
|
|
|
|
1) Read data from database
2) Read data from file
3) Compare
only two letters away from being an asset
|
|
|
|
|
how to read my.mysettings property from other computer compiled my application.Actualy i want to know that how we can share our app.config file with other computer deployed the same project
Shamo
|
|
|
|